Rough cut of making largestDimension work as expected

This commit is contained in:
Jeremy Wright
2020-04-10 23:32:52 -04:00
parent 6ecb0fc96f
commit 5609e4c460
2 changed files with 49 additions and 6 deletions

View File

@ -2279,13 +2279,51 @@ class Workplane(CQ):
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
"""
xmin = ymin = zmin = 999999
xmax = ymax = zmax = -999999
# Get all the solids contained within this CQ object
solids = self.solids().vals()
# Protect against this being called on something like a blank workplane
if len(solids) == 0: return -1
# Find the combined outer bounds of all the solids
for solid in solids:
# Mins
if solid.BoundingBox().xmin < xmin:
xmin = solid.BoundingBox().xmin
if solid.BoundingBox().ymin < ymin:
ymin = solid.BoundingBox().ymin
if solid.BoundingBox().zmin < zmin:
zmin = solid.BoundingBox().zmin
# Maxes
if solid.BoundingBox().xmax > xmax:
xmax = solid.BoundingBox().xmax
if solid.BoundingBox().ymax > ymax:
ymax = solid.BoundingBox().ymax
if solid.BoundingBox().zmax > zmax:
zmax = solid.BoundingBox().zmax
xLength = (xmax - xmin)
yLength = (ymax - ymin)
zLength = (zmax - zmin)
centroid = Vector(xLength, yLength, zLength)
# Calculate the sphere size of the outer bounds of all solids
sphereSize = centroid.Length
return sphereSize
# 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:
return -1
# s = self.findSolid()
# if s:
# return s.BoundingBox().DiagonalLength * 5.0
# else:
# return -1
def cutEach(self, fcn, useLocalCoords=False, clean=True):
"""

View File

@ -1503,7 +1503,12 @@ class TestCadQuery(BaseTest):
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()