def test_off_axis_off_origin(self): origin = Point(2, 2) start = Point(6, 3) clockwise = TurnDirection.RIGHT counterclockwise = TurnDirection.LEFT self.assertEqual(Point(3, -2), rotate(origin, start, clockwise, 90)) self.assertEqual(Point(1, 6), rotate(origin, start, counterclockwise, 90))
def test_off_axis(self): origin = Point(0, 0) start = Point(4, 1) clockwise = TurnDirection.RIGHT counterclockwise = TurnDirection.LEFT self.assertEqual(Point(1, -4), rotate(origin, start, clockwise, 90)) self.assertEqual(Point(-1, 4), rotate(origin, start, counterclockwise, 90))
def test_unit_no_turn(self): origin = Point(0, 0) up = Point(0, 1) down = Point(0, -1) left = Point(-1, 0) right = Point(1, 0) clockwise = TurnDirection.RIGHT counterclockwise = TurnDirection.LEFT self.assertEqual(up, rotate(origin, up, clockwise, 0)) self.assertEqual(down, rotate(origin, down, clockwise, 0)) self.assertEqual(left, rotate(origin, left, clockwise, 0)) self.assertEqual(right, rotate(origin, right, clockwise, 0))
def move_by_waypoint(directions): way_point = PathPoint(10, 1, 0) ship = Point(0, 0) for direction in directions: code = direction[0] argument = int(direction[1:]) if code == "F": ship_x = ship.x_coordinate + argument * way_point.get_point( ).x_coordinate ship_y = ship.y_coordinate + argument * way_point.get_point( ).y_coordinate ship = Point(ship_x, ship_y) elif code in ("C", "A"): if code == "C": turn = TurnDirection.RIGHT else: turn = TurnDirection.LEFT new_way_point = rotate(Point(0, 0), way_point.get_point(), turn, argument) way_point = PathPoint(new_way_point.x_coordinate, new_way_point.y_coordinate, 0) else: way_path = make_path(way_point, direction) way_point = way_path[-1] return ship
def test_example(self): origin = Point(0, 0) start = Point(10, 4) final = Point(4, -10) clockwise = TurnDirection.RIGHT self.assertEqual(final, rotate(origin, start, clockwise, 90))