Fix extrude of non-planar face Issue #307

This commit is contained in:
gumyr 2023-08-29 10:33:37 -04:00
parent 8970b73e46
commit 750fa0e071
2 changed files with 16 additions and 1 deletions

View file

@ -101,7 +101,14 @@ def extrude(
if isinstance(to_extrude, (tuple, list, filter)) if isinstance(to_extrude, (tuple, list, filter))
else to_extrude.faces() else to_extrude.faces()
) )
face_planes = [Plane(face) for face in to_extrude_faces] face_planes = []
for face in to_extrude_faces:
try:
plane = Plane(face)
except ValueError: # non-planar face
plane = None
if plane is not None:
face_planes.append(plane)
new_solids: list[Solid] = [] new_solids: list[Solid] = []
@ -111,6 +118,8 @@ def extrude(
Plane(face.center(), face.center_location.x_axis.direction, Vector(dir)) Plane(face.center(), face.center_location.x_axis.direction, Vector(dir))
for face in to_extrude_faces for face in to_extrude_faces
] ]
if len(face_planes) != len(to_extrude_faces):
raise ValueError("dir must be provided when extruding non-planar faces")
if until is not None: if until is not None:
if target is None and context is None: if target is None and context is None:

View file

@ -274,6 +274,12 @@ class TestExtrude(unittest.TestCase):
extrude(square.sketch, amount=10) extrude(square.sketch, amount=10)
self.assertAlmostEqual(box.part.volume, 10**3, 5) self.assertAlmostEqual(box.part.volume, 10**3, 5)
def test_extrude_non_planar_face(self):
cyl = Cylinder(1, 2)
npf = cyl.split(Plane.XZ).faces().filter_by(GeomType.PLANE, reverse=True)[0]
test_solid = extrude(npf, amount=3, dir=(0, 1, 0))
self.assertAlmostEqual(test_solid.volume, 2 * 2 * 3, 5)
class TestHole(unittest.TestCase): class TestHole(unittest.TestCase):
def test_fixed_depth(self): def test_fixed_depth(self):