ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/math/Vector.hpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/math/Vector.hpp (file contents):
Revision 1586 by tim, Sun Oct 17 01:19:11 2004 UTC vs.
Revision 1594 by tim, Mon Oct 18 23:13:23 2004 UTC

# Line 85 | Line 85 | namespace oopse {
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) {
# Line 159 | Line 165 | namespace oopse {
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              /**
# Line 224 | Line 229 | namespace oopse {
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              }
# Line 309 | Line 314 | namespace oopse {
314              }          
315              
316          protected:
317 <            double data_[3];
317 >            double data_[Dim];
318          
319      };
320  
321      /** unary minus*/
322      template<typename Real, unsigned int Dim>    
323      inline Vector<Real, Dim> operator -(const Vector<Real, Dim>& v1){
324 <        Vector tmp(v1);
325 <        return tmp.negate();
324 >        Vector<Real, Dim> tmp(v1);
325 >        tmp.negate();
326 >        return tmp;
327      }
328  
329      /**
# Line 356 | Line 362 | namespace oopse {
362      template<typename Real, unsigned int Dim>                
363      Vector<Real, Dim> operator * ( const Vector<Real, Dim>& v1, double s) {      
364          Vector<Real, Dim> result;
365 <        result.mul(s, v1);
365 >        result.mul(v1,s);
366          return result;          
367      }
368      
# Line 369 | Line 375 | namespace oopse {
375      template<typename Real, unsigned int Dim>
376      Vector<Real, Dim> operator * ( double s, const Vector<Real, Dim>& v1 ) {
377          Vector<Real, Dim> result;
378 <        result.mul(s, v1);
378 >        result.mul(v1, s);
379          return result;          
380      }
381  
# Line 386 | Line 392 | namespace oopse {
392          return result;          
393      }
394      
389    /**
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
395      /** fuzzy comparson */
396      template<typename Real, unsigned int Dim>        
397      inline bool epsilonEqual( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines