def main(): parser = get_parser() args = parser.parse_args() points = [[0, 5], [-1, 4], [-2, 1], [-2, 0], [-1, -3], [0, -5]] poly = Polygon([Vector(*p) for p in points]).translate(Vector(0.5, 0)) shapes = { "cirlce": Circle(Vector(0, 0), radius=2), "polygon": poly, "triangle": Triangle([Vector(-2, 2), Vector(0, -2), Vector(4, 4)]), "aabb": AABB(Vector(-3.5, -2.5), Vector(1, 4)) } shape = shapes[args.shape] segments = [] for angle in range(360, step=1): d = Vector.polar_deg(angle) p = d * -10 t = shape.raycast(p, d) p2 = p + d * t segments.append(Segment(p, p2)) debug_draw(shape, *segments)
def test_vector_unit(self): self.assertEqual(Vector(0, 2).unit(), Vector(0, 1)) self.assertEqual(Vector(0, 1).unit(), Vector(0, 1)) self.assertEqual(Vector(1, 1).unit(), Vector.polar_deg(45))