| 85 |  |  | 
| 86 |  | return *this; | 
| 87 |  | } | 
| 88 | + |  | 
| 89 | + | template<typename T> | 
| 90 | + | inline Vector(const T& s){ | 
| 91 | + | for (unsigned int i = 0; i < Dim; i++) | 
| 92 | + | data_[i] = s; | 
| 93 | + | } | 
| 94 |  |  | 
| 95 |  | /** Constructs and initializes a Vector from an array */ | 
| 96 |  | inline Vector( double* v) { | 
| 165 |  |  | 
| 166 |  | /** Negates the value of this vector in place. */ | 
| 167 |  | inline void negate() { | 
| 168 | < | data_[0] = -data_[0]; | 
| 169 | < | data_[1] = -data_[1]; | 
| 164 | < | data_[2] = -data_[2]; | 
| 168 | > | for (unsigned int i = 0; i < Dim; i++) | 
| 169 | > | data_[i] = -data_[i]; | 
| 170 |  | } | 
| 171 |  |  | 
| 172 |  | /** | 
| 229 |  | /** | 
| 230 |  | * Sets the value of this vector to the scalar multiplication of vector v1 | 
| 231 |  | * (*this = s * v1). | 
| 232 | + | * @param v1 the vector | 
| 233 |  | * @param s the scalar value | 
| 228 | – | * @param v1 the vector | 
| 234 |  | */ | 
| 235 | < | inline void mul( double s, const Vector<Real, Dim>& v1 ) { | 
| 235 | > | inline void mul( const Vector<Real, Dim>& v1, double s) { | 
| 236 |  | for (unsigned int i = 0; i < Dim; i++) | 
| 237 |  | data_[i] = s * v1.data_[i]; | 
| 238 |  | } | 
| 285 |  | * @return the length of this vector | 
| 286 |  | */ | 
| 287 |  | inline double length() { | 
| 288 | < | return sqrt(lengthSquared()); | 
| 288 | > | return sqrt(lengthSquare()); | 
| 289 |  | } | 
| 290 |  |  | 
| 291 |  | /** | 
| 301 |  | double len; | 
| 302 |  |  | 
| 303 |  | len = length(); | 
| 304 | + |  | 
| 305 | + | //if (len < oopse:epsilon) | 
| 306 | + | //  throw(); | 
| 307 | + |  | 
| 308 |  | *this /= len; | 
| 309 |  | } | 
| 310 |  |  | 
| 312 |  | * Tests if this vector is normalized | 
| 313 |  | * @return true if this vector is normalized, otherwise return false | 
| 314 |  | */ | 
| 315 | < | inline bool isNormalized() const | 
| 316 | < | { | 
| 308 | < | return lengthSquare() == 1.0; | 
| 315 | > | inline bool isNormalized() { | 
| 316 | > | return equal(lengthSquare(), 1.0); | 
| 317 |  | } | 
| 318 |  |  | 
| 319 |  | protected: | 
| 320 | < | double data_[3]; | 
| 320 | > | double data_[Dim]; | 
| 321 |  |  | 
| 322 |  | }; | 
| 323 |  |  | 
| 324 |  | /** unary minus*/ | 
| 325 |  | template<typename Real, unsigned int Dim> | 
| 326 |  | inline Vector<Real, Dim> operator -(const Vector<Real, Dim>& v1){ | 
| 327 | < | Vector tmp(v1); | 
| 328 | < | return tmp.negate(); | 
| 327 | > | Vector<Real, Dim> tmp(v1); | 
| 328 | > | tmp.negate(); | 
| 329 | > | return tmp; | 
| 330 |  | } | 
| 331 |  |  | 
| 332 |  | /** | 
| 365 |  | template<typename Real, unsigned int Dim> | 
| 366 |  | Vector<Real, Dim> operator * ( const Vector<Real, Dim>& v1, double s) { | 
| 367 |  | Vector<Real, Dim> result; | 
| 368 | < | result.mul(s, v1); | 
| 368 | > | result.mul(v1,s); | 
| 369 |  | return result; | 
| 370 |  | } | 
| 371 |  |  | 
| 378 |  | template<typename Real, unsigned int Dim> | 
| 379 |  | Vector<Real, Dim> operator * ( double s, const Vector<Real, Dim>& v1 ) { | 
| 380 |  | Vector<Real, Dim> result; | 
| 381 | < | result.mul(s, v1); | 
| 381 | > | result.mul(v1, s); | 
| 382 |  | return result; | 
| 383 |  | } | 
| 384 |  |  | 
| 396 |  | } | 
| 397 |  |  | 
| 398 |  | /** | 
| 390 | – | * Returns the  value of division of a vector by a scalar. | 
| 391 | – | * @return  the vaule of scalar division of this vector | 
| 392 | – | * @param s the scalar value | 
| 393 | – | * @param v1 the source vector | 
| 394 | – | */ | 
| 395 | – | template<typename Real, unsigned int Dim> | 
| 396 | – | inline Vector<Real, Dim> operator /( double s, const Vector<Real, Dim>& v1 ) { | 
| 397 | – | Vector<Real, Dim> result; | 
| 398 | – | result.div( v1,s); | 
| 399 | – | return result; | 
| 400 | – | } | 
| 401 | – |  | 
| 402 | – | /** fuzzy comparson */ | 
| 403 | – | template<typename Real, unsigned int Dim> | 
| 404 | – | inline bool epsilonEqual( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) { | 
| 405 | – |  | 
| 406 | – | } | 
| 407 | – |  | 
| 408 | – |  | 
| 409 | – | /** | 
| 399 |  | * Returns the dot product of two Vectors | 
| 400 |  | * @param v1 first vector | 
| 401 |  | * @param v2 second vector |