diff --git a/tools/coordinate.py b/tools/coordinate.py index 7912fb5..02f59bc 100644 --- a/tools/coordinate.py +++ b/tools/coordinate.py @@ -25,7 +25,7 @@ class Coordinate: Get distance to target Coordinate :param target: - :param algorithm: Calculation Mode (0 = Manhattan, 1 = Pythagoras) + :param algorithm: Calculation Algorithm (s. DistanceAlgorithm) :param includeDiagonals: in Manhattan Mode specify if diagonal movements are allowed (counts as 1.4 in 2D, 1.7 in 3D) :return: Distance to Target @@ -168,6 +168,18 @@ class Coordinate: else: return self.x <= other.x and self.y <= other.y and self.z <= other.z + def __str__(self): + if self.z is None: + return "(%d,%d)" % (self.x, self.y) + else: + return "(%d,%d,%d)" % (self.x, self.y, self.z) + + def __repr__(self): + if self.z is None: + return "%s(x=%d, y=%d)" % (self.__class__.__name__, self.x, self.y) + else: + return "%s(x=%d, y=%d, z=%d)" % (self.__class__.__name__, self.x, self.y, self.z) + @staticmethod def generate(from_x: int, to_x: int, from_y: int, to_y: int, from_z: int = None, to_z: int = None) -> List[Coordinate]: @@ -247,6 +259,9 @@ class Shape: return self.intersection(other) def __str__(self): + return "%s(%s -> %s)" % (self.__class__.__name__, self.top_left, self.bottom_right) + + def __repr__(self): return "%s(%s, %s)" % (self.__class__.__name__, self.top_left, self.bottom_right)