-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.py
47 lines (32 loc) · 1.03 KB
/
point.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
from enum import Enum
class Point:
def __init__(self, x: int, y: int):
self._x = x
self._y = y
@property
def x(self) -> int:
return self._x
@property
def y(self) -> int:
return self._y
def __add__(self, other_point: 'Point') -> 'Point':
return Point(self.x + other_point.x, self.y + other_point.y)
def __mul__(self, coefficient: int):
return Point(self.x * coefficient, self.y * coefficient)
def __rmul__(self, coefficient: int):
return self * coefficient
def __eq__(self, o: object) -> bool:
return type(o) is Point and self.x == o.x and self.y == o.y
def __hash__(self) -> int:
return hash(self.x)*31 + hash(self.y)
def __str__(self):
return "(" + str(self._x) + ", " + str(self._y) + ")"
def __sub__(self, other):
return self + (other * (-1))
class Direction(Enum):
Up = Point(0, 1)
Down = Point(0, -1)
Left = Point(-1, 0)
Right = Point(1, 0)
Stand = Point(0, 0)