base.py 781 B

1234567891011121314151617181920212223242526
  1. class PointError(Exception):
  2. pass
  3. class Point:
  4. def __init__(self, x: int, y: int) -> None:
  5. if not isinstance(x, int) or not isinstance(y, int):
  6. raise PointError("x,y should be an integer type")
  7. self.x = x
  8. self.y = y
  9. def __add__(self, other: "Point") -> "Point":
  10. return Point(self.x + other.x, self.y + other.y)
  11. def __sub__(self, other: "Point") -> "Point":
  12. return Point(self.x - other.x, self.y - other.y)
  13. def __eq__(self, other: object) -> bool:
  14. if not isinstance(other, Point):
  15. raise NotImplementedError
  16. return self.x == other.x and self.y == other.y
  17. def distance_to(self, other: "Point") -> float:
  18. p = self - other
  19. return (p.x ** 2 + p.y ** 2) ** 0.5