--- trunk/src/math/Vector.hpp 2006/02/10 15:12:14 886 +++ trunk/src/math/Vector.hpp 2009/05/20 19:35:05 1349 @@ -53,22 +53,23 @@ #include #include #include +#include "config.h" namespace oopse { - static const double epsilon = 0.000001; + static const RealType epsilon = 0.000001; template inline bool equal(T e1, T e2) { return e1 == e2; } - template<> - inline bool equal(float e1, float e2) { - return fabs(e1 - e2) < epsilon; - } + //template<> + //inline bool equal(float e1, float e2) { + // return fabs(e1 - e2) < epsilon; + //} template<> - inline bool equal(double e1, double e2) { + inline bool equal(RealType e1, RealType e2) { return fabs(e1 - e2) < epsilon; } @@ -313,6 +314,18 @@ namespace oopse { } /** + * Returns the sum of all elements of this vector. + * @return the sum of all elements of this vector + */ + inline Real sum() { + Real tmp; + tmp = 0; + for (unsigned int i = 0; i < Dim; i++) + tmp += this->data_[i]; + return tmp; + } + + /** * Returns the length of this vector. * @return the length of this vector */ @@ -345,7 +358,7 @@ namespace oopse { * @return true if this vector is normalized, otherwise return false */ inline bool isNormalized() { - return equal(lengthSquare(), 1.0); + return equal(lengthSquare(), (RealType)1); } unsigned int size() {return Dim;}