| 53 |
|
#include <cmath> |
| 54 |
|
#include <iostream> |
| 55 |
|
#include <math.h> |
| 56 |
+ |
#include "config.h" |
| 57 |
|
namespace oopse { |
| 58 |
|
|
| 59 |
< |
static const double epsilon = 0.000001; |
| 59 |
> |
static const RealType epsilon = 0.000001; |
| 60 |
|
|
| 61 |
|
template<typename T> |
| 62 |
|
inline bool equal(T e1, T e2) { |
| 63 |
|
return e1 == e2; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
< |
template<> |
| 67 |
< |
inline bool equal(float e1, float e2) { |
| 68 |
< |
return fabs(e1 - e2) < epsilon; |
| 69 |
< |
} |
| 66 |
> |
//template<> |
| 67 |
> |
//inline bool equal(float e1, float e2) { |
| 68 |
> |
// return fabs(e1 - e2) < epsilon; |
| 69 |
> |
//} |
| 70 |
|
|
| 71 |
|
template<> |
| 72 |
< |
inline bool equal(double e1, double e2) { |
| 72 |
> |
inline bool equal(RealType e1, RealType e2) { |
| 73 |
|
return fabs(e1 - e2) < epsilon; |
| 74 |
|
} |
| 75 |
|
|
| 313 |
|
return *this; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
+ |
/** |
| 317 |
+ |
* Returns the sum of all elements of this vector. |
| 318 |
+ |
* @return the sum of all elements of this vector |
| 319 |
+ |
*/ |
| 320 |
+ |
inline Real sum() { |
| 321 |
+ |
Real tmp; |
| 322 |
+ |
tmp = 0; |
| 323 |
+ |
for (unsigned int i = 0; i < Dim; i++) |
| 324 |
+ |
tmp += this->data_[i]; |
| 325 |
+ |
return tmp; |
| 326 |
+ |
} |
| 327 |
+ |
|
| 328 |
|
/** |
| 329 |
|
* Returns the length of this vector. |
| 330 |
|
* @return the length of this vector |
| 358 |
|
* @return true if this vector is normalized, otherwise return false |
| 359 |
|
*/ |
| 360 |
|
inline bool isNormalized() { |
| 361 |
< |
return equal(lengthSquare(), 1.0); |
| 361 |
> |
return equal(lengthSquare(), (RealType)1); |
| 362 |
|
} |
| 363 |
< |
|
| 363 |
> |
|
| 364 |
> |
unsigned int size() {return Dim;} |
| 365 |
|
protected: |
| 366 |
|
Real data_[Dim]; |
| 367 |
|
|