Skip to content

Commit 05e42a7

Browse files
authored
Merge pull request #768 from CadQuery/face-speed
Faster makeFromWires
2 parents 7493e61 + 6f847e2 commit 05e42a7

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156

157157
from OCP.TopExp import TopExp
158158

159-
from OCP.ShapeFix import ShapeFix_Shape, ShapeFix_Solid
159+
from OCP.ShapeFix import ShapeFix_Shape, ShapeFix_Solid, ShapeFix_Face
160160

161161
from OCP.STEPControl import STEPControl_Writer, STEPControl_AsIs
162162

@@ -2100,7 +2100,12 @@ def makeFromWires(
21002100
if not BRepLib_FindSurface(ws.wrapped, OnlyPlane=True).Found():
21012101
raise ValueError("Cannot build face(s): wires not planar")
21022102

2103-
face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped, True)
2103+
# fix outer wire
2104+
sf_s = ShapeFix_Shape(outerWire.wrapped)
2105+
sf_s.Perform()
2106+
wo = TopoDS.Wire_s(sf_s.Shape())
2107+
2108+
face_builder = BRepBuilderAPI_MakeFace(wo, True)
21042109

21052110
for w in innerWires:
21062111
face_builder.Add(w.wrapped)
@@ -2110,9 +2115,13 @@ def makeFromWires(
21102115
if not face_builder.IsDone():
21112116
raise ValueError(f"Cannot build face(s): {face_builder.Error()}")
21122117

2113-
face = face_builder.Shape()
2118+
face = face_builder.Face()
2119+
2120+
sf_f = ShapeFix_Face(face)
2121+
sf_f.FixOrientation()
2122+
sf_f.Perform()
21142123

2115-
return cls(face).fix()
2124+
return cls(sf_f.Result())
21162125

21172126
@classmethod
21182127
def makeSplineApprox(
@@ -2127,7 +2136,7 @@ def makeSplineApprox(
21272136
Approximate a spline surface through the provided points.
21282137
21292138
:param points: a 2D list of Vectors that represent the points
2130-
:param tol: tolerance of the algorithm (consult OCC documentation).
2139+
:param tol: tolerance of the algorithm (consult OCC documentation).
21312140
:param smoothing: optional tuple of 3 weights use for variational smoothing (default: None)
21322141
:param minDeg: minimum spline degree. Enforced only when smothing is None (default: 1)
21332142
:param maxDeg: maximum spline degree (default: 6)

cadquery/selectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class AreaNthSelector(_NthSelector):
488488
- closed planar Wires - a temporary face is created to compute area
489489
490490
Will ignore non-planar or non-closed wires.
491-
491+
492492
Among other things can be used to select one of
493493
the nested coplanar wires or faces.
494494
@@ -534,7 +534,7 @@ def key(self, obj: Shape) -> float:
534534
return obj.Area()
535535
elif isinstance(obj, Wire):
536536
try:
537-
return Face.makeFromWires(obj).Area()
537+
return abs(Face.makeFromWires(obj).Area())
538538
except Exception as ex:
539539
raise ValueError(
540540
f"Can not compute area of the Wire: {ex}. AreaNthSelector supports only closed planar Wires."

0 commit comments

Comments
 (0)