def build_bundles(paths: Iterable[Path]) -> Iterable[Bundle]: def append_holes(holes): for hole in holes: if isinstance(hole, Path): # just for edge cases, in general: # holes should be inside of the contour! box.extend(hole.control_vertices()) entities.append(hole.user_data) else: append_holes(hole) # the fast bbox detection algorithm is not very accurate! for polygon in nesting.fast_bbox_detection(paths): contour = polygon[0] box = BoundingBox(contour.control_vertices()) # optional: add some spacing between items if required: box.grow(0.5) entities = [contour.user_data] for hole in polygon[1:]: append_holes(hole) yield Bundle(entities, box)
def test_grow_bounding_box(self): box = BoundingBox([(0, 0, 0), (1, 1, 1)]) box.grow(1) assert box.extmin.isclose((-1, -1, -1)) assert box.extmax.isclose((2, 2, 2))
def test_shrinking_to_zero_or_below_raises_exception(self): box = BoundingBox([(0, 0, 0), (1, 1, 1)]) with pytest.raises(ValueError): box.grow(-0.5)
def test_growing_empty_bounding_box_does_nothing(self): box = BoundingBox() box.grow(1) assert box.has_data is False