Skip to content
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
16 changes: 16 additions & 0 deletions cadquery/occ_impl/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,22 @@ def add(

return BoundBox(tmp)

def enlarge(self, tol: float) -> "BoundBox":
"""Returns a modified (expanded) bounding box, expanded in all
directions by the tolerance value.

This means that the minimum values of its X, Y and Z intervals
of the bounding box are reduced by the absolute value of tol, while
the maximum values are increased by the same amount.
"""
tmp = Bnd_Box()
tmp.Add(self.wrapped)
tmp.SetGap(self.wrapped.GetGap())

tmp.Enlarge(tol)

return BoundBox(tmp)

@staticmethod
def findOutsideBox2D(bb1: "BoundBox", bb2: "BoundBox") -> Optional["BoundBox"]:
"""Compares bounding boxes
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,25 @@ def testBoundingBox(self):
self.assertAlmostEqual(0.0, bb.zmin, 2)
self.assertAlmostEqual(100.0, bb.zmax, 2)

def testBoundBoxEnlarge(self):
"""
Tests BoundBox.enlarge(). Confirms that the
bounding box lengths are all enlarged by the
correct amount.
"""

enlarge_tol = 2.0
bb = Workplane("XY").rect(10, 10).extrude(10).val().BoundingBox()
bb_enlarged = bb.enlarge(enlarge_tol)

self.assertTrue(bb_enlarged.isInside(bb))
self.assertAlmostEqual(bb_enlarged.xmin, bb.xmin - enlarge_tol, 2)
self.assertAlmostEqual(bb_enlarged.xmax, bb.xmax + enlarge_tol, 2)
self.assertAlmostEqual(bb_enlarged.ymin, bb.ymin - enlarge_tol, 2)
self.assertAlmostEqual(bb_enlarged.ymax, bb.ymax + enlarge_tol, 2)
self.assertAlmostEqual(bb_enlarged.zmin, bb.zmin - enlarge_tol, 2)
self.assertAlmostEqual(bb_enlarged.zmax, bb.zmax + enlarge_tol, 2)

def testCutThroughAll(self):
"""
Tests a model that uses more than one workplane
Expand Down