From 36206b5cc0d73a1b31d7142e599c58e297e6d287 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 12 Feb 2023 19:44:28 -0800 Subject: [PATCH] Clean up __add__ on Point; add __sub__ The dunder add method only ever had one overload, so you don't need to declare an overload --- erynrl/geometry.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/erynrl/geometry.py b/erynrl/geometry.py index 611660c..424f3b6 100644 --- a/erynrl/geometry.py +++ b/erynrl/geometry.py @@ -4,7 +4,7 @@ import math from dataclasses import dataclass -from typing import Any, Iterator, Optional, overload, Tuple +from typing import Iterator, Optional, Tuple @dataclass(frozen=True) @@ -36,6 +36,7 @@ class Point: return (self.x in (other.x - 1, other.x + 1)) and (self.y in (other.y - 1, other.y + 1)) def direction_to_adjacent_point(self, other: 'Point') -> Optional['Vector']: + '''Given a point directly adjacent to `self`''' for direction in Direction.all(): if (self + direction) != other: continue @@ -47,15 +48,16 @@ class Point: '''Compute the Euclidean distance to another Point''' return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2) - @overload def __add__(self, other: 'Vector') -> 'Point': - ... - - def __add__(self, other: Any) -> 'Point': if not isinstance(other, Vector): raise TypeError('Only Vector can be added to a Point') return Point(self.x + other.dx, self.y + other.dy) + def __sub__(self, other: 'Vector') -> 'Point': + if not isinstance(other, Vector): + raise TypeError('Only Vector can be added to a Point') + return Point(self.x - other.dx, self.y - other.dy) + def __iter__(self): yield self.x yield self.y