Check if wires are coplanar

This commit is contained in:
adam-urbanczyk
2021-04-01 22:31:30 +02:00
committed by Marcus Boyd
parent 7546866159
commit 39e60f6e48
2 changed files with 13 additions and 0 deletions

View File

@ -2095,12 +2095,21 @@ class Face(Shape):
Makes a planar face from one or more wires Makes a planar face from one or more wires
""" """
# check if wires are coplanar
ws = Compound.makeCompound([outerWire] + innerWires)
if not BRepLib_FindSurface(ws.wrapped, OnlyPlane=True).Found():
raise ValueError("Cannot build face(s): wires not planar")
face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped, True) face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped, True)
for w in innerWires: for w in innerWires:
face_builder.Add(w.wrapped) face_builder.Add(w.wrapped)
face_builder.Build() face_builder.Build()
if not face_builder.IsDone():
raise ValueError(f"Cannot build face(s): {face_builder.Error()}")
face = face_builder.Shape() face = face_builder.Shape()
return cls(face).fix() return cls(face).fix()

View File

@ -3087,6 +3087,10 @@ class TestCadQuery(BaseTest):
delta.toTuple(), (0.0, 0.0, 2.0 * h), decimal_places delta.toTuple(), (0.0, 0.0, 2.0 * h), decimal_places
) )
# check that non-conplanar extrusion raises
with self.assertRaises(ValueError):
Workplane().box(1, 1, 1).faces().circle(0.1).extrude(0.1)
def testTaperedExtrudeCutBlind(self): def testTaperedExtrudeCutBlind(self):
h = 1.0 h = 1.0