summaryrefslogtreecommitdiff
path: root/Vec.py
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 23:10:04 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 23:10:04 +0200
commitd1c404fe8eac3c743004a9a48a683e9361c8f7b3 (patch)
treef5df16492fd5cfc3a2915c678306b53c212edb5e /Vec.py
parentef6abc27cec35e32acef66c5077ffcc6bedde983 (diff)
downloadSnakePuzzle-d1c404fe8eac3c743004a9a48a683e9361c8f7b3.tar.gz
SnakePuzzle-d1c404fe8eac3c743004a9a48a683e9361c8f7b3.zip
fix: added typing
Diffstat (limited to 'Vec.py')
-rw-r--r--Vec.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/Vec.py b/Vec.py
index 31a67da..a6e0dcd 100644
--- a/Vec.py
+++ b/Vec.py
@@ -1,23 +1,27 @@
+from __future__ import annotations
+
class Vec2:
- def __init__(self, x, y):
+ def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
- def __add__(self, other):
+ def __add__(self, other: 'Vec2') -> 'Vec2':
return Vec2(self.x + other.x, self.y + other.y)
- def __eq__(self, other):
- return (other != None) and (self.x == other.x) and (self.y == other.y)
+ def __eq__(self, other: object) -> bool:
+ match other:
+ case Vec2(): return self.x == other.x and self.y == other.y
+ case _: return False
- def neg(self):
+ def neg(self) -> 'Vec2':
return Vec2(-self.x, -self.y)
- def toString(self):
+ def toString(self) -> str:
return f"({self.x}, {self.y})"
-right = Vec2(1, 0)
-up = Vec2(0, -1)
-left = Vec2(-1, 0)
-down = Vec2(0, 1)
+right: Vec2 = Vec2(1, 0)
+up: Vec2 = Vec2(0, -1)
+left: Vec2 = Vec2(-1, 0)
+down: Vec2 = Vec2(0, 1)