-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVector.py
More file actions
68 lines (54 loc) · 1.47 KB
/
Copy pathVector.py
File metadata and controls
68 lines (54 loc) · 1.47 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
'''
Created on Mar 15, 2013
@author: easyrider
Non object oriented version
'''
class Vector(object):
'''
classdocs
'''
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __repr__(self):
return repr((self.x, self.y, self.z))
# overload []
def __getitem__(self, index):
'''data = [self.x,self.y,self.z]'''
return (self.x, self.y, self.z)[index]
# overload set []
def __setitem__(self, key, item):
if (key == 0):
self.x = item
elif (key == 1):
self.y = item
elif (key == 2):
self.z = item
else:
raise Exception("Index doesnt exist!")
def __add__(self, other):
self.x+=other.x
self.y+=other.y
self.z+=other.z
return Vector(self.x, self.y, self.z)
def __div__(self, other):
if (isinstance(other, int)):
self.x/=other
self.y/=other
self.z/=other
else:
self.x/=other.x
self.y/=other.y
self.z/=other.z
return Vector(self.x, self.y, self.z)
def __mul__(self, other):
if (isinstance(other, float)):
self.x*=other
self.y*=other
self.z*=other
else:
self.x*=other.x
self.y*=other.y
self.z*=other.z
return Vector(self.x, self.y, self.z)