FIX Coordinate().getNeighbours() min/maxY
All checks were successful
Publish to PyPI / Publish to PyPI (push) Successful in 1m4s

FIX Coordinate() not hashable after implementing __eq__
This commit is contained in:
Stefan Harmuth 2023-12-17 08:24:19 +01:00
parent 42cbf6f85c
commit b2cc1e814c

View File

@ -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,9 @@ 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: def __eq__(self, other: Coordinate | tuple) -> bool:
if self[2] is None: if self[2] is None:
return self[0] == other[0] and self[1] == other[1] return self[0] == other[0] and self[1] == other[1]