| 33 | |
| 34 | @dataclass |
| 35 | class Point: |
| 36 | x: int |
| 37 | y: int |
| 38 | |
| 39 | def __hash__(self): |
| 40 | return hash((self.x, self.y)) |
| 41 | |
| 42 | def __add__(self, other) -> Self: |
| 43 | if isinstance(other, Point): |
| 44 | return Point(self.x + other.x, self.y + other.y) |
| 45 | else: |
| 46 | raise TypeError |
| 47 | |
| 48 | def taxi_distance(self, other) -> int: |
| 49 | return abs(self.x - other.x) + abs(self.y - other.y) |
| 50 | |
| 51 | def forward(self, direction: Direction, distance: int = 1) -> Self: |
| 52 | match direction: |
| 53 | case "N": |
| 54 | return Point(self.x, self.y - distance) # ty: ignore[invalid-return-type] |
| 55 | case "S": |
| 56 | return Point(self.x, self.y + distance) # ty: ignore[invalid-return-type] |
| 57 | case "E": |
| 58 | return Point(self.x + distance, self.y) # ty: ignore[invalid-return-type] |
| 59 | case "W": |
| 60 | return Point(self.x - distance, self.y) # ty: ignore[invalid-return-type] |
| 61 | |
| 62 | @dataclass |
| 63 | class Rect: |
no outgoing calls
no test coverage detected