Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be9a310

Browse files
committed
Merge pull request matplotlib#1002 from dhyams/fix_segment_hits
Fixed potential overflow exception in the lines.contains() method
2 parents 9911308 + 6f3dab5 commit be9a310

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lib/matplotlib/lines.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,22 @@ def contains(self, mouseevent):
264264
else:
265265
pixels = self.figure.dpi/72. * self.pickradius
266266

267-
# Check for collision
268-
if self._linestyle in ['None',None]:
269-
# If no line, return the nearby point(s)
270-
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
271-
ind, = np.nonzero(np.less_equal(d, pixels**2))
272-
else:
273-
# If line, return the nearby segment(s)
274-
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
267+
# the math involved in checking for containment (here and inside of segment_hits) assumes
268+
# that it is OK to overflow. In case the application has set the error flags such that
269+
# an exception is raised on overflow, we temporarily set the appropriate error flags here
270+
# and set them back when we are finished.
271+
olderrflags = np.seterr(all='ignore')
272+
try:
273+
# Check for collision
274+
if self._linestyle in ['None',None]:
275+
# If no line, return the nearby point(s)
276+
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
277+
ind, = np.nonzero(np.less_equal(d, pixels**2))
278+
else:
279+
# If line, return the nearby segment(s)
280+
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
281+
finally:
282+
np.seterr(**olderrflags)
275283

276284
ind += self.ind_offset
277285

0 commit comments

Comments
 (0)