Skip to content

Commit 1491e0c

Browse files
authored
Merge pull request #317 from jmwright/master
Making largestDimension work as expected
2 parents b81319a + 71196ba commit 1491e0c

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

cadquery/cq.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,14 +2279,15 @@ def largestDimension(self):
22792279
how long or wide a feature must be to make sure to cut through all of the material
22802280
:return: A value representing the largest dimension of the first solid on the stack
22812281
"""
2282-
# TODO: this implementation is naive and returns the dims of the first solid... most of
2283-
# TODO: the time this works. but a stronger implementation would be to search all solids.
2284-
s = self.findSolid()
2285-
if s:
2286-
return s.BoundingBox().DiagonalLength * 5.0
2287-
else:
2282+
# Get all the solids contained within this CQ object
2283+
compound = self.findSolid()
2284+
2285+
# Protect against this being called on something like a blank workplane
2286+
if not compound:
22882287
return -1
22892288

2289+
return compound.BoundingBox().DiagonalLength
2290+
22902291
def cutEach(self, fcn, useLocalCoords=False, clean=True):
22912292
"""
22922293
Evaluates the provided function at each point on the stack (ie, eachpoint)

cadquery/occ_impl/shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def fix(self):
254254

255255
@classmethod
256256
def cast(cls, obj, forConstruction=False):
257-
"Returns the right type of wrapper, given a FreeCAD object"
257+
"Returns the right type of wrapper, given a OCCT object"
258258

259259
tr = None
260260

tests/test_cadquery.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,12 @@ def testLargestDimension(self):
15031503
r = Workplane("XY").box(1, 1, 1)
15041504
dim = r.largestDimension()
15051505

1506-
self.assertAlmostEqual(8.7, dim, 1)
1506+
self.assertAlmostEqual(1.76, dim, 1)
1507+
1508+
r = Workplane("XY").rect(1, 1).extrude(1)
1509+
dim = r.largestDimension()
1510+
1511+
self.assertAlmostEqual(1.76, dim, 1)
15071512

15081513
r = Workplane("XY")
15091514
dim = r.largestDimension()
@@ -1728,7 +1733,6 @@ def testCounterBores(self):
17281733

17291734
# Tests the case where the depth of the cboreHole is not specified
17301735
c2 = CQ(makeCube(3.0))
1731-
pnts = [(-1.0, -1.0), (0.0, 0.0), (1.0, 1.0)]
17321736
c2 = c2.faces(">Z").workplane().pushPoints(pnts).cboreHole(0.1, 0.25, 0.25)
17331737
self.assertEqual(15, c2.faces().size())
17341738

0 commit comments

Comments
 (0)