Skip to content

Commit c20e16e

Browse files
authored
Merge pull request #25943 from meeseeksmachine/auto-backport-of-pr-25902-on-v3.7.x
Backport PR #25902 on branch v3.7.x (Fix TransformedBbox.{,full_}contains.)
2 parents 6686227 + a9b4f01 commit c20e16e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/matplotlib/tests/test_transforms.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import matplotlib.pyplot as plt
1010
import matplotlib.patches as mpatches
1111
import matplotlib.transforms as mtransforms
12+
from matplotlib.transforms import Affine2D, Bbox, TransformedBbox
1213
from matplotlib.path import Path
1314
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1415

@@ -755,3 +756,14 @@ def test_offset_copy_errors():
755756
with pytest.raises(ValueError,
756757
match='For units of inches or points a fig kwarg is needed'):
757758
mtransforms.offset_copy(None, units='inches')
759+
760+
761+
def test_transformedbbox_contains():
762+
bb = TransformedBbox(Bbox.unit(), Affine2D().rotate_deg(30))
763+
assert bb.contains(.8, .5)
764+
assert bb.contains(-.4, .85)
765+
assert not bb.contains(.9, .5)
766+
bb = TransformedBbox(Bbox.unit(), Affine2D().translate(.25, .5))
767+
assert bb.contains(1.25, 1.5)
768+
assert not bb.fully_contains(1.25, 1.5)
769+
assert not bb.fully_contains(.1, .1)

lib/matplotlib/transforms.py

+8
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,14 @@ def get_points(self):
11441144
self._check(points)
11451145
return points
11461146

1147+
def contains(self, x, y):
1148+
# Docstring inherited.
1149+
return self._bbox.contains(*self._transform.inverted().transform((x, y)))
1150+
1151+
def fully_contains(self, x, y):
1152+
# Docstring inherited.
1153+
return self._bbox.fully_contains(*self._transform.inverted().transform((x, y)))
1154+
11471155

11481156
class LockableBbox(BboxBase):
11491157
"""

0 commit comments

Comments
 (0)