Skip to content

Commit

Permalink
feat: Create a function to calculate the distance to Manhattan (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaFerreira015 authored Sep 12, 2024
1 parent 16136eb commit dd3343f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cereja/geolinear/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ def rotate(self, angle: float, center=(0, 0, 0), axis: str = 'z') -> 'Point':
else:
raise ValueError(f"Invalid axis: {axis}. Axis should be 'x', 'y', or 'z'.")

def manhattan_distance_to(self, other: 'Point') -> float:
"""
Computes the Manhattan distance between this point and another point.
Args:
other (Point): The other point to which the Manhattan distance is calculated.
Returns:
float: The Manhattan distance between the two points.
"""
other = Point(other)
return abs(sum(self - other))

def __getitem__(self, item: Union[int, str]) -> Union[int, float]:
"""Allows indexing into the point to retrieve its coordinates."""
if isinstance(item, str):
Expand Down

0 comments on commit dd3343f

Please sign in to comment.