コード例 #1
0
def test_point():
    poly1 = [(1,1), (1,-1), (-1,-1), (-1,1)]
    poly2 = [(2,2), (1,-1), (-1,-1), (-1,1)]
    assert helpers.pointInPolygon(0, 0, poly1)
    assert helpers.pointInPolygon(12, 12, poly1) == False
    assert helpers.pointInPolygon(0, 0, [(0,0), (1,1)]) == False

    helpers.nxutils = nxutils
    matplotlib.__version__ = '1.1'  # matplotlib.nxutils
    assert helpers.polygonsOverlap(poly1, poly2)
    del(helpers.nxutils)

    matplotlib.__version__ = '0.0'    # pure python
    assert helpers.polygonsOverlap(poly1, poly2)
    matplotlib.__version__ = mpl_version
コード例 #2
0
def test_point():
    poly1 = [(1, 1), (1, -1), (-1, -1), (-1, 1)]
    poly2 = [(2, 2), (1, -1), (-1, -1), (-1, 1)]
    assert helpers.pointInPolygon(0, 0, poly1)
    assert (helpers.pointInPolygon(12, 12, poly1) is False)
    assert (helpers.pointInPolygon(0, 0, [(0, 0), (1, 1)]) is False)

    if have_nxutils:
        helpers.nxutils = nxutils
        matplotlib.__version__ = '1.1'  # matplotlib.nxutils
        assert helpers.polygonsOverlap(poly1, poly2)
        del helpers.nxutils

    matplotlib.__version__ = '0.0'  # pure python
    assert helpers.polygonsOverlap(poly1, poly2)
    matplotlib.__version__ = mpl_version
コード例 #3
0
ファイル: basevisual.py プロジェクト: Gianluigi/psychopy
    def contains(self, x, y=None):
        """Determines if a point x,y is inside the extent of the stimulus.

        Can accept: a) two args, x and y; b) one arg, as a point (x,y) that is
        list-like; or c) an object with a getPos() method that returns x,y, such
        as a mouse. Returns True if the point is within the area defined by `vertices`.
        This handles complex shapes, including concavities and self-crossings.

        Note that, if your stimulus uses a mask (such as a Gaussian blob) then
        this is not accounted for by the `contains` method; the extent of the
        stmulus is determined purely by the size, pos and orientation settings
        (and by the vertices for shape stimuli).

        See coder demo, shapeContains.py
        """
        if self.needVertexUpdate:
            self._calcVerticesRendered()
        if hasattr(x, 'getPos'):
            x, y = x.getPos()
        elif type(x) in [list, tuple, numpy.ndarray]:
            x, y = x[0], x[1]
        if self.units in ['deg','degs']:
            x, y = deg2pix(numpy.array((x, y)), self.win.monitor)
        elif self.units == 'cm':
            x, y = cm2pix(numpy.array((x, y)), self.win.monitor)
        if self.ori:
            oriRadians = numpy.radians(self.ori)
            sinOri = numpy.sin(oriRadians)
            cosOri = numpy.cos(oriRadians)
            x0, y0 = x-self._posRendered[0], y-self._posRendered[1]
            x = x0 * cosOri - y0 * sinOri + self._posRendered[0]
            y = x0 * sinOri + y0 * cosOri + self._posRendered[1]

        return pointInPolygon(x, y, self)
コード例 #4
0
ファイル: image.py プロジェクト: Gianluigi/psychopy
    def contains(self, x, y=None):
        """Determines if a point x,y is on the image (within its boundary).

        See :class:`~psychopy.visual.ShapeStim` `.contains()`.
        """
        if hasattr(x, 'getPos'):
            x,y = x.getPos()
        elif type(x) in [list, tuple, numpy.ndarray]:
            x,y = x[0:2]
        return pointInPolygon(x, y, self)
コード例 #5
0
ファイル: basevisual.py プロジェクト: larigaldie-n/psychopy
    def contains(self, x, y=None, units=None):
        """Determines if a point x,y is inside the extent of the stimulus.

        Can accept variety of input options:
            + two separate args, x and y
            + one arg (list, tuple or array) containing two vals (x,y)
            + an object with a getPos() method that returns x,y, such
                as a :class:`~psychopy.event.Mouse`. Returns `True` if the point is
                within the area defined by `vertices`.

        This method handles complex shapes, including concavities and self-crossings.

        Note that, if your stimulus uses a mask (such as a Gaussian blob) then
        this is not accounted for by the `contains` method; the extent of the
        stmulus is determined purely by the size, pos and orientation settings
        (and by the vertices for shape stimuli).

        See coder demo, shapeContains.py
        """
        #get the object in pixels
        if hasattr(x, 'verticesPix'):
            xy = x.verticesPix #access only once - this is a property (slower to access)
            units = 'pix' #we can forget about the units
        elif hasattr(x, 'getPos'):
            xy = x.getPos()
            units = x.units
        elif type(x) in [list, tuple, numpy.ndarray]:
            xy = numpy.array(x)
        else:
            xy = numpy.array((x,y))
        #try to work out what units x,y has
        if units is None:
            if hasattr(xy, 'units'):
                units = xy.units
            else:
                units = self.units
        if units != 'pix':
            xy = convertToPix(xy, pos=0, units=units, win=self.win)
        # ourself in pixels
        selfVerts = self.verticesPix
        return pointInPolygon(xy[0], xy[1], poly = selfVerts)
コード例 #6
0
ファイル: basevisual.py プロジェクト: rpbaxter/psychopy
    def contains(self, x, y=None, units=None):
        """Determines if a point x,y is inside the extent of the stimulus.

        Can accept variety of input options:
            + two separate args, x and y
            + one arg (list, tuple or array) containing two vals (x,y)
            + an object with a getPos() method that returns x,y, such
                as a :class:`~psychopy.event.Mouse`. Returns `True` if the point is
                within the area defined by `vertices`.

        This method handles complex shapes, including concavities and self-crossings.

        Note that, if your stimulus uses a mask (such as a Gaussian blob) then
        this is not accounted for by the `contains` method; the extent of the
        stmulus is determined purely by the size, pos and orientation settings
        (and by the vertices for shape stimuli).

        See coder demo, shapeContains.py
        """
        #get the object in pixels
        if hasattr(x, 'verticesPix'):
            xy = x.verticesPix  #access only once - this is a property (slower to access)
            units = 'pix'  #we can forget about the units
        elif hasattr(x, 'getPos'):
            xy = x.getPos()
            units = x.units
        elif type(x) in [list, tuple, numpy.ndarray]:
            xy = numpy.array(x)
        else:
            xy = numpy.array((x, y))
        #try to work out what units x,y has
        if units is None:
            if hasattr(xy, 'units'):
                units = xy.units
            else:
                units = self.units
        if units != 'pix':
            xy = convertToPix(xy, pos=0, units=units, win=self.win)
        # ourself in pixels
        selfVerts = self.verticesPix
        return pointInPolygon(xy[0], xy[1], poly=selfVerts)