Skip to content

Commit ac585b4

Browse files
authored
Add glue option to combine() (#535)
* Update cq.py Add glue option to combine() * Update test_cadquery.py Add test of glue=True to combine() * Update test_cadquery.py update testcombine() * Update cq.py Reformat combine() * Reformat Black * Update test_cadquery.py Added tol=None to testCombine() * Update test_cadquery.py Correct testCombine() * Update test_cadquery.py * Update test_cadquery.py * Update test_cadquery.py Black formatting * Update test_cadquery.py
1 parent a03648c commit ac585b4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

cadquery/cq.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ def __init__(
140140
) -> None:
141141
...
142142

143-
def __init__(
144-
self, inPlane="XY", origin=(0, 0, 0), obj=None,
145-
):
143+
def __init__(self, inPlane="XY", origin=(0, 0, 0), obj=None):
146144
"""
147145
make a workplane from a particular plane
148146
@@ -2126,7 +2124,7 @@ def wire(self, forConstruction: bool = False) -> "Workplane":
21262124
return self.newObject(others + [w])
21272125

21282126
def each(
2129-
self, callback: Callable[[CQObject], Shape], useLocalCoordinates: bool = False,
2127+
self, callback: Callable[[CQObject], Shape], useLocalCoordinates: bool = False
21302128
) -> "Workplane":
21312129
"""
21322130
Runs the provided function on each value in the stack, and collects the return values into
@@ -2178,7 +2176,7 @@ def each(
21782176
return self.newObject(results)
21792177

21802178
def eachpoint(
2181-
self, callback: Callable[[Location], Shape], useLocalCoordinates: bool = False,
2179+
self, callback: Callable[[Location], Shape], useLocalCoordinates: bool = False
21822180
) -> "Workplane":
21832181
"""
21842182
Same as each(), except each item on the stack is converted into a point before it
@@ -2899,20 +2897,25 @@ def _cutFromBase(self, obj: Shape) -> "Workplane":
28992897

29002898
return self.newObject([r])
29012899

2902-
def combine(self, clean: bool = True) -> "Workplane":
2900+
def combine(
2901+
self, clean: bool = True, glue: bool = False, tol: Optional[float] = None
2902+
) -> "Workplane":
29032903
"""
29042904
Attempts to combine all of the items on the stack into a single item.
29052905
WARNING: all of the items must be of the same type!
29062906
29072907
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
2908+
:param boolean glue: use a faster gluing mode for non-overlapping shapes (default False)
2909+
:param float tol: tolerance value for fuzzy bool operation mode (default None)
29082910
:raises: ValueError if there are no items on the stack, or if they cannot be combined
29092911
:return: a CQ object with the resulting object selected
29102912
"""
2913+
29112914
items: List[Shape] = [o for o in self.objects if isinstance(o, Shape)]
29122915
s = items.pop(0)
29132916

29142917
if items:
2915-
s = s.fuse(*items)
2918+
s = s.fuse(*items, glue=glue, tol=tol)
29162919

29172920
if clean:
29182921
s = s.clean()

tests/test_cadquery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,9 +2180,13 @@ def testCombine(self):
21802180
objects1 = s.rect(2.0, 2.0).extrude(0.5).faces(">Z").rect(1.0, 1.0).extrude(0.5)
21812181

21822182
objects1.combine()
2183-
21842183
self.assertEqual(11, objects1.faces().size())
21852184

2185+
objects1 = s.rect(2.0, 2.0).extrude(0.5)
2186+
objects2 = s.rect(1.0, 1.0).extrude(0.5).translate((0, 0, 0.5))
2187+
objects2 = objects1.add(objects2).combine(glue=True, tol=None)
2188+
self.assertEqual(11, objects2.faces().size())
2189+
21862190
def testCombineSolidsInLoop(self):
21872191
# duplicates a memory problem of some kind reported when combining lots of objects
21882192
s = Workplane("XY").rect(0.5, 0.5).extrude(5.0)

0 commit comments

Comments
 (0)