8000 Fix patch contains logic for patches that don't have any codes by dstansby · Pull Request #13998 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix patch contains logic for patches that don't have any codes #13998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions lib/matplotlib/patches.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,33 @@ def _process_radius(self, radius):
return _radius

def contains(self, mouseevent, radius=None):
"""Test whether the mouse event occurred in the patch.
"""
Test whether the mouse event occurred in the patch.

Returns T/F, {}
Returns
-------
(bool, empty dict)
"""
if self._contains is not None:
return self._contains(self, mouseevent)
radius = self._process_radius(radius)
codes = self.get_path().codes
vertices = self.get_path().vertices
# if the current path is concatenated by multiple sub paths.
# get the indexes of the starting code(MOVETO) of all sub paths
idxs, = np.where(codes == Path.MOVETO)
# Don't split before the first MOVETO.
idxs = idxs[1:]
return any(
if codes is not None:
vertices = self.get_path().vertices
# if the current path is concatenated by multiple sub paths.
# get the indexes of the starting code(MOVETO) of all sub paths
idxs, = np.where(codes == Path.MOVETO)
# Don't split before the first MOVETO.
idxs = idxs[1:]
subpaths = map(
Path, np.split(vertices, idxs), np.split(codes, idxs))
else:
subpaths = [self.get_path()]
inside = any(
subpath.contains_point(
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
for subpath in map(
Path, np.split(vertices, idxs), np.split(codes, idxs))), {}
for subpath in subpaths)
return inside, {}

def contains_point(self, point, radius=None):
"""
Expand Down
0