8000 Fix containment test with nonlinear transforms. · matplotlib/matplotlib@15eb7e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15eb7e7

Browse files
committed
Fix containment test with nonlinear transforms.
1 parent 747792b commit 15eb7e7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/matplotlib/path.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
import numpy as np
2424

25-
from matplotlib import _path
26-
from matplotlib.cbook import simple_linear_interpolation, maxdict
27-
from matplotlib import rcParams
25+
from . import _path, rcParams
26+
from .cbook import simple_linear_interpolation, maxdict
2827

2928

3029
class Path(object):
@@ -493,9 +492,14 @@ def contains_point(self, point, transform=None, radius=0.0):
493492
"""
494493
if transform is not None:
495494
transform = transform.frozen()
496-
result = _path.point_in_path(point[0], point[1], radius, self,
497-
transform)
498-
return result
495+
# `point_in_path` does not handle nonlinear transforms, so we
496+
# transform the path ourselves. If `transform` is affine, letting
497+
# `point_in_path` handle the transform avoids allocating an extra
498+
# buffer.
499+
if transform and not transform.is_affine:
500+
self = transform.transform_path(self)
501+
transform = None
502+
return _path.point_in_path(point[0], point[1], radius, self, transform)
499503

500504
def contains_points(self, points, transform=None, radius=0.0):
501505
"""

0 commit comments

Comments
 (0)
0