Remove the combine arg for bool ops and get rid of side-effects

This commit is contained in:
adam-urbanczyk
2019-06-08 17:21:23 +02:00
parent 646e07c33a
commit e4c84c99e0
2 changed files with 20 additions and 36 deletions

View File

@ -2378,12 +2378,10 @@ class Workplane(CQ):
return self.newObject([s]) return self.newObject([s])
def union(self, toUnion=None, combine=True, clean=True): def union(self, toUnion=None, clean=True):
""" """
Unions all of the items on the stack of toUnion with the current solid. Unions all of the items on the stack of toUnion with the current solid.
If there is no current solid, the items in toUnion are unioned together. If there is no current solid, the items in toUnion are unioned together.
if combine=True, the result and the original are updated to point to the new object
if combine=False, the result will be on the stack, but the original is unmodified
:param toUnion: :param toUnion:
:type toUnion: a solid object, or a CQ object having a solid, :type toUnion: a solid object, or a CQ object having a solid,
@ -2409,9 +2407,8 @@ class Workplane(CQ):
# now combine with existing solid, if there is one # now combine with existing solid, if there is one
# look for parents to cut from # look for parents to cut from
solidRef = self.findSolid(searchStack=True, searchParents=True) solidRef = self.findSolid(searchStack=True, searchParents=True)
if combine and solidRef is not None: if solidRef is not None:
r = solidRef.fuse(newS) r = solidRef.fuse(newS)
solidRef.wrapped = newS.wrapped
else: else:
r = newS r = newS
@ -2420,13 +2417,10 @@ class Workplane(CQ):
return self.newObject([r]) return self.newObject([r])
def cut(self, toCut, combine=True, clean=True): def cut(self, toCut, clean=True):
""" """
Cuts the provided solid from the current solid, IE, perform a solid subtraction Cuts the provided solid from the current solid, IE, perform a solid subtraction
if combine=True, the result and the original are updated to point to the new object
if combine=False, the result will be on the stack, but the original is unmodified
:param toCut: object to cut :param toCut: object to cut
:type toCut: a solid object, or a CQ object having a solid, :type toCut: a solid object, or a CQ object having a solid,
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape :param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
@ -2452,18 +2446,12 @@ class Workplane(CQ):
if clean: if clean:
newS = newS.clean() newS = newS.clean()
if combine:
solidRef.wrapped = newS.wrapped
return self.newObject([newS]) return self.newObject([newS])
def intersect(self, toIntersect, combine=True, clean=True): def intersect(self, toIntersect, clean=True):
""" """
Intersects the provided solid from the current solid. Intersects the provided solid from the current solid.
if combine=True, the result and the original are updated to point to the new object
if combine=False, the result will be on the stack, but the original is unmodified
:param toIntersect: object to intersect :param toIntersect: object to intersect
:type toIntersect: a solid object, or a CQ object having a solid, :type toIntersect: a solid object, or a CQ object having a solid,
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape :param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
@ -2489,9 +2477,6 @@ class Workplane(CQ):
if clean: newS = newS.clean() if clean: newS = newS.clean()
if combine:
solidRef.wrapped = newS.wrapped
return self.newObject([newS]) return self.newObject([newS])
def cutBlind(self, distanceToCut, clean=True, taper=None): def cutBlind(self, distanceToCut, clean=True, taper=None):

View File

@ -771,9 +771,9 @@ class TestCadQuery(BaseTest):
currentS = s.rect(2.0, 2.0).extrude(0.5) currentS = s.rect(2.0, 2.0).extrude(0.5)
toCut = s.rect(1.0, 1.0).extrude(0.5) toCut = s.rect(1.0, 1.0).extrude(0.5)
currentS.cut(toCut.val()) resS = currentS.cut(toCut.val())
self.assertEqual(10, currentS.faces().size()) self.assertEqual(10, resS.faces().size())
def testIntersect(self): def testIntersect(self):
""" """
@ -783,15 +783,15 @@ class TestCadQuery(BaseTest):
currentS = s.rect(2.0, 2.0).extrude(0.5) currentS = s.rect(2.0, 2.0).extrude(0.5)
toIntersect = s.rect(1.0, 1.0).extrude(1) toIntersect = s.rect(1.0, 1.0).extrude(1)
currentS.intersect(toIntersect.val()) resS = currentS.intersect(toIntersect.val())
self.assertEqual(6, currentS.faces().size()) self.assertEqual(6, resS.faces().size())
self.assertAlmostEqual(currentS.val().Volume(),0.5) self.assertAlmostEqual(resS.val().Volume(),0.5)
currentS.intersect(toIntersect) resS = currentS.intersect(toIntersect)
self.assertEqual(6, currentS.faces().size()) self.assertEqual(6, resS.faces().size())
self.assertAlmostEqual(currentS.val().Volume(),0.5) self.assertAlmostEqual(resS.val().Volume(),0.5)
def testBoundingBox(self): def testBoundingBox(self):
""" """
@ -1414,10 +1414,9 @@ class TestCadQuery(BaseTest):
currentS = s.rect(2.0, 2.0).extrude(0.5) currentS = s.rect(2.0, 2.0).extrude(0.5)
toUnion = s.rect(1.0, 1.0).extrude(1.0) toUnion = s.rect(1.0, 1.0).extrude(1.0)
currentS.union(toUnion.val(), combine=False) resS = currentS.union(toUnion)
# TODO: When unioning and combining is figured out, uncomment the following assert self.assertEqual(11,resS.faces().size())
# self.assertEqual(10,currentS.faces().size())
def testCombine(self): def testCombine(self):
s = Workplane(Plane.XY()) s = Workplane(Plane.XY())