From 06d34a527b608c1fd35d20038ee2038ab07b08a0 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 18 Feb 2023 22:51:42 -0800 Subject: [PATCH] Add Point.manhattan_distance_to Returns the manhattan distance to another Point. --- erynrl/geometry.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erynrl/geometry.py b/erynrl/geometry.py index cbc156e..aab95b8 100644 --- a/erynrl/geometry.py +++ b/erynrl/geometry.py @@ -48,6 +48,10 @@ class Point: '''Compute the Euclidean distance to another Point''' return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2) + def manhattan_distance_to(self, other: 'Point') -> int: + '''Compute the Manhattan distance to another Point''' + return abs(self.x - other.x) + abs(self.y - other.y) + def __add__(self, other: 'Vector') -> 'Point': if not isinstance(other, Vector): raise TypeError('Only Vector can be added to a Point')