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

Skip to content

Commit 6f3dab5

Browse files
committed
Fixed potential overflow exception in the lines.contains() method, if the application happened
to have set the numpy error flags to raise exceptions in case of overflow.
1 parent 2bb91ce commit 6f3dab5

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

lib/matplotlib/lines.py

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

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

275283
ind += self.ind_offset
276284

0 commit comments

Comments
 (0)