From 21388385fa355dd280616ce0fa6a4f042861c221 Mon Sep 17 00:00:00 2001 From: Justin Buchanan Date: Sun, 18 Nov 2018 00:07:39 -0800 Subject: [PATCH 1/2] fix Vector.__eq__() --- cadquery/occ_impl/geom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/occ_impl/geom.py b/cadquery/occ_impl/geom.py index 1f7be5595..12143b83c 100644 --- a/cadquery/occ_impl/geom.py +++ b/cadquery/occ_impl/geom.py @@ -133,7 +133,7 @@ def __str__(self): return 'Vector: ' + str((self.x, self.y, self.z)) def __eq__(self, other): - return self.wrapped == other.wrapped + return self.x == other.x and self.y == other.y and self.z == other.z ''' is not implemented in OCC def __ne__(self, other): From 084db38d566a3d9599bf1bd49839473da226beaf Mon Sep 17 00:00:00 2001 From: Justin Buchanan Date: Sun, 18 Nov 2018 13:02:21 -0800 Subject: [PATCH 2/2] Use gp_Vec.IsEqual() and add a test for Vector.__eq__() --- cadquery/occ_impl/geom.py | 2 +- tests/TestCadObjects.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cadquery/occ_impl/geom.py b/cadquery/occ_impl/geom.py index 12143b83c..47af6eec5 100644 --- a/cadquery/occ_impl/geom.py +++ b/cadquery/occ_impl/geom.py @@ -133,7 +133,7 @@ def __str__(self): return 'Vector: ' + str((self.x, self.y, self.z)) def __eq__(self, other): - return self.x == other.x and self.y == other.y and self.z == other.z + return self.wrapped.IsEqual(other.wrapped, 0.00001, 0.00001) ''' is not implemented in OCC def __ne__(self, other): diff --git a/tests/TestCadObjects.py b/tests/TestCadObjects.py index 807d1779b..c220b96be 100644 --- a/tests/TestCadObjects.py +++ b/tests/TestCadObjects.py @@ -108,6 +108,13 @@ def testVectorAdd(self): result = Vector(1, 2, 0) + Vector(0, 0, 3) self.assertTupleAlmostEquals((1.0, 2.0, 3.0), result.toTuple(), 3) + def testVectorEquals(self): + a = Vector(1, 2, 3) + b = Vector(1, 2, 3) + c = Vector(1, 2, 3.000001) + self.assertEqual(a, b) + self.assertEqual(a, c) + def testTranslate(self): e = Edge.makeCircle(2, (1, 2, 3)) e2 = e.translate(Vector(0, 0, 1))