Skip to content

Commit

Permalink
fix union_bbox()
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomulik committed Sep 26, 2022
1 parent f34b748 commit 7655010
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions svgelements/svgelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -7584,33 +7584,18 @@ def union_bbox(elements, transformed=True, with_stroke=False):
:param with_stroke: should the stroke-width be included in the bounds of the elements
:return: union of all bounding boxes of elements within the iterable.
"""
boundary_points = []
boxes = []
for e in elements:
if not hasattr(e, "bbox"):
if not hasattr(e, "bbox") or isinstance(e, (Group, Use)):
continue
box = e.bbox(transformed=False, with_stroke=with_stroke)
box = e.bbox(transformed=transformed, with_stroke=with_stroke)
if box is None:
continue
top_left = (box[0], box[1])
top_right = (box[2], box[1])
bottom_left = (box[0], box[3])
bottom_right = (box[2], box[3])
if transformed:
top_left = e.transform.point_in_matrix_space(top_left)
top_right = e.transform.point_in_matrix_space(top_right)
bottom_left = e.transform.point_in_matrix_space(bottom_left)
bottom_right = e.transform.point_in_matrix_space(bottom_right)
boundary_points.append(top_left)
boundary_points.append(top_right)
boundary_points.append(bottom_left)
boundary_points.append(bottom_right)
if len(boundary_points) == 0:
boxes.append(box)
if len(boxes) == 0:
return None
xmin = min([e[0] for e in boundary_points])
ymin = min([e[1] for e in boundary_points])
xmax = max([e[0] for e in boundary_points])
ymax = max([e[1] for e in boundary_points])
return xmin, ymin, xmax, ymax
(xmins, ymins, xmaxs, ymaxs) = zip(*boxes)
return (min(xmins), min(ymins), max(xmaxs), max(ymaxs))

def bbox(self, transformed=True, with_stroke=False):
"""
Expand Down

0 comments on commit 7655010

Please sign in to comment.