Skip to content

Commit 40cf143

Browse files
committed
Updated edges() to use WireExplorer when appropriate Issue gumyr#864
1 parent 2d84e6e commit 40cf143

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/build123d/topology/one_d.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
from OCP.BRepOffsetAPI import BRepOffsetAPI_MakeOffset
8989
from OCP.BRepPrimAPI import BRepPrimAPI_MakeHalfSpace
9090
from OCP.BRepProj import BRepProj_Projection
91-
from OCP.BRepTools import BRepTools
91+
from OCP.BRepTools import BRepTools, BRepTools_WireExplorer
9292
from OCP.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse
9393
from OCP.GCPnts import GCPnts_AbscissaPoint
9494
from OCP.GProp import GProp_GProps
@@ -480,10 +480,20 @@ def edge(self) -> Edge | None:
480480

481481
def edges(self) -> ShapeList[Edge]:
482482
"""edges - all the edges in this Shape"""
483-
edge_list = Shape.get_shape_list(self, "Edge")
484-
return edge_list.filter_by(
485-
lambda e: BRep_Tool.Degenerated_s(e.wrapped), reverse=True
486-
)
483+
if isinstance(self, Wire):
484+
# The WireExplorer is a tool to explore the edges of a wire in a connection order.
485+
explorer = BRepTools_WireExplorer(self.wrapped)
486+
487+
edge_list: ShapeList[Edge] = ShapeList()
488+
while explorer.More():
489+
edge_list.append(Edge(explorer.Current()))
490+
explorer.Next()
491+
return edge_list
492+
else:
493+
edge_list = Shape.get_shape_list(self, "Edge")
494+
return edge_list.filter_by(
495+
lambda e: BRep_Tool.Degenerated_s(e.wrapped), reverse=True
496+
)
487497

488498
def end_point(self) -> Vector:
489499
"""The end point of this edge.

0 commit comments

Comments
 (0)