# -*- coding: utf-8 -*- from collections import namedtuple class Coordinate(namedtuple("Coordinate", ["x", "y"])): def __sub__(self, other: "Coordinate"): return Coordinate(self.x - other.x, self.y - other.y) def __add__(self, other: "Coordinate"): return Coordinate(self.x + other.x, self.y + other.y) def manhattan_distance(self, other: "Coordinate"): return abs(self.x - other.x) + abs(self.y - other.y) @property def polarity_x(self): try: return abs(self.x) / self.x except ZeroDivisionError: return 0 @property def polarity_y(self): try: return abs(self.y) / self.y except ZeroDivisionError: return 0