27
27
28
28
class Vector (object ):
29
29
"""
30
- This class represents a vector of arbitray size.
30
+ This class represents a vector of arbitrary size.
31
31
You need to give the vector components.
32
32
33
33
Overview about the methods:
@@ -46,11 +46,13 @@ class Vector(object):
46
46
TODO: compare-operator
47
47
"""
48
48
49
- def __init__ (self , components = [] ):
49
+ def __init__ (self , components = None ):
50
50
"""
51
51
input: components or nothing
52
52
simple constructor for init the vector
53
53
"""
54
+ if components is None :
55
+ components = []
54
56
self .__components = list (components )
55
57
56
58
def set (self , components ):
@@ -112,7 +114,7 @@ def __sub__(self, other):
112
114
"""
113
115
input: other vector
114
116
assumes: other vector has the same size
115
- returns a new vector that represents the differenz .
117
+ returns a new vector that represents the difference .
116
118
"""
117
119
size = len (self )
118
120
if size == len (other ):
@@ -136,7 +138,7 @@ def __mul__(self, other):
136
138
summe += self .__components [i ] * other .component (i )
137
139
return summe
138
140
else : # error case
139
- raise Exception ("invalide operand!" )
141
+ raise Exception ("invalid operand!" )
140
142
141
143
def copy (self ):
142
144
"""
@@ -223,7 +225,7 @@ class Matrix(object):
223
225
224
226
def __init__ (self , matrix , w , h ):
225
227
"""
226
- simple constructor for initialzes
228
+ simple constructor for initializing
227
229
the matrix with components.
228
230
"""
229
231
self .__matrix = matrix
@@ -249,7 +251,7 @@ def changeComponent(self, x, y, value):
249
251
"""
250
252
changes the x-y component of this matrix
251
253
"""
252
- if x >= 0 and x < self .__height and y >= 0 and y < self .__width :
254
+ if 0 <= x < self .__height and 0 <= y < self .__width :
253
255
self .__matrix [x ][y ] = value
254
256
else :
255
257
raise Exception ("changeComponent: indices out of bounds" )
@@ -258,7 +260,7 @@ def component(self, x, y):
258
260
"""
259
261
returns the specified (x,y) component
260
262
"""
261
- if x >= 0 and x < self .__height and y >= 0 and y < self .__width :
263
+ if 0 <= x < self .__height and 0 <= y < self .__width :
262
264
return self .__matrix [x ][y ]
263
265
else :
264
266
raise Exception ("changeComponent: indices out of bounds" )
0 commit comments