diff --git a/src/build123d/topology.py b/src/build123d/topology.py index 9ee91452..0a54791f 100644 --- a/src/build123d/topology.py +++ b/src/build123d/topology.py @@ -3650,6 +3650,10 @@ def __or__(self, filter_by: Union[Axis, GeomType] = Axis.Z): """Filter by axis or geomtype operator |""" return self.filter_by(filter_by) + def __eq__(self, other: ShapeList): + """ShapeLists equality operator ==""" + return set(self) == set(other) + def __add__(self, other: ShapeList): """Combine two ShapeLists together operator +""" return ShapeList(list(self) + list(other)) @@ -3661,6 +3665,10 @@ def __sub__(self, other: ShapeList) -> ShapeList: # return ShapeList(hash_set.values()) return ShapeList(set(self) - set(other)) + def __and__(self, other: ShapeList): + """Intersect two ShapeLists operator &""" + return ShapeList(set(self) & set(other)) + @overload def __getitem__(self, key: int) -> T: ... diff --git a/tests/test_build_common.py b/tests/test_build_common.py index 94a67599..075a27fc 100644 --- a/tests/test_build_common.py +++ b/tests/test_build_common.py @@ -553,6 +553,14 @@ def test_shapes(self): Box(1, 1, 1) self.assertIsNone(test._shapes(Compound)) + def test_operators(self): + with BuildPart() as test: + Box(1, 1, 1) + self.assertEqual( + (test.faces() | Axis.Z).edges() & (test.faces() | Axis.Y).edges(), + (test.edges() | Axis.X) + ) + class TestValidateInputs(unittest.TestCase): def test_wrong_builder(self):