def test_circumference_simple(self): p1 = Circle() p2 = Circle(Vec2D(3, 0), 1) poly = Polygon([p1, p2]) self.assertAlmostEqual(poly.circumference(), 6 + 2 * pi)
def test_circumference_simple(self): p1 = Circle() p2 = Circle(Vec2D(3, 0), 1) poly = Polygon([p1, p2]) self.assertAlmostEqual(poly.circumference(), 6 + 2*pi)
def test_polygon_from_circles_normal(self): ref = dummy_polygon() poly = Polygon(ref.corners) self.assertTrue(len(ref.corners) == len(poly.corners)) for ref_corner in ref.corners: self.assertTrue(ref_corner in poly.corners) self.assertTrue(len(ref.sides) == len(poly.sides)) for ref_side in ref.sides: self.assertTrue(ref_side in poly.sides)
def dummy_polygon(): "return a dummy triangular polygon" circ1 = Circle() circ2 = Circle(Vec2D(4, 0)) circ3 = Circle(Vec2D(0, 4)) side2_helper = Vec2D(sqrt(2.0) / 2.0, sqrt(2.0) / 2.0) side2_pos1 = circ2.pos + side2_helper side2_pos2 = circ3.pos + side2_helper side1 = Tangent(Vec2D(0, -1), circ1, -1, Vec2D(4, -1), circ2, 1) side2 = Tangent(side2_pos1, circ2, -1, side2_pos2, circ3, 1) side3 = Tangent(Vec2D(-1, 4), circ3, -1, Vec2D(-1, 0), circ1, 1) return Polygon([circ1, circ2, circ3], [side1, side2, side3])
def main(): "draw loop" start = Vec2D(0.1, 0.1) end = Vec2D(2.1, 1.1) direction = Vec2D(0, 0.1) obs1 = Circle(Vec2D(1.5, 0.75), 0.2) #obs2 = Circle(Vec2D(0.9, 0.6), 0.2) corner1 = Circle(Vec2D(), 0.1) corner2 = Circle(Vec2D(0.5, 0), 0.1) side1 = Tangent(Vec2D(0, -0.1), corner1, -1, Vec2D(0.5, -0.1), corner2, 1) side2 = Tangent(Vec2D(0, 0.1), corner1, 1, Vec2D(0.5, 0.1), corner2, -1) poly1 = Polygon([corner1, corner2], [side1, side2]) + Vec2D(0.15, 0.3) circs = [obs1] polys = [poly1] paused = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_p: paused = not paused if not paused: SCREEN.fill(BLACK) #SCRREN.blit(BACKGROUND, (0, 0)) path = get_path(SETTINGS, polys, circs, start, direction, 0, end) draw_pos(start) draw_pos(end) draw_env(SETTINGS, circs, polys) draw_path(path) pygame.display.update()
def translated_dummy(vec): "return dummy triangular polygon manually translated by vec" delta_x = vec.pos_x delta_y = vec.pos_y circ1 = Circle(Vec2D(delta_x, delta_y)) circ2 = Circle(Vec2D(4 + delta_x, 0 + delta_y)) circ3 = Circle(Vec2D(0 + delta_x, 4 + delta_y)) side2_helper = Vec2D(sqrt(2.0) / 2.0, sqrt(2.0) / 2.0) side2_pos1 = circ2.pos + side2_helper side2_pos2 = circ3.pos + side2_helper side1 = Tangent(Vec2D(0 + delta_x, -1 + delta_y), circ1, -1, Vec2D(4 + delta_x, -1 + delta_y), circ2, 1) side2 = Tangent(side2_pos1, circ2, -1, side2_pos2, circ3, 1) side3 = Tangent(Vec2D(-1 + delta_x, 4 + delta_y), circ3, -1, Vec2D(-1 + delta_x, 0 + delta_y), circ1, 1) return Polygon([circ1, circ2, circ3], [side1, side2, side3])
CIRCLE1 = Circle(Vec2D(0, 0), 0.2) CIRCLE2 = Circle(Vec2D(1.066, 0), 0.2) CIRCLE3 = Circle(Vec2D(1.066, 0.6), 0.2) CIRCLE4 = Circle(Vec2D(0, 0.6), 0.2) CORNERS = [CIRCLE1, CIRCLE2, CIRCLE3, CIRCLE4] SIDE1 = Tangent(Vec2D(0, -0.2), CIRCLE1, -1, Vec2D(1.066, -0.2), CIRCLE2, 1) SIDE2 = Tangent(Vec2D(1.266, 0), CIRCLE2, -1, Vec2D(1.266, 0.6), CIRCLE3, 1) SIDE3 = Tangent(Vec2D(1.066, 0.8), CIRCLE3, -1, Vec2D(0, 0.8), CIRCLE4, 1) SIDE4 = Tangent(Vec2D(-0.2, 0.6), CIRCLE4, -1, Vec2D(-0.2, 0), CIRCLE1, 1) SIDES = [SIDE1, SIDE2, SIDE3, SIDE4] STAIRS = Polygon(CORNERS, SIDES) STAIRS = STAIRS + Vec2D(1.5 - 1.066 / 2, 0) class Settings(object): "settings class memorizing settings for molly" def __init__(self, max_acc=1.6, max_v=0.6, time_resolution=0.1, static_poly_obs=[STAIRS], static_circ_obs=[], obs_min_r=0.1, playground_dim=(3.0, 2.0)):
def test_polygon_from_circles_bad2(self): Polygon([Circle()])
def test_polygon_from_circles_bad1(self): Polygon([])