Skip to content

Commit 5fb8823

Browse files
committed
added cut for revolve and loft
added the option to combine="cut" for revolve and loft, added tests removed old arg of loft that was actually unused
1 parent 6c8502f commit 5fb8823

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

cadquery/cq.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,7 +3085,7 @@ def revolve(
30853085
:param axisEnd: the end point of the axis of rotation
30863086
:type axisEnd: tuple, a two tuple
30873087
:param combine: True to combine the resulting solid with parent solids if found.
3088-
:type combine: boolean, combine with parent solid
3088+
:type combine: boolean or string, defines how the result of the operation is combined with the base solid
30893089
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
30903090
:return: a CQ object with the resulting solid selected.
30913091
@@ -3129,7 +3129,9 @@ def revolve(
31293129

31303130
# returns a Solid (or a compound if there were multiple)
31313131
r = self._revolve(angleDegrees, axisStart, axisEnd)
3132-
if combine:
3132+
if isinstance(combine, str) and combine == "cut":
3133+
newS = self._cutFromBase(r)
3134+
elif isinstance(combine, bool) and combine:
31333135
newS = self._combineWithBase(r)
31343136
else:
31353137
newS = self.newObject([r])
@@ -3492,12 +3494,10 @@ def cutThruAll(self: T, clean: bool = True, taper: float = 0) -> T:
34923494

34933495
return self.newObject([s])
34943496

3495-
def loft(
3496-
self: T, filled: bool = True, ruled: bool = False, combine: bool = True
3497-
) -> T:
3497+
def loft(self: T, ruled: bool = False, combine: Union[bool, str] = True) -> T:
34983498
"""
34993499
Make a lofted solid, through the set of wires.
3500-
:return: a CQ object containing the created loft
3500+
:return: a Workplane object containing the created loft
35013501
"""
35023502

35033503
if self.ctx.pendingWires:
@@ -3510,14 +3510,13 @@ def loft(
35103510

35113511
r: Shape = Solid.makeLoft(wiresToLoft, ruled)
35123512

3513-
if combine:
3514-
parentSolid = self._findType(
3515-
(Solid, Compound), searchStack=False, searchParents=True
3516-
)
3517-
if parentSolid is not None:
3518-
r = parentSolid.fuse(r)
3513+
if isinstance(combine, str) and combine == "cut":
3514+
r = self._cutFromBase(r)
35193515

3520-
return self.newObject([r])
3516+
elif isinstance(combine, bool) and combine:
3517+
r = self._combineWithBase(r)
3518+
3519+
return r
35213520

35223521
def _getFaces(self) -> List[Face]:
35233522
"""

tests/test_cadquery.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,19 @@ def testLoft(self):
467467
# the resulting loft had a split on the side, not sure why really, i expected only 3 faces
468468
self.assertEqual(7, s.faces().size())
469469

470+
# test loft with combine="cut"
471+
box = Workplane().box(10, 10, 10).solids()
472+
cut = (
473+
box.faces(">Z")
474+
.workplane()
475+
.circle(2)
476+
.workplane(invert=True, offset=12)
477+
.rect(3, 2)
478+
.loft(combine="cut")
479+
)
480+
481+
self.assertGreater(box.val().Volume(), cut.val().Volume())
482+
470483
def testLoftRaisesValueError(self):
471484
s0 = Workplane().hLine(1) # no wires
472485
with raises(ValueError):
@@ -616,6 +629,17 @@ def testRevolveCone(self):
616629
self.assertEqual(2, result.vertices().size())
617630
self.assertEqual(2, result.edges().size())
618631

632+
def testRevolveCut(self):
633+
box = Workplane().box(10, 10, 10)
634+
cut = (
635+
box.transformed((90, 0, 0))
636+
.move(5, 0)
637+
.rect(3, 4, centered=False)
638+
.revolve(360, (0, 0, 0), (0, 1, 0), combine="cut")
639+
)
640+
641+
self.assertGreater(box.val().Volume(), cut.val().Volume())
642+
619643
def testRevolveErrors(self):
620644
"""
621645
Test that revolve raises errors when used incorrectly.

0 commit comments

Comments
 (0)