8000 Fix patch contains logic for patches that don't have any codes · matplotlib/matplotlib@5c0835f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c0835f

Browse files
committed
Fix patch contains logic for patches that don't have any codes
1 parent 4f76f04 commit 5c0835f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lib/matplotlib/patches.py

Lines changed: 20 additions & 12 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(
141-
subpath.contains_point(
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+
inside = any(
145+
subpath.contains_point(
146+
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
147+
for subpath in map(
148+
Path, np.split(vertices, idxs), np.split(codes, idxs)))
149+
else:
150+
inside = self.get_path().contains_point(
142151
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
143-
for subpath in map(
144-
Path, np.split(vertices, idxs), np.split(codes, idxs))), {}
152+
return inside, {}
145153

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

0 commit comments

Comments
 (0)
0