From 391f84b21b5346f7f7d525702c2b1b5e964bf058 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 9 Feb 2023 16:09:58 -0800 Subject: [PATCH] Fix up the type annotations for geometry.Direction --- erynrl/geometry.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/erynrl/geometry.py b/erynrl/geometry.py index 7990f78..37ad50c 100644 --- a/erynrl/geometry.py +++ b/erynrl/geometry.py @@ -6,6 +6,7 @@ import math from dataclasses import dataclass from typing import Any, Iterator, Optional, overload + @dataclass(frozen=True) class Point: '''A two-dimensional point, with coordinates in X and Y axes''' @@ -32,9 +33,9 @@ class Point: bool True if this point is adjacent to the other point ''' - return (self.x in (other.x - 1, other.x + 1)) and (self.y in (other.y -1, other.y + 1)) + 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['Direction']: + def direction_to_adjacent_point(self, other: 'Point') -> Optional['Vector']: for direction in Direction.all(): if (self + direction) != other: continue @@ -62,6 +63,7 @@ class Point: def __str__(self): return f'(x:{self.x}, y:{self.y})' + @dataclass(frozen=True) class Vector: '''A two-dimensional vector, representing change in position in X and Y axes''' @@ -76,8 +78,12 @@ class Vector: def __str__(self): return f'(δx:{self.dx}, δy:{self.dy})' + class Direction: - '''A collection of simple uint vectors in each of the eight major compass directions. This is a namespace, not a class.''' + ''' + A collection of simple uint vectors in each of the eight major compass + directions. This is a namespace, not a class. + ''' North = Vector(0, -1) NorthEast = Vector(1, -1) @@ -89,7 +95,7 @@ class Direction: NorthWest = Vector(-1, -1) @classmethod - def all(cls) -> Iterator['Direction']: + def all(cls) -> Iterator[Vector]: '''Iterate through all directions, starting with North and proceeding clockwise''' yield Direction.North yield Direction.NorthEast @@ -100,6 +106,7 @@ class Direction: yield Direction.West yield Direction.NorthWest + @dataclass(frozen=True) class Size: '''A two-dimensional size, representing size in X (width) and Y (height) axes''' @@ -114,6 +121,7 @@ class Size: def __str__(self): return f'(w:{self.width}, h:{self.height})' + @dataclass(frozen=True) class Rect: '''A two-dimensional rectangle, defined by an origin point and size'''