@@ -263,14 +263,22 @@ def contains(self, mouseevent):
263
263
else :
264
264
pixels = self .figure .dpi / 72. * self .pickradius
265
265
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 )
274
282
275
283
ind += self .ind_offset
276
284
0 commit comments