Ejemplo n.º 1
0
    def contains(self, mouseevent):
        '''
        a hit test based on what is used in 
        line2D
        '''        
        from matplotlib.lines import segment_hits
        if self.figure is None:
            pixels = self.pickradius
        else:
            pixels = self.figure.dpi / 72. * self.pickradius

        olderrflags = np.seterr(all='ignore')
        transformed_path = self._get_transformed_path()
        path, affine = transformed_path.get_transformed_path_and_affine()
        path = affine.transform_path(path)
        xy = path.vertices
        xt = xy[:, 0]
        yt = xy[:, 1]

        try:
            # If line, return the nearby segment(s)
            ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
        finally:
            np.seterr(**olderrflags)
        return len(ind) > 0, dict(ind=ind)
Ejemplo n.º 2
0
    def contains(self, mouseevent):
        '''
        a hit test based on what is used in 
        line2D
        '''
        from matplotlib.lines import segment_hits
        if self.figure is None:
            pixels = self.pickradius
        else:
            pixels = self.figure.dpi / 72. * self.pickradius

        olderrflags = np.seterr(all='ignore')
        transformed_path = self._get_transformed_path()
        path, affine = transformed_path.get_transformed_path_and_affine()
        path = affine.transform_path(path)
        xy = path.vertices
        xt = xy[:, 0]
        yt = xy[:, 1]

        try:
            # If line, return the nearby segment(s)
            ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
        finally:
            np.seterr(**olderrflags)
        return len(ind) > 0, dict(ind=ind)
Ejemplo n.º 3
0
    def contains(self, mouseevent):
        """
        Test whether the mouse event occurred in the collection.

        Returns T/F, dict(ind=itemlist), where every item in itemlist contains the event.
        """
        import matplotlib.lines as ML
        if callable(self._contains): return self._contains(self,mouseevent)

        # TODO: add offset processing; adjusting the mouse for each offset
        # will be somewhat cheaper than adjusting the segments.
        if self._offsets != None:
            raise NotImplementedError, "LineCollection does not yet support picking with offsets"

        mx,my = mouseevent.x,mouseevent.y
        transform = self.get_transform()

        ind = []
        for this in xrange(len(self._segments)):
            xy = transform.seq_xy_tups(self._segments[this])
            this_ind = ML.segment_hits(mx,my,xy[:,0],xy[:,1],self.pickradius)
            ind.extend([(this,k) for k in this_ind])
        return len(ind)>0,dict(ind=ind)
Ejemplo n.º 4
0
    def contains(self, mouseevent):
        """
        Test whether the mouse event occurred in the collection.

        Returns T/F, dict(ind=itemlist), where every item in itemlist contains the event.
        """
        import matplotlib.lines as ML
        if callable(self._contains): return self._contains(self,mouseevent)

        # TODO: add offset processing; adjusting the mouse for each offset
        # will be somewhat cheaper than adjusting the segments.
        if self._offsets != None:
            raise NotImplementedError, "LineCollection does not yet support picking with offsets"

        mx,my = mouseevent.x,mouseevent.y
        transform = self.get_transform()

        ind = []
        for this in xrange(len(self._segments)):
            xy = transform.seq_xy_tups(self._segments[this])
            this_ind = ML.segment_hits(mx,my,xy[:,0],xy[:,1],self.pickradius)
            ind.extend([(this,k) for k in this_ind])
        return len(ind)>0,dict(ind=ind)
Ejemplo n.º 5
0
def test_segment_hits():
    """Test a problematic case."""
    cx, cy = 553, 902
    x, y = np.array([553., 553.]), np.array([95., 947.])
    radius = 6.94
    assert_array_equal(mlines.segment_hits(cx, cy, x, y, radius), [0])