Skip to content

Commit 40c2664

Browse files
authored
Return False on Vector comparison with non-Vector (#1610)
* Return NotImplemented on Vector comparison with non-Vector * Return False on Vector comparison with non-Vector
1 parent 33f72d2 commit 40c2664

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cadquery/occ_impl/geom.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ def __str__(self) -> str:
230230
return "Vector: " + str((self.x, self.y, self.z))
231231

232232
def __eq__(self, other: "Vector") -> bool: # type: ignore[override]
233-
return self.wrapped.IsEqual(other.wrapped, 0.00001, 0.00001)
233+
return (
234+
self.wrapped.IsEqual(other.wrapped, 0.00001, 0.00001)
235+
if isinstance(other, Vector)
236+
else False
237+
)
234238

235239
def toPnt(self) -> gp_Pnt:
236240

tests/test_cad_objects.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,5 +805,21 @@ def test_wire_makepolygon(points, close, expected_edges):
805805
assert len(Wire.makePolygon(points, False, close).Edges()) == expected_edges
806806

807807

808+
def test_equality():
809+
810+
# do not raise error comparing with other type
811+
assert (Vector(0, 0, 0) == 0) == False
812+
assert (Plane.XY() == 0) == False
813+
814+
list1 = [
815+
Vector(0, 0, 0),
816+
Plane.XY(),
817+
Vertex.makeVertex(0, 0, 0),
818+
"a string",
819+
4,
820+
]
821+
assert [list1.index(item) for item in list1] == [0, 1, 2, 3, 4]
822+
823+
808824
if __name__ == "__main__":
809825
unittest.main()

0 commit comments

Comments
 (0)