Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making largestDimension work as expected #317

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,14 +2279,15 @@ def largestDimension(self):
how long or wide a feature must be to make sure to cut through all of the material
:return: A value representing the largest dimension of the first solid on the stack
"""
# TODO: this implementation is naive and returns the dims of the first solid... most of
# TODO: the time this works. but a stronger implementation would be to search all solids.
s = self.findSolid()
if s:
return s.BoundingBox().DiagonalLength * 5.0
else:
# Get all the solids contained within this CQ object
compound = self.findSolid()

# Protect against this being called on something like a blank workplane
if not compound:
return -1

return compound.BoundingBox().DiagonalLength

def cutEach(self, fcn, useLocalCoords=False, clean=True):
"""
Evaluates the provided function at each point on the stack (ie, eachpoint)
Expand Down
2 changes: 1 addition & 1 deletion cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def fix(self):

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

tr = None

Expand Down
8 changes: 6 additions & 2 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,12 @@ def testLargestDimension(self):
r = Workplane("XY").box(1, 1, 1)
dim = r.largestDimension()

self.assertAlmostEqual(8.7, dim, 1)
self.assertAlmostEqual(1.76, dim, 1)

r = Workplane("XY").rect(1, 1).extrude(1)
dim = r.largestDimension()

self.assertAlmostEqual(1.76, dim, 1)

r = Workplane("XY")
dim = r.largestDimension()
Expand Down Expand Up @@ -1728,7 +1733,6 @@ def testCounterBores(self):

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

Expand Down