-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
98 lines (80 loc) · 2.33 KB
/
example.py
File metadata and controls
98 lines (80 loc) · 2.33 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from __future__ import annotations
from dataclasses import dataclass
from pyoverload.overloading import OverloadMeta, overload
@dataclass
class Coordinate(metaclass=OverloadMeta): # pragma: no cover
"""
An example, has both Coordiante and scalar overload methods.
Not particularly useful as you can just use a Coordiante with
equal x and y values instead of a scalar, but a good demonstration.
"""
x: int
y: int
@overload
def __floordiv__(self, other: Coordinate):
x = self.x // other.x
y = self.y // other.y
return Coordinate(x, y)
@overload
def __floordiv__(self, n: int):
x = self.x // n
y = self.y // n
return Coordinate(x, y)
@overload
def __mul__(self, other: Coordinate):
x = int(self.x * other.x)
y = int(self.y * other.y)
return Coordinate(x, y)
@overload
def __mul__(self, n: int):
x = int(self.x * n)
y = int(self.y * n)
return Coordinate(x, y)
@overload
def __add__(self, other: Coordinate):
x = self.x + other.x
y = self.y + other.y
return Coordinate(x, y)
@overload
def __add__(self, n: int):
x = self.x + n
y = self.y + n
return Coordinate(x, y)
@overload
def __sub__(self, other: Coordinate):
x = self.x - other.x
y = self.y - other.y
return Coordinate(x, y)
@overload
def __sub__(self, n: int):
x = self.x - n
y = self.y - n
return Coordinate(x, y)
@overload
def __mod__(self, other: Coordinate):
x = self.x % other.x
y = self.x % other.y
return Coordinate(x, y)
@overload
def __mod__(self, n: int):
x = self.x % n
y = self.x % n
return Coordinate(x, y)
@overload
def __mod__(self, complex: dict[str, list[tuple[int]]]):
x = self.x % complex["x"][0][0]
y = self.x % complex["y"][0][0]
return Coordinate(x, y)
if __name__ == "__main__": # pragma: no cover
c = Coordinate(10, 10)
print(c // 2)
print(c // Coordinate(2, 2))
print(c * 2)
print(c * Coordinate(2, 2))
print(c + 2)
print(c + Coordinate(2, 2))
print(c - 2)
print(c - Coordinate(2, 2))
print(c % 2)
print(c % Coordinate(2, 2))
print(c % {"x": [(1,)], "y": [(1,)]})