Add Point.manhattan_distance_to
Returns the manhattan distance to another Point.
This commit is contained in:
parent
462eebd95c
commit
06d34a527b
1 changed files with 4 additions and 0 deletions
|
@ -48,6 +48,10 @@ class Point:
|
||||||
'''Compute the Euclidean distance to another Point'''
|
'''Compute the Euclidean distance to another Point'''
|
||||||
return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)
|
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':
|
def __add__(self, other: 'Vector') -> 'Point':
|
||||||
if not isinstance(other, Vector):
|
if not isinstance(other, Vector):
|
||||||
raise TypeError('Only Vector can be added to a Point')
|
raise TypeError('Only Vector can be added to a Point')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue