Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41788da

Browse filesBrowse files
committed
Fix patch contains logic for patches that don't have any codes
1 parent 4f76f04 commit 41788da
Copy full SHA for 41788da

File tree

Expand file treeCollapse file tree

1 file changed

+19
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-11
lines changed

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+19-11Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,33 @@ def _process_radius(self, radius):
123123
return _radius
124124

125125
def contains(self, mouseevent, radius=None):
126-
"""Test whether the mouse event occurred in the patch.
126+
"""
127+
Test whether the mouse event occurred in the patch.
127128
128-
Returns T/F, {}
129+
Returns
130+
-------
131+
(bool, empty dict)
129132
"""
130133
if self._contains is not None:
131134
return self._contains(self, mouseevent)
132135
radius = self._process_radius(radius)
133136
codes = self.get_path().codes
134-
vertices = self.get_path().vertices
135-
# if the current path is concatenated by multiple sub paths.
136-
# get the indexes of the starting code(MOVETO) of all sub paths
137-
idxs, = np.where(codes == Path.MOVETO)
138-
# Don't split before the first MOVETO.
139-
idxs = idxs[1:]
140-
return any(
137+
if codes is not None:
138+
vertices = self.get_path().vertices
139+
# if the current path is concatenated by multiple sub paths.
140+
# get the indexes of the starting code(MOVETO) of all sub paths
141+
idxs, = np.where(codes == Path.MOVETO)
142+
# Don't split before the first MOVETO.
143+
idxs = idxs[1:]
144+
subpaths = map(
145+
Path, np.split(vertices, idxs), np.split(codes, idxs))
146+
else:
147+
subpaths = [self.get_path()]
148+
inside = any(
141149
subpath.contains_point(
142150
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
143-
for subpath in map(
144-
Path, np.split(vertices, idxs), np.split(codes, idxs))), {}
151+
for subpath in subpaths)
152+
return inside, {}
145153

146154
def contains_point(self, point, radius=None):
147155
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.