-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoord.py
72 lines (47 loc) · 1.65 KB
/
coord.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class AbstractCoord:
def __init__(self, y: int, x: int) -> None:
self.y = y
self.x = x
self.value: tuple[int, int] = (y, x)
def __str__(self) -> tuple:
return self.value
def __hash__(self):
return hash(self.value)
def __eq__(self, other: "AbstractCoord") -> bool:
if issubclass(type(other), AbstractCoord):
return self.value == other.value
else: return False
def __iter__(self):
return iter(self.value)
class Coord(AbstractCoord):
def __init__(self, y: int, x: int) -> None:
super().__init__(y, x)
def __sub__(self, other):
if not issubclass(type(other), AbstractCoord):
return NotImplemented
return Coord(self.y - other.y, self.x - other.x)
def __add__(self, other: "Coord"):
if not issubclass(type(other), AbstractCoord):
return NotImplemented
return Coord(self.y + other.y, self.x + other.x)
def move(self, mov: tuple[int, int]) -> "Coord":
return Coord(self.y + mov[0], self.x + mov[1])
def indexMax(self):
y, x = self.value
result: int = None
if y > x:
result = 0
elif y < x:
result = 1
return result
#Funciones Abs
def absData(self):
return (abs(self.y), abs(self.x))
def GetAbsoluteCoord(self):
absY, absX = self.absData()
return Coord(absY, absX)
def Absolute(self):
absY, absX = self.absData()
self.value = (absY, absX)
def copy(self):
return Coord(self.y, self.x)