def test_objects_collide1(self): '''Test the objects collision detection w/ multiple scenarios.''' pos1, r1 = (0,0), 1 pos2, r2 = (0,2), 1 self.assertFalse(Helper.objects_collide(pos1, r1, pos2, r2)) pos1, r1 = (0,0), 1 pos2, r2 = (0,1), 0 self.assertFalse(Helper.objects_collide(pos1, r1, pos2, r2)) pos1, r1 = (0,0), 1 pos2, r2 = (0,1), 1 self.assertTrue(Helper.objects_collide(pos1, r1, pos2, r2)) pos1, r1 = (0,0), 1 pos2, r2 = (2,2), 1 self.assertFalse(Helper.objects_collide(pos1, r1, pos2, r2))
def __generate_coord_without_collision(self, collision_list, collision_radius): '''Generate a new coordinate so that it does not collide with any of the coords from collision_list. ''' x,y = self.__get_dimensions() while True: coord = (random.random()*x, random.random()*y) # new generated coord should not conflict w/ collision list. for (coord2, collision_radius2) in collision_list: if Helper.objects_collide(coord, collision_radius, coord2, collision_radius2): break # did not break, thus no collision w/ any of coords from list. else: return coord
def objects_collide(o1, o2): return Helper.objects_collide(o1.coord, o1.collision_radius, o2.coord, o2.collision_radius)
def test_objects_collide2(self): pos1, r1 = (0,0), 10 r2 = 15 pos2 = (0, r1 + r2 - 1) self.assertTrue(Helper.objects_collide(pos1, r1, pos2, r2))