def test_is_false_for_line_in_the_bottom_left_corner(self): corner = Point( self.obstacle.rect.left, self.obstacle.rect.bottom) # Build a line so that the player is on its edge line = Polygon([ corner + Point(-10, -10), corner + Point(10, 10)]) self.assertFalse( self.obstacle.is_to_the_right(line))
def test_creates_a_polygon(self): self.assertEqual(rectangle(A, E), Polygon([A, B, E, D]))
def test_distance_y_positive(self): first = Polygon([A, B]) other = Polygon([C, E, D]) self.assertEqual(first.distance_y(other), 2)
def test_distance_x_negative(self): first = Polygon([B, E]) other = Polygon([A, C, D]) self.assertEqual(first.distance_x(other), -2)
def test_distance_x_positive(self): first = Polygon([A, D]) other = Polygon([B, C, E]) self.assertEqual(first.distance_x(other), 2)
def test_build_surface_mask(self): polygon = Polygon([A, B, C]) expected = np.array([[1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]) self.assertTrue(np.array_equal(polygon.build_surface_mask(), expected))
def test_edges(self): polygon = Polygon([A, B, C]) expected = [Edge(A, B), Edge(B, C), Edge(C, A)] self.assertEqual(polygon.edges(), expected)
def test_radius(self): polygon = Polygon([A, B, E, D]) self.assertEqual(polygon.radius(), ceil(2 * sqrt(2)))
def test_centre(self): polygon = Polygon([A, B, E, D]) self.assertEqual(polygon.centre(), C)