-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector.py
36 lines (26 loc) · 795 Bytes
/
Vector.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
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def __mul__(self, n):
return Vector(self.x * n, self.y * n)
def __add__(self, vector):
return Vector(self.x + vector.x, self.y + vector.y)
def __sub__(self, vector):
return self + (vector * -1)
def __abs__(self):
return Vector(abs(self.x), abs(self.y))
def rotateClockwise(self):
return Vector(self.y * -1, self.x)
def rotateCounterClockwise(self):
return Vector(self.y, self.x * -1)
def unitize(self):
if self.x == 0:
x = 0
else:
x = int(self.x / abs(self.x))
if self.y == 0:
y = 0
else:
y = int(self.y / abs(self.y))
return Vector(x, y)