Пример #1
0
    def test_gives_correct_area_scaling(self):

        polygon = np.array([
            (-3, -2),
            (-1, 4),
            (6, 1),
            (3, 10),
            (-4, 9),
        ])

        cx, cy = poly.center_of_polygon(polygon)

        res = poly.scale_polygon(polygon, 2.0)

        exp = np.array([
            (-6.36666667, -9.5333333),
            (-2.36666667,  2.4666667),
            (11.63333333, -3.5333333),
            (5.63333333, 14.4666667),
            (-8.36666667, 12.4666667),
        ])
        np.testing.assert_almost_equal(res, exp)

        rx, ry = poly.center_of_polygon(res)

        self.assertAlmostEqual(rx, cx)
        self.assertAlmostEqual(ry, cy)

        area = poly.area_of_polygon(res)
        self.assertEqual(area, 240)
Пример #2
0
    def test_gives_correct_center_circle(self):

        theta = np.linspace(0, 2*np.pi, 50)
        polygon = np.stack([
            np.cos(theta) + 5,
            np.sin(theta) - 1,
        ], axis=1)

        cx, cy = poly.center_of_polygon(polygon)

        np.testing.assert_almost_equal(cx, 5, decimal=3)
        np.testing.assert_almost_equal(cy, -1, decimal=3)
Пример #3
0
    def test_gives_correct_center_evenly_sampled(self):

        # It's a square... so center is -1, +1
        polygon = np.array([
            (-4, -2),
            (-4, 4),
            (2, 4),
            (2, -2),
        ])

        cx, cy = poly.center_of_polygon(polygon)

        self.assertEqual(cx, -1)
        self.assertEqual(cy, 1)
Пример #4
0
    def test_gives_correct_center_counter_clockwise(self):

        polygon = np.array([
            (2, -2),
            (2, 4),
            (1, 4),
            (-1, 4),
            (-2, 4),
            (-3, 4),
            (-4, 4),
            (-4, -2),
        ])

        cx, cy = poly.center_of_polygon(polygon)

        self.assertEqual(cx, -1)
        self.assertEqual(cy, 1)
Пример #5
0
    def test_gives_correct_center_clockwise(self):

        # It's a square... so center is -1, +1
        # BUUUT, we have extra samples along the line from x=(-4 to +2)
        polygon = np.array([
            (-4, -2),
            (-4, 4),
            (-3, 4),
            (-2, 4),
            (-1, 4),
            (1, 4),
            (2, 4),
            (2, -2),
        ])

        cx, cy = poly.center_of_polygon(polygon)

        self.assertEqual(cx, -1)
        self.assertEqual(cy, 1)