From 1df1bf566097f62e1ff88bb30c7816da673a079f Mon Sep 17 00:00:00 2001 From: AnaFerreira015 Date: Wed, 11 Sep 2024 20:35:14 -0300 Subject: [PATCH] feat: Create a function to calculate the distance to Manhattan --- 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):