Skip to content

Commit c681756

Browse files
committed
Restore fast(er) impl. of overlaps.
1 parent c2aabe9 commit c681756

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/matplotlib/transforms.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,17 @@ def overlaps(self, other):
466466
"""
467467
Returns whether this bounding box overlaps with the other bounding box.
468468
"""
469-
return (self.xmin <= other.xmax and other.xmin <= self.xmax
470-
and self.ymin <= other.ymax and other.ymin <= self.ymax)
469+
ax1, ay1, ax2, ay2 = self._get_extents()
470+
bx1, by1, bx2, by2 = other._get_extents()
471+
if ax2 < ax1:
472+
ax2, ax1 = ax1, ax2
473+
if ay2 < ay1:
474+
ay2, ay1 = ay1, ay2
475+
if bx2 < bx1:
476+
bx2, bx1 = bx1, bx2
477+
if by2 < by1:
478+
by2, by1 = by1, by2
479+
return ax1 <= bx2 and bx1 <= ax2 and ay1 <= by2 and by1 <= ay2
471480

472481
def fully_containsx(self, x):
473482
"""
@@ -494,8 +503,17 @@ def fully_overlaps(self, other):
494503
Returns whether this bounding box overlaps with the other bounding box,
495504
not including the edges.
496505
"""
497-
return (self.xmin < other.xmax and other.xmin < self.xmax
498-
and self.ymin < other.ymax and other.ymin < self.ymax)
506+
ax1, ay1, ax2, ay2 = self._get_extents()
507+
bx1, by1, bx2, by2 = other._get_extents()
508+
if ax2 < ax1:
509+
ax2, ax1 = ax1, ax2
510+
if ay2 < ay1:
511+
ay2, ay1 = ay1, ay2
512+
if bx2 < bx1:
513+
bx2, bx1 = bx1, bx2
514+
if by2 < by1:
515+
by2, by1 = by1, by2
516+
return ax1 < bx2 and bx1 < ax2 and ay1 < by2 and by1 < ay2
499517

500518
def transformed(self, transform):
501519
"""

0 commit comments

Comments
 (0)