diff --git a/lib/src/vector_math/quad.dart b/lib/src/vector_math/quad.dart index 39064b91..0e46e1d2 100644 --- a/lib/src/vector_math/quad.dart +++ b/lib/src/vector_math/quad.dart @@ -88,4 +88,21 @@ class Quad { _point2.add(offset); _point3.add(offset); } + + /// Returns a printable string + @override + String toString() => '[0] $_point0\n[1] $_point1\n' + '[2] $_point2\n[3] $_point3\n'; + + /// Check if two quad are the same. + @override + bool operator ==(Object other) => + (other is Quad) && + (_point3 == other._point3) && + (_point2 == other._point2) && + (_point1 == other._point1) && + (_point0 == other._point0); + + @override + int get hashCode => Object.hash(_point0, _point1, _point2, _point3); } diff --git a/lib/src/vector_math/vector4.dart b/lib/src/vector_math/vector4.dart index 37780958..e9dc95f9 100644 --- a/lib/src/vector_math/vector4.dart +++ b/lib/src/vector_math/vector4.dart @@ -119,8 +119,8 @@ class Vector4 implements Vector { /// Returns a printable string @override - String toString() => '${_v4storage[0]},${_v4storage[1]},' - '${_v4storage[2]},${_v4storage[3]}'; + String toString() => '[${_v4storage[0]},${_v4storage[1]},' + '${_v4storage[2]},${_v4storage[3]}]'; /// Check if two vectors are the same. @override diff --git a/lib/src/vector_math_64/quad.dart b/lib/src/vector_math_64/quad.dart index 5a5b3aa4..04eb6255 100644 --- a/lib/src/vector_math_64/quad.dart +++ b/lib/src/vector_math_64/quad.dart @@ -88,4 +88,21 @@ class Quad { _point2.add(offset); _point3.add(offset); } + + /// Returns a printable string + @override + String toString() => '[0] $_point0\n[1] $_point1\n' + '[2] $_point2\n[3] $_point3\n'; + + /// Check if two quad are the same. + @override + bool operator ==(Object other) => + (other is Quad) && + (_point3 == other._point3) && + (_point2 == other._point2) && + (_point1 == other._point1) && + (_point0 == other._point0); + + @override + int get hashCode => Object.hash(_point0, _point1, _point2, _point3); } diff --git a/lib/src/vector_math_64/vector4.dart b/lib/src/vector_math_64/vector4.dart index d017f4a9..5157b03b 100644 --- a/lib/src/vector_math_64/vector4.dart +++ b/lib/src/vector_math_64/vector4.dart @@ -119,8 +119,8 @@ class Vector4 implements Vector { /// Returns a printable string @override - String toString() => '${_v4storage[0]},${_v4storage[1]},' - '${_v4storage[2]},${_v4storage[3]}'; + String toString() => '[${_v4storage[0]},${_v4storage[1]},' + '${_v4storage[2]},${_v4storage[3]}]'; /// Check if two vectors are the same. @override diff --git a/test/quad_test.dart b/test/quad_test.dart index 051a48ff..b97e0dbe 100644 --- a/test/quad_test.dart +++ b/test/quad_test.dart @@ -48,10 +48,29 @@ void testQuadCopyTriangles() { relativeTest(t2Normal, normal); } +void testQuadEquals() { + final v1 = Vector3(1.0, 0.0, 1.0); + final v2 = Vector3(0.0, 2.0, 1.0); + final v3 = Vector3(1.0, 0.0, 0.0); + final v4 = Vector3(0.0, 2.0, 0.0); + final quad = Quad.points(v1, v2, v3, v4); + + expect(quad, Quad.points(v1, v2, v3, v4)); + + expect(quad, isNot(Quad.points(Vector3.zero(), v2, v3, v4))); + expect(quad, isNot(Quad.points(v1, Vector3.zero(), v3, v4))); + expect(quad, isNot(Quad.points(v1, v2, Vector3.zero(), v4))); + expect(quad, isNot(Quad.points(v1, v2, v3, Vector3.zero()))); + + expect(Quad.points(v1, v2, v3, v4).hashCode, + equals(Quad.points(v1, v2, v3, v4).hashCode)); +} + void main() { group('Quad', () { test('Copy', testQuadCopy); test('CopyNormalInto', testQuadCopyNormalInto); test('CopyTriangles', testQuadCopyTriangles); + test('equals', testQuadEquals); }); }