Skip to content

Commit f45b423

Browse files
authored
Merge pull request #25902 from anntzer/tbc
Fix TransformedBbox.{,full_}contains.
2 parents b0c625a + a81c3d0 commit f45b423

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
@@ -1138,6 +1138,14 @@ def get_points(self):
11381138
self._check(points)
11391139
return points
11401140

1141+
def contains(self, x, y):
1142+
# Docstring inherited.
1143+
return self._bbox.contains(*self._transform.inverted().transform((x, y)))
1144+
1145+
def fully_contains(self, x, y):
1146+
# Docstring inherited.
1147+
return self._bbox.fully_contains(*self._transform.inverted().transform((x, y)))
1148+
11411149

11421150
class LockableBbox(BboxBase):
11431151
"""

0 commit comments

Comments
 (0)