From 42cbf6f85c23d769a04c084ce089e44e92b4cdae Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 17 Dec 2023 07:21:00 +0100 Subject: [PATCH] Coordinate().__eq__: enable comparison with tuples --- src/tools/coordinate.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/coordinate.py b/src/tools/coordinate.py index 5c9c538..e5e78d5 100644 --- a/src/tools/coordinate.py +++ b/src/tools/coordinate.py @@ -261,6 +261,12 @@ class Coordinate(tuple): else: return self.__class__(-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: if self[2] is None: return self.__class__(self[0] + other[0], self[1] + other[1])