diff --git a/lib/matplotlib/tests/test_transforms.py b/lib/matplotlib/tests/test_transforms.py index 85df46b4c9d0..ee6754cb8da8 100644 --- a/lib/matplotlib/tests/test_transforms.py +++ b/lib/matplotlib/tests/test_transforms.py @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt import matplotlib.patches as mpatches import matplotlib.transforms as mtransforms +from matplotlib.transforms import Affine2D, Bbox, TransformedBbox from matplotlib.path import Path from matplotlib.testing.decorators import image_comparison, check_figures_equal @@ -755,3 +756,14 @@ def test_offset_copy_errors(): with pytest.raises(ValueError, match='For units of inches or points a fig kwarg is needed'): mtransforms.offset_copy(None, units='inches') + + +def test_transformedbbox_contains(): + bb = TransformedBbox(Bbox.unit(), Affine2D().rotate_deg(30)) + assert bb.contains(.8, .5) + assert bb.contains(-.4, .85) + assert not bb.contains(.9, .5) + bb = TransformedBbox(Bbox.unit(), Affine2D().translate(.25, .5)) + assert bb.contains(1.25, 1.5) + assert not bb.fully_contains(1.25, 1.5) + assert not bb.fully_contains(.1, .1) diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 0933a2c01c64..f2ffa09932de 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1138,6 +1138,14 @@ def get_points(self): self._check(points) return points + def contains(self, x, y): + # Docstring inherited. + return self._bbox.contains(*self._transform.inverted().transform((x, y))) + + def fully_contains(self, x, y): + # Docstring inherited. + return self._bbox.fully_contains(*self._transform.inverted().transform((x, y))) + class LockableBbox(BboxBase): """