-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.py
62 lines (44 loc) · 1.54 KB
/
Position.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
class Position:
def __init__(self, coords):
self._coords = coords
# Below is an experimental way of accessing coordinate data.
self.i = coords[0]
self.j = coords[1]
self.k = coords[2]
def __getitem__(self, i):
return self._coords[i]
def __str__(self):
return str(self._coords)
def __add__(self, other):
return Position([self[i] + other[i] for i in range(3)])
def __iadd__(self, other):
return self + other
def __mul__(self, other):
"""
This only works for scalars right now.
"""
return Position([self[i] * other for i in range(3)])
def __rmul__(self, other):
return self * other
def __imul__(self, other):
return self * other
def __sub__(self, other):
return self + (-1 * other)
def __isub__(self, other):
return self - other
def __rsub__(self, other):
return self - other
def __neg__(self):
return self * -1
def __eq__(self, other):
return self._coords == other._coords
def __ne__(self, other):
return not self == other
def __gt__(self, other):
return self.magnitude() > other.magnitude()
def __lt__(self, other):
return self.magnitude() < other.magnitude()
def magnitude(self):
return sum([abs(axis) for axis in self._coords])
# Used to adjust a position
Unit = {"i": Position([1,0,0]), "j": Position([0,1,0]), "k": Position([0,0,1])}