Exemplo n.º 1
0
    def test_all_points_equidistant_to_anchor(self, n_sides, radius, ax, ay):

        shape = vector.RegularPolygon(sides=n_sides, radius=radius, anchor=(ax, ay))
        coords = shape[0]
        for i in range(0, len(coords) // 2, 2):
            distance = self.distance(coords[i], coords[i+1], -ax, -ay)
            self.assertAlmostEqual(distance, radius, places=1)
Exemplo n.º 2
0
    def test_all_points_at_side_distance_from_each_other(self, n_sides, side, ax, ay):

        shape = vector.RegularPolygon(sides=n_sides, side=side, anchor=(ax, ay))
        coords = shape[0]
        for i in range(0, len(coords) // 2, 2):
            distance = self.distance(*coords[i:i+4])
            self.assertAlmostEqual(distance, side, places=1)
        # Also assert distance from last to first.
        distance = self.distance(*coords[-2:], *coords[:2])
        self.assertAlmostEqual(distance, side, places=1)
Exemplo n.º 3
0
    def test_4_sided_polygon_at_angle_45(self):

        shape = vector.RegularPolygon(sides=4, side=10, angle=45)

        coords = shape[0]
        self.assert_almost_equal_coords(
            coords,
            [5, -5, 5, 5, -5, 5, -5, -5],
            places=1,
        )
Exemplo n.º 4
0
    def test_4_sided_polygon_at_angle_0(self):

        shape = vector.RegularPolygon(sides=4, radius=10, angle=0)

        coords = shape[0]
        self.assert_almost_equal_coords(
            coords,
            [10, 0, 0, 10, -10, 0, 0, -10],
            places=1,
        )
Exemplo n.º 5
0
    def test_N_sided_polygon_has_N_points(self, n_sides, radius, ax, ay):

        shape = vector.RegularPolygon(sides=n_sides, radius=radius, anchor=(ax, ay))
        # Two items (x, y) per point.
        n_points = len(shape[0]) // 2
        self.assertEqual(n_points, n_sides)
Exemplo n.º 6
0
    def test_create_with_both_radius_and_side_raises_ValueError(self):

        with self.assertRaises(ValueError):
            _shape = vector.RegularPolygon(sides=5, radius=42, side=42)
Exemplo n.º 7
0
    def test_create_with_no_radius_or_side_raises_ValueError(self):

        with self.assertRaises(ValueError):
            _shape = vector.RegularPolygon(sides=5)
Exemplo n.º 8
0
    def test_create_with_less_than_three_sides_raises_ValueError(self):

        for sides in range(-1, 3):
            with self.subTest(sides=sides):
                with self.assertRaises(ValueError):
                    _shape = vector.RegularPolygon(sides=sides, radius=42)