def test_points_for_rectangle_at_origin(self): width = 5 height = 3 rect = Rectangle(width, height) expected_points = [Point2D(0, 0), Point2D(width, 0), Point2D(width, height), Point2D(0, height)] actual_points = rect.points self._assert_points_are_equal(expected_points, actual_points)
def test_rotate_0_degrees(self): width = 5 height = 3 rect = Rectangle(width, height) rect.rotate(0) expected_points = [Point2D(0, 0), Point2D(width, 0), Point2D(width, height), Point2D(0, height)] actual_points = rect.points self._assert_points_are_equal(expected_points, actual_points)
def test_rotate_clockwise(self): width = 5 height = 3 rect = Rectangle(width, height) rect.rotate(-90) expected_points = [Point2D(0, 0), Point2D(0, -width), Point2D(height, -width), Point2D(height, 0)] actual_points = rect.points self._assert_points_are_equal(expected_points, actual_points)
def test_rotate_2_times(self): width = 5 height = 3 rect = Rectangle(width, height) rect.rotate(45) rect.rotate(45) expected_points = [Point2D(0, 0), Point2D(0, width), Point2D(-height, width), Point2D(-height, 0)] actual_points = rect.points self._assert_points_are_equal(expected_points, actual_points)
def test_points_for_positioned_rectangle(self): width = 5 height = 3 position = Point2D(1, 2) rect = Rectangle(width, height) rect.position = position expected_points = [position, Point2D(position.x + width, position.y), Point2D(position.x + width, position.y + height), Point2D(position.x, position.y + height)] actual_points = rect.points self._assert_points_are_equal(expected_points, actual_points)
def test_fully_overlapping_oriented_boxes(self): box1 = CollisionablePolygonExample( [Point2D(-1, 1), Point2D(0, 2), Point2D(1, 1), Point2D(0, 0)]) box2 = CollisionablePolygonExample( [Point2D(-1, 1), Point2D(0, 2), Point2D(1, 1), Point2D(0, 0)]) self.assertTrue(CollisionDetection.are_colliding(box1, box2))
def test_touching_axis_aligned_boxes(self): box1 = CollisionablePolygonExample( [Point2D(0, 1), Point2D(1, 1), Point2D(1, 0), Point2D(0, 0)]) box2 = CollisionablePolygonExample( [Point2D(1, 1), Point2D(2, 1), Point2D(2, 0), Point2D(1, 0)]) self.assertTrue(CollisionDetection.are_colliding(box1, box2))
def test_partially_overlapping_axis_aligned_boxes(self): box1 = CollisionablePolygonExample( [Point2D(0, 1), Point2D(1, 1), Point2D(1, 0), Point2D(0, 0)]) box2 = CollisionablePolygonExample([ Point2D(0.5, 1), Point2D(2.5, 1), Point2D(2.5, 0), Point2D(1.5, 0) ]) self.assertTrue(CollisionDetection.are_colliding(box1, box2))
def test_falla(self): box1 = CollisionablePolygonExample([ Point2D(15, 5), Point2D(15.0, 3.0), Point2D(24.43, -2.92), Point2D(25, -1) ]) box2 = CollisionablePolygonExample([ Point2D(18.6, -0.5), Point2D(20.6, -0.5), Point2D(20.6, 0.5), Point2D(18.6, 0.5) ]) self.assertTrue(CollisionDetection.are_colliding(box1, box2))