diff --git a/src/build123d/topology/shape_core.py b/src/build123d/topology/shape_core.py index b30e5962..691f7f55 100644 --- a/src/build123d/topology/shape_core.py +++ b/src/build123d/topology/shape_core.py @@ -117,6 +117,7 @@ from OCP.TopLoc import TopLoc_Location from OCP.TopTools import ( TopTools_IndexedDataMapOfShapeListOfShape, + TopTools_IndexedMapOfShape, TopTools_ListOfShape, TopTools_SequenceOfShape, ) @@ -2833,16 +2834,9 @@ def _sew_topods_faces(faces: Iterable[TopoDS_Face]) -> TopoDS_Shape: def _topods_entities(shape: TopoDS_Shape, topo_type: Shapes) -> list[TopoDS_Shape]: """Return the TopoDS_Shapes of topo_type from this TopoDS_Shape""" - out = {} # using dict to prevent duplicates - - explorer = TopExp_Explorer(shape, Shape.inverse_shape_LUT[topo_type]) - - while explorer.More(): - item = explorer.Current() - out[hash(item)] = item # needed to avoid pseudo-duplicate entities - explorer.Next() - - return list(out.values()) + shape_set = TopTools_IndexedMapOfShape() + TopExp.MapShapes_s(shape, Shape.inverse_shape_LUT[topo_type], shape_set) + return [shape_set.FindKey(i) for i in range(1, shape_set.Size() + 1)] def _topods_face_normal_at(face: TopoDS_Face, surface_point: gp_Pnt) -> Vector: diff --git a/tests/test_direct_api.py b/tests/test_direct_api.py index da5bfefa..a6d7b221 100644 --- a/tests/test_direct_api.py +++ b/tests/test_direct_api.py @@ -2417,8 +2417,8 @@ def test_project2(self): def test_is_forward(self): plate = Box(10, 10, 1) - Cylinder(1, 1) hole_edges = plate.edges().filter_by(GeomType.CIRCLE) - self.assertTrue(hole_edges.sort_by(Axis.Z)[-1].is_forward) - self.assertFalse(hole_edges.sort_by(Axis.Z)[0].is_forward) + self.assertTrue(hole_edges.sort_by(Axis.Z)[0].is_forward) + self.assertFalse(hole_edges.sort_by(Axis.Z)[-1].is_forward) def test_offset_2d(self): base_wire = Wire.make_polygon([(0, 0), (1, 0), (1, 1)], close=False)