nicer reprs

This commit is contained in:
Stefan Harmuth 2022-01-14 12:39:14 +01:00
parent 1e1f5ef126
commit a1eb51eb80

View File

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