Ejemplo n.º 1
0
    def test_inside_polygon(self):

        polygon_test_cases = [
            ([0.5, 0.5, -0.5, -0.5, 0.5], [0.0, 0.5, 0.5, -0.5, -0.5]),
        ]
        p_test_cases = [

            # (x,y),
            # inside
            (0, 0.000),
            #
            # # outside
            (-1, 1),
            (0, 1),
            (1, 1),
            (-1, 0),
            (1, 0),
            (-1, -1),
            (0, -1),
            (1, -1),

            # on the line test cases
            # inclusion is not defined if point lies on the line
            # (0.0, -0.5),
            # (0, 0.5),
            # (-0.5, 0),
            # (0.5, 0),
        ]
        expected_results = [(
            True,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
            False,
        )
                            # (True, True, True, True)
                            ]

        n = 0
        for coords in polygon_test_cases:
            i = 0
            for x, y in p_test_cases:
                assert inside_polygon(x, y, coords) == expected_results[n][i]
                i += 1
            n += 1
Ejemplo n.º 2
0
    def test_inside_polygon(self):
        p_test_cases = [
            # (x,y),
            (-1, 1),
            (0, 1),
            (1, 1),
            (-1, 0),
            (0, 0),
            (1, 0),
            (-1, -1),
            (0, -1),
            (1, -1),

            # on the line test cases
            # (-0.5, 0.5),
            # (0, 0.5),
            # (-0.5, 0),
            # (0.5, 0),
        ]

        polygon_test_cases = [
            ([0.5, -0.5, -0.5, 0.5], [0.5, 0.5, -0.5, -0.5]),
        ]

        expected_results = [
            (
                False,
                False,
                False,
                False,
                True,
                False,
                False,
                False,
                False,
            ),
        ]

        n = 0
        for coords in polygon_test_cases:
            i = 0
            for x, y in p_test_cases:
                assert inside_polygon(x, y, coords) == expected_results[n][i]
                i += 1
            n += 1
Ejemplo n.º 3
0
def contained(x, y, x_coords, y_coords):
    return inside_polygon(x, y, [x_coords, y_coords])