Skip to content

Commit

Permalink
Merge pull request #5500 from mdboom/picking-patches
Browse files Browse the repository at this point in the history
Fix #5475: Support tolerance when picking patches
  • Loading branch information
WeatherGod committed Nov 23, 2015
1 parent 605718b commit 8fcbf60
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions lib/matplotlib/patches.py
Expand Up @@ -142,14 +142,13 @@ def contains(self, mouseevent, radius=None):
Returns T/F, {}
"""
# This is a general version of contains that should work on any
# patch with a path. However, patches that have a faster
# algebraic solution to hit-testing should override this
# method.
if six.callable(self._contains):
return self._contains(self, mouseevent)
if radius is None:
radius = self.get_linewidth()
if cbook.is_numlike(self._picker):
radius = self._picker
else:
radius = self.get_linewidth()
inside = self.get_path().contains_point(
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
return inside, {}
Expand All @@ -160,7 +159,10 @@ def contains_point(self, point, radius=None):
(transformed with its transform attribute).
"""
if radius is None:
radius = self.get_linewidth()
if cbook.is_numlike(self._picker):
radius = self._picker
else:
radius = self.get_linewidth()
return self.get_path().contains_point(point,
self.get_transform(),
radius)
Expand Down Expand Up @@ -670,15 +672,6 @@ def get_patch_transform(self):
self._update_patch_transform()
return self._rect_transform

def contains(self, mouseevent):
# special case the degenerate rectangle
if self._width == 0 or self._height == 0:
return False, {}

x, y = self.get_transform().inverted().transform_point(
(mouseevent.x, mouseevent.y))
return (x >= 0.0 and x <= 1.0 and y >= 0.0 and y <= 1.0), {}

def get_x(self):
"Return the left coord of the rectangle"
return self._x
Expand Down Expand Up @@ -1416,12 +1409,6 @@ def get_patch_transform(self):
self._recompute_transform()
return self._patch_transform

def contains(self, ev):
if ev.x is None or ev.y is None:
return False, {}
x, y = self.get_transform().inverted().transform_point((ev.x, ev.y))
return (x * x + y * y) <= 1.0, {}


class Circle(Ellipse):
"""
Expand Down

0 comments on commit 8fcbf60

Please sign in to comment.