# | Line 35 | Line 35 | |
---|---|---|
35 | ||
36 | #include <cassert> | |
37 | #include <cmath> | |
38 | + | #include <iostream> |
39 | ||
40 | namespace oopse { | |
41 | ||
# | Line 42 | Line 43 | namespace oopse { | |
43 | * @class Vector Vector.hpp "math/Vector.hpp" | |
44 | * @brief Fix length vector class | |
45 | */ | |
46 | < | template<typename Real, int Dim> |
46 | > | template<typename Real, unsigned int Dim> |
47 | class Vector{ | |
48 | public: | |
49 | ||
# | Line 209 | Line 210 | namespace oopse { | |
210 | } | |
211 | ||
212 | /** @see #add */ | |
213 | < | inline Vector<Real, Dim> operator +=( const Vector<Real, Dim>& v1 ) { |
213 | > | inline Vector<Real, Dim>& operator +=( const Vector<Real, Dim>& v1 ) { |
214 | add(v1); | |
215 | return *this; | |
216 | } | |
217 | ||
218 | /** @see #sub */ | |
219 | < | inline Vector<Real, Dim> operator -=( const Vector<Real, Dim>& v1 ) { |
219 | > | inline Vector<Real, Dim>& operator -=( const Vector<Real, Dim>& v1 ) { |
220 | sub(v1); | |
221 | return *this; | |
222 | } | |
223 | ||
224 | /** @see #mul */ | |
225 | < | inline Vector<Real, Dim> operator *=( double s) { |
225 | > | inline Vector<Real, Dim>& operator *=( double s) { |
226 | mul(s); | |
227 | return *this; | |
228 | } | |
229 | ||
230 | /** @see #div */ | |
231 | < | inline Vector<Real, Dim> operator /=( double s ) { |
231 | > | inline Vector<Real, Dim>& operator /=( double s ) { |
232 | div(s); | |
233 | return *this; | |
234 | } | |
# | Line 262 | Line 263 | namespace oopse { | |
263 | }; | |
264 | ||
265 | /** unary minus*/ | |
266 | < | template<typename Real, int Dim> |
266 | > | template<typename Real, unsigned int Dim> |
267 | inline Vector<Real, Dim> operator -(const Vector<Real, Dim>& v1){ | |
268 | Vector tmp(v1); | |
269 | return tmp.negate(); | |
# | Line 274 | Line 275 | namespace oopse { | |
275 | * @param v1 the first vector | |
276 | * @param v2 the second vector | |
277 | */ | |
278 | < | template<typename Real, int Dim> |
278 | > | template<typename Real, unsigned int Dim> |
279 | inline Vector<Real, Dim> operator +(const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { | |
280 | Vector<Real, Dim> result; | |
281 | ||
# | Line 288 | Line 289 | namespace oopse { | |
289 | * @param v1 the first vector | |
290 | * @param v2 the second vector | |
291 | */ | |
292 | < | template<typename Real, int Dim> |
292 | > | template<typename Real, unsigned int Dim> |
293 | Vector<Real, Dim> operator -(const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2) { | |
294 | Vector<Real, Dim> result; | |
295 | result.sub(v1, v2); | |
# | Line 301 | Line 302 | namespace oopse { | |
302 | * @param v1 the source vector | |
303 | * @param s the scalar value | |
304 | */ | |
305 | < | template<typename Real, int Dim> |
305 | > | template<typename Real, unsigned int Dim> |
306 | Vector<Real, Dim> operator * ( const Vector<Real, Dim>& v1, double s) { | |
307 | Vector<Real, Dim> result; | |
308 | result.mul(s, v1); | |
# | Line 314 | Line 315 | namespace oopse { | |
315 | * @param s the scalar value | |
316 | * @param v1 the source vector | |
317 | */ | |
318 | < | template<typename Real, int Dim> |
318 | > | template<typename Real, unsigned int Dim> |
319 | Vector<Real, Dim> operator * ( double s, const Vector<Real, Dim>& v1 ) { | |
320 | Vector<Real, Dim> result; | |
321 | result.mul(s, v1); | |
# | Line 327 | Line 328 | namespace oopse { | |
328 | * @param v1 the source vector | |
329 | * @param s the scalar value | |
330 | */ | |
331 | < | template<typename Real, int Dim> |
331 | > | template<typename Real, unsigned int Dim> |
332 | Vector<Real, Dim> operator / ( const Vector<Real, Dim>& v1, double s) { | |
333 | Vector<Real, Dim> result; | |
334 | result.div( v1,s); | |
# | Line 340 | Line 341 | namespace oopse { | |
341 | * @param s the scalar value | |
342 | * @param v1 the source vector | |
343 | */ | |
344 | < | template<typename Real, int Dim> |
344 | > | template<typename Real, unsigned int Dim> |
345 | inline Vector<Real, Dim> operator /( double s, const Vector<Real, Dim>& v1 ) { | |
346 | Vector<Real, Dim> result; | |
347 | result.div( v1,s); | |
# | Line 348 | Line 349 | namespace oopse { | |
349 | } | |
350 | ||
351 | /** fuzzy comparson */ | |
352 | < | template<typename Real, int Dim> |
352 | > | template<typename Real, unsigned int Dim> |
353 | inline bool epsilonEqual( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) { | |
354 | ||
355 | } | |
# | Line 360 | Line 361 | namespace oopse { | |
361 | * @param v2 second vector | |
362 | * @return the dot product of v1 and v2 | |
363 | */ | |
364 | < | template<typename Real, int Dim> |
364 | > | template<typename Real, unsigned int Dim> |
365 | inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) { | |
366 | Real tmp; | |
367 | tmp = 0; | |
# | Line 377 | Line 378 | namespace oopse { | |
378 | * @param v2 second vector | |
379 | * @return the distance between v1 and v2 | |
380 | */ | |
381 | < | template<typename Real, int Dim> |
381 | > | template<typename Real, unsigned int Dim> |
382 | inline Real distance( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) { | |
383 | Vector<Real, Dim> tempVector = v1 - v2; | |
384 | return tempVector.length(); | |
# | Line 389 | Line 390 | namespace oopse { | |
390 | * @param v2 second vector | |
391 | * @return the squared distance between v1 and v2 | |
392 | */ | |
393 | < | template<typename Real, int Dim> |
393 | > | template<typename Real, unsigned int Dim> |
394 | inline Real distanceSquare( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) { | |
395 | Vector<Real, Dim> tempVector = v1 - v2; | |
396 | return tempVector.lengthSquare(); | |
# | Line 398 | Line 399 | namespace oopse { | |
399 | /** | |
400 | * Write to an output stream | |
401 | */ | |
402 | < | template<typename Real, int Dim> |
402 | > | template<typename Real, unsigned int Dim> |
403 | std::ostream &operator<< ( std::ostream& o, const Vector<Real, Dim>& v1 ) { | |
404 | ||
405 | return o; |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |