Skip to content

Commit e1ce046

Browse files
committed
... and some more cleanups to transforms.py.
1 parent 9e778d2 commit e1ce046

File tree

1 file changed

+12
-41
lines changed

1 file changed

+12
-41
lines changed

lib/matplotlib/transforms.py

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,14 @@ def min(self):
368368
"""
369369
(property) :attr:`min` is the bottom-left corner of the bounding box.
370370
"""
371-
return [min(self.get_points()[:, 0]),
372-
min(self.get_points()[:, 1])]
371+
return np.min(self.get_points(), axis=0)
373372

374373
@property
375374
def max(self):
376375
"""
377376
(property) :attr:`max` is the top-right corner of the bounding box.
378377
"""
379-
return [max(self.get_points()[:, 0]),
380-
max(self.get_points()[:, 1])]
378+
return np.max(self.get_points(), axis=1)
381379

382380
@property
383381
def intervalx(self):
@@ -695,50 +693,23 @@ def union(bboxes):
695693
"""
696694
if not len(bboxes):
697695
raise ValueError("'bboxes' cannot be empty")
698-
699-
if len(bboxes) == 1:
700-
return bboxes[0]
701-
702-
x0 = np.inf
703-
y0 = np.inf
704-
x1 = -np.inf
705-
y1 = -np.inf
706-
707-
for bbox in bboxes:
708-
points = bbox.get_points()
709-
xs = points[:, 0]
710-
ys = points[:, 1]
711-
x0 = min(x0, np.min(xs))
712-
y0 = min(y0, np.min(ys))
713-
x1 = max(x1, np.max(xs))
714-
y1 = max(y1, np.max(ys))
715-
716-
return Bbox.from_extents(x0, y0, x1, y1)
696+
x0 = min(bbox.xmin for bbox in bboxes)
697+
x1 = max(bbox.xmax for bbox in bboxes)
698+
y0 = min(bbox.ymin for bbox in bboxes)
699+
y1 = max(bbox.ymax for bbox in bboxes)
700+
return Bbox([[x0, y0], [x1, y1]])
717701

718702
@staticmethod
719703
def intersection(bbox1, bbox2):
720704
"""
721705
Return the intersection of the two bboxes or None
722706
if they do not intersect.
723-
724-
Implements the algorithm described at:
725-
726-
http://www.tekpool.com/node/2687
727-
728707
"""
729-
intersects = not (bbox2.xmin > bbox1.xmax or
730-
bbox2.xmax < bbox1.xmin or
731-
bbox2.ymin > bbox1.ymax or
732-
bbox2.ymax < bbox1.ymin)
733-
734-
if intersects:
735-
x0 = max([bbox1.xmin, bbox2.xmin])
736-
x1 = min([bbox1.xmax, bbox2.xmax])
737-
y0 = max([bbox1.ymin, bbox2.ymin])
738-
y1 = min([bbox1.ymax, bbox2.ymax])
739-
return Bbox.from_extents(x0, y0, x1, y1)
740-
741-
return None
708+
x0 = max(bbox1.xmin, bbox2.xmin)
709+
x1 = min(bbox1.xmax, bbox2.xmax)
710+
y0 = max(bbox1.ymin, bbox2.ymin)
711+
y1 = min(bbox1.ymax, bbox2.ymax)
712+
return Bbox([[x0, y0], [x1, y1]]) if x0 <= x1 and y0 <= y1 else None
742713

743714

744715
class Bbox(BboxBase):

0 commit comments

Comments
 (0)