MCPcopy Create free account
hub / github.com/JoshuaPostel/texaform / Point

Class Point

python/utils.py:35–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34@dataclass
35class 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
63class Rect:

Callers 15

__init__Method · 0.90
gotoMethod · 0.90
make.pyFile · 0.90
__init__Method · 0.90
statMethod · 0.90
gather.pyFile · 0.90
__init__Method · 0.90
addressMethod · 0.90
takeMethod · 0.90
expand_areaMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected