1 """Imago geometry module"""
3 from manual import line, intersection
6 def __init__(self, x, y):
10 def __add__(self, other):
11 return V(self.x + other.x, self.y + other.y)
13 def __sub__(self, other):
14 return V(self.x - other.x, self.y - other.y)
16 def __rmul__(self, other):
17 return V(other * self.x, other * self.y)
22 def __getitem__(self, key):
27 elif type(key) != int:
28 raise TypeError("V indices must be integers")
30 raise KeyError("V index ({}) out of range".format(key))
38 return V(-self.y, self.x)
40 def projection(p, l, v):
41 return V(*intersection(line(p, p + v.normal), line(*l)))