diff options
author | Tom Kramkowski <tomasz@kramkow.ski> | 2022-12-15 19:05:25 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-15 19:07:16 +0000 |
commit | 75d1dba7ee5f3d35bb5571fe66c3f1b5be36f850 (patch) | |
tree | e85aeeb9155d3fcd12438acfe5458e2aa08b665a | |
parent | 4246099f07ce2c5ccf2503a2c45ce24e55f96445 (diff) | |
download | aoc2022-75d1dba7ee5f3d35bb5571fe66c3f1b5be36f850.tar.gz aoc2022-75d1dba7ee5f3d35bb5571fe66c3f1b5be36f850.tar.xz aoc2022-75d1dba7ee5f3d35bb5571fe66c3f1b5be36f850.zip |
utils: docstrings
-rw-r--r-- | utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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 |