示例#1
0
 def test_overlap(self):
     '''
     Test overlap between circles and rectangles.
     '''
     new_rect1 = Rectangle(100, 100)
     new_rect2 = Rectangle(50, 150, 50, 50)
     circ1 = Circle(25) 
     circ2 = Circle(30, 0, -5)
     self.assertEqual(-50, new_rect1.get_overlap(new_rect2))
     self.assertEqual(new_rect1.get_overlap(new_rect2),
                      new_rect2.get_overlap(new_rect1))
     self.assertEqual(-50, circ1.get_overlap(new_rect1))
     self.assertEqual(circ1.get_overlap(new_rect1),
                      new_rect1.get_overlap(circ1))
     self.assertAlmostEqual(math.sqrt(2)*25 - 25,
                            circ1.get_overlap(new_rect2))
     self.assertEqual(circ1.get_overlap(new_rect2),
                      new_rect2.get_overlap(circ1))
     self.assertEqual(-50, circ1.get_overlap(circ2))
     self.assertEqual(circ1.get_overlap(circ2),
                      circ2.get_overlap(circ1))
     circ1.set_position(80, 50)
     self.assertEqual(-20, circ1.get_overlap(new_rect2))
     self.assertEqual(circ1.get_overlap(new_rect2),
                      new_rect2.get_overlap(circ1))
示例#2
0
 def test_circle_distance_from_frame(self):
     '''
     Test overlap between circles and frame.
     '''
     new_circle = Circle(20)
     new_circle.set_position(160, 160)
     self.assertAlmostEqual(200 - math.sqrt(2)*20 - 20,
                            new_circle.get_distance_from_frame(200), 2) 
     new_circle.set_position(420, 180)
     self.assertAlmostEqual(-60, new_circle.get_distance_from_frame(200), 2)
     new_circle.set_position(180 + 1 / math.sqrt(2) * 180, 
                             180 + 1 / math.sqrt(2) * 180)
     self.assertAlmostEqual(0, new_circle.get_distance_from_frame(200), 2)