From 41788da9738365133f8ce90caea626f60b3d4e5e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 21 Apr 2019 13:06:07 +0100 Subject: [PATCH] Fix patch contains logic for patches that don't have any codes --- lib/matplotlib/patches.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index d34a92aa1ac0..c125bca741b1 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -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): """