Skip to content

Commit 050b20c

Browse files
committed
Fix containment test with nonlinear transforms.
1 parent 3b9a92d commit 050b20c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/matplotlib/path.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,15 @@ def contains_point(self, point, transform=None, radius=0.0):
493493
"""
494494
if transform is not None:
495495
transform = transform.frozen()
496-
result = _path.point_in_path(point[0], point[1], radius, self,
497-
transform)
498-
return result
496+
from .transforms import Affine2D
497+
# `point_in_path` does not handle nonlinear transforms, so we
498+
# transform the path ourselves. If `transform` is affine, letting
499+
# `point_in_path` handle the transform avoids allocating an extra
500+
# buffer.
501+
if transform and not isinstance(transform, Affine2D):
502+
self = transform.transform_path(self)
503+
transform = None
504+
return _path.point_in_path(point[0], point[1], radius, self, transform)
499505

500506
def contains_points(self, points, transform=None, radius=0.0):
501507
"""

0 commit comments

Comments
 (0)