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

Comparing trunk/OOPSE-3.0/src/math/Vector.hpp (file contents):
Revision 1569 by tim, Thu Oct 14 23:28:09 2004 UTC vs.
Revision 1586 by tim, Sun Oct 17 01:19:11 2004 UTC

# Line 88 | Line 88 | namespace oopse {
88              
89              /** Constructs and initializes a Vector from an array */            
90              inline Vector( double* v) {
91 <                for (unsigned int i = 0; i < Dim; i++)
92 <                    data_[i] = v[i];
91 >                for (unsigned int i = 0; i < Dim; i++)
92 >                    data_[i] = v[i];
93              }
94  
95              /**
# Line 179 | Line 179 | namespace oopse {
179              * @param v1 the other vector
180              */
181              inline void add( const Vector<Real, Dim>& v1 ) {
182 <                for (unsigned int i = 0; i < Dim; i++)
183 <                    data_[i] += v1.data_[i];
182 >            for (unsigned int i = 0; i < Dim; i++)
183 >                data_[i] += v1.data_[i];
184                  }
185  
186              /**
# Line 189 | Line 189 | namespace oopse {
189              * @param v2 the second vector
190              */
191              inline void add( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) {
192 <                for (unsigned int i = 0; i < Dim; i++)
193 <                    data_[i] = v1.data_[i] + v2.data_[i];
192 >                for (unsigned int i = 0; i < Dim; i++)
193 >                    data_[i] = v1.data_[i] + v2.data_[i];
194              }
195  
196              /**
# Line 217 | Line 217 | namespace oopse {
217              * @param s the scalar value
218              */
219              inline void mul( double s ) {
220 <                for (unsigned int i = 0; i < Dim; i++)
220 >                for (unsigned int i = 0; i < Dim; i++)
221                     data_[i] *= s;
222              }
223  
# Line 228 | Line 228 | namespace oopse {
228              * @param v1 the vector
229              */
230              inline void mul( double s, const Vector<Real, Dim>& v1 ) {
231 <                for (unsigned int i = 0; i < Dim; i++)
231 >                for (unsigned int i = 0; i < Dim; i++)
232                      data_[i] = s * v1.data_[i];
233              }
234  
# Line 237 | Line 237 | namespace oopse {
237              * @param s the scalar value
238              */            
239              inline void div( double s) {
240 <                for (unsigned int i = 0; i < Dim; i++)            
240 >                for (unsigned int i = 0; i < Dim; i++)            
241                      data_[i] /= s;
242              }
243  
# Line 247 | Line 247 | namespace oopse {
247              * @param s the scalar value
248              */                        
249              inline void div( const Vector<Real, Dim>& v1, double s ) {
250 <                for (unsigned int i = 0; i < Dim; i++)
250 >                for (unsigned int i = 0; i < Dim; i++)
251                      data_[i] = v1.data_[i] / s;
252              }
253  
# Line 287 | Line 287 | namespace oopse {
287               * Returns the squared length of this vector.
288               * @return the squared length of this vector
289               */
290 <             inline double lengthSquared() {
290 >             inline double lengthSquare() {
291                  return dot(*this, *this);
292              }
293              
# Line 298 | Line 298 | namespace oopse {
298                  len = length();
299                  *this /= len;
300              }
301 +
302 +            /**
303 +             * Tests if this vector is normalized
304 +             * @return true if this vector is normalized, otherwise return false
305 +             */
306 +            inline bool isNormalized() const
307 +            {
308 +                return lengthSquare() == 1.0;
309 +            }          
310              
311          protected:
312              double data_[3];
# Line 405 | Line 414 | namespace oopse {
414       */
415      template<typename Real, unsigned int Dim>    
416      inline Real dot( const Vector<Real, Dim>& v1, const Vector<Real, Dim>& v2 ) {
417 <                Real tmp;
418 <                tmp = 0;
417 >        Real tmp;
418 >        tmp = 0;
419  
420 <                for (unsigned int i = 0; i < Dim; i++)
421 <                        tmp += v1[i] + v2[i];
422 <                
423 <                return tmp;
420 >        for (unsigned int i = 0; i < Dim; i++)
421 >            tmp += v1[i] + v2[i];
422 >
423 >        return tmp;
424      }
425  
426      /**
# Line 442 | Line 451 | namespace oopse {
451       * Write to an output stream
452       */
453      template<typename Real, unsigned int Dim>
454 <    std::ostream &operator<< ( std::ostream& o, const Vector<Real, Dim>& v1 ) {
455 <        
454 >    std::ostream &operator<< ( std::ostream& o, const Vector<Real, Dim>& v) {
455 >
456 >        o << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]" << endl;
457          return o;        
458      }
459      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines