summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils.py7
1 files changed, 6 insertions, 1 deletions
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