From 75d1dba7ee5f3d35bb5571fe66c3f1b5be36f850 Mon Sep 17 00:00:00 2001 From: Tom Kramkowski Date: Thu, 15 Dec 2022 19:05:25 +0000 Subject: utils: docstrings --- utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index 6a8f423..5bb7ea4 100644 --- a/utils.py +++ b/utils.py @@ -11,8 +11,9 @@ from typing import TypeVar, Generic, Union, Optional, cast NumT = TypeVar('NumT', float, int) -@dataclass(frozen=True, slots=True) +@dataclass(frozen=True) class Point2D(Generic[NumT]): + __slots__ = 'x', 'y' x: NumT y: NumT @@ -33,15 +34,19 @@ class Point2D(Generic[NumT]): return Point2D(cast(NumT, abs(self.x)), cast(NumT, abs(self.y))) def norm_1(p: Point2D[NumT]) -> NumT: + "Calculate the Manhattan norm (distance) from (0, 0) to p" return cast(NumT, abs(p.x) + abs(p.y)) def norm_2(p: Point2D) -> float: + "Calculate the Euclidean norm (distance) from (0, 0) to p" return sqrt(p.x ** 2 + p.y ** 2) def norm_inf(p: Point2D[NumT]) -> NumT: + "Calculate the Maximum norm (absolute value of the axis furthest away from (0, 0)) of p" return cast(NumT, max(abs(p.x), abs(p.y))) def inbounds(p: Point2D[NumT], a: Point2D[NumT], _b: Optional[Point2D[NumT]] = None) -> bool: + "Check if p is in the bounding box with corners a, b" b: Point2D[NumT] if isinstance(_b, Point2D): b = _b -- cgit v1.2.3-54-g00ecf