Example #1
0
def point_intersect_rectangle( point, rect ):
    """Calculates the intersection point of a point and a 2D rectangle.

    For 3D points, the Z axis will be ignored.

    :return: Returns True if the point is touching
    or within the rectangle.
    """
    left, right, bottom, top = rectangle.bounds( rect )
    if \
        point[ 0 ] < left or \
        point[ 0 ] > right or \
        point[ 1 ] < bottom or \
        point[ 1 ] > top:
        return None
    return point
Example #2
0
 def test_bounds(self):
     rect = rectangle.create_from_bounds(-1, 1, -2, 2)
     result = rectangle.bounds(rect)
     np.testing.assert_almost_equal(result, (-1,1,-2,2), decimal=5)
Example #3
0
    def test_bounds( self ):
        left = 0.0
        right = 5.0
        bottom = 0.0
        top = 5.0

        rect = numpy.array(
            [
                [ left, bottom ],
                [ right - left, top - bottom ],
                ]
            )

        left2, right2, bottom2, top2 = rectangle.bounds( rect )

        self.assertEqual(
            left,
            left2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            right,
            right2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            bottom,
            bottom2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            top,
            top2,
            "Bounds not calculated correctly"
            )

        left = 0.0
        right = 5.0
        bottom = 0.0
        top = 5.0

        # make rectangle inverse size
        rect = numpy.array(
            [
                [ right, top ],
                [ left - right, bottom - top ],
                ]
            )

        left2, right2, bottom2, top2 = rectangle.bounds( rect )

        self.assertEqual(
            left,
            left2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            right,
            right2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            bottom,
            bottom2,
            "Bounds not calculated correctly"
            )
        self.assertEqual(
            top,
            top2,
            "Bounds not calculated correctly"
            )
Example #4
0
 def test_bounds(self):
     rect = rectangle.create_from_bounds(-1, 1, -2, 2)
     result = rectangle.bounds(rect)
     np.testing.assert_almost_equal(result, (-1,1,-2,2), decimal=5)