Compare commits
2 Commits
2bec56eb1c
...
b2cc1e814c
| Author | SHA1 | Date | |
|---|---|---|---|
| b2cc1e814c | |||
| 42cbf6f85c |
@ -187,7 +187,7 @@ class Coordinate(tuple):
|
|||||||
nb_list = [(-1, 0), (1, 0), (0, -1), (0, 1)]
|
nb_list = [(-1, 0), (1, 0), (0, -1), (0, 1)]
|
||||||
|
|
||||||
for dx, dy in nb_list:
|
for dx, dy in nb_list:
|
||||||
if minX <= self[0] + dx <= maxX and minY <= self[0] + dy <= maxY:
|
if minX <= self[0] + dx <= maxX and minY <= self[1] + dy <= maxY:
|
||||||
yield self.__class__(self[0] + dx, self[1] + dy)
|
yield self.__class__(self[0] + dx, self[1] + dy)
|
||||||
else:
|
else:
|
||||||
if includeDiagonal:
|
if includeDiagonal:
|
||||||
@ -261,6 +261,15 @@ class Coordinate(tuple):
|
|||||||
else:
|
else:
|
||||||
return self.__class__(-self[0], -self[1], -self[2])
|
return self.__class__(-self[0], -self[1], -self[2])
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self[0], self[1], self[2]))
|
||||||
|
|
||||||
|
def __eq__(self, other: Coordinate | tuple) -> bool:
|
||||||
|
if self[2] is None:
|
||||||
|
return self[0] == other[0] and self[1] == other[1]
|
||||||
|
else:
|
||||||
|
return self[0] == other[0] and self[1] == other[1] and self[2] == other[2]
|
||||||
|
|
||||||
def __add__(self, other: Coordinate | tuple) -> Coordinate:
|
def __add__(self, other: Coordinate | tuple) -> Coordinate:
|
||||||
if self[2] is None:
|
if self[2] is None:
|
||||||
return self.__class__(self[0] + other[0], self[1] + other[1])
|
return self.__class__(self[0] + other[0], self[1] + other[1])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user