From dd3343f4b74729cb4cdb9eb920b7c624ec8ff0de Mon Sep 17 00:00:00 2001 From: Ana Ferreira Date: Thu, 12 Sep 2024 12:12:22 -0300 Subject: [PATCH] feat: Create a function to calculate the distance to Manhattan (#212) --- cereja/geolinear/point.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cereja/geolinear/point.py b/cereja/geolinear/point.py index d4a15bd..c8bbcd4 100644 --- a/cereja/geolinear/point.py +++ b/cereja/geolinear/point.py @@ -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):