TinyVector< N, T > Class Template Reference

specialization for three component vectors More...

#include <TinyVector.hpp>

Inheritance diagram for TinyVector< N, T >:

Inheritance graph
[legend]
Collaboration diagram for TinyVector< N, T >:

Collaboration graph
[legend]

List of all members.

Public Types

enum  { Dimension = N }
typedef T ValueType
 The type of values stored in the TinyVector.

Public Member Functions

size_t size () const
T & operator[] (const size_t &i)
const T & operator[] (const size_t &i) const
const TinyVector< N, T > & operator= (const TinyVector< N, T > &V)
const TinyVector< N, T > & operator= (const T &t)
TinyVector< N, T > operator* (const T &t) const
real_t operator* (const TinyVector< N, T > &V) const
const TinyVector< N, T > & operator*= (const T &t)
const TinyVector< N, T > & operator/= (const T &t)
TinyVector< N, T > operator- (const TinyVector< N, T > &V) const
const TinyVector< N, T > & operator-= (const TinyVector< N, T > &V)
TinyVector< N, T > operator^ (const TinyVector< N, T > &V) const
TinyVector< N, T > operator+ (const TinyVector< N, T > &V) const
TinyVector< N, T > & operator+= (const TinyVector< N, T > &V)
bool operator== (const TinyVector< N, T > &V) const
bool operator!= (const TinyVector< N, T > &V) const
bool operator< (const TinyVector< N, T > &V) const
 TinyVector ()
 TinyVector (const T &t)
 TinyVector (const TinyVector< N, T > &V)
 ~TinyVector ()

Protected Attributes

__x [N]
 stored data

Friends

TinyVector< N, T > sqrt (const TinyVector< N, T > &V)
Norm (const TinyVector< N, T > &V)
TinyVector< N, T > operator* (const T &a, const TinyVector< N, T > &V)
std::ostream & operator<< (std::ostream &os, const TinyVector< N, T > &V)


Detailed Description

template<size_t N, typename T = real_t>
class TinyVector< N, T >

specialization for three component vectors

special vector of size 1 (ie lonely values)

Author:
Stéphane Del Pino
Date:
Wed Aug 6 18:52:20 2003
Author:
Stéphane Del Pino
Date:
Wed Aug 6 21:41:47 2003

Definition at line 42 of file TinyVector.hpp.


Member Typedef Documentation

template<size_t N, typename T = real_t>
typedef T TinyVector< N, T >::ValueType

The type of values stored in the TinyVector.

Definition at line 46 of file TinyVector.hpp.


Member Enumeration Documentation

template<size_t N, typename T = real_t>
anonymous enum

Enumerator:
Dimension  The dimension of the vector

Definition at line 48 of file TinyVector.hpp.

00048        {
00049     Dimension = N               
00050   };


Constructor & Destructor Documentation

template<size_t N, typename T = real_t>
TinyVector< N, T >::TinyVector (  )  [inline]

Default constructor.

Note:
data are not initialized

Definition at line 381 of file TinyVector.hpp.

00382   {
00383     ;
00384   }

template<size_t N, typename T = real_t>
TinyVector< N, T >::TinyVector ( const T &  t  )  [inline]

Construct the vector setting its coordinates to t.

Parameters:
t the given value

Definition at line 391 of file TinyVector.hpp.

00392   {
00393     for (size_t i=0; i<N; i++) {
00394       __x[i] = t;
00395     }
00396   }

template<size_t N, typename T = real_t>
TinyVector< N, T >::TinyVector ( const TinyVector< N, T > &  V  )  [inline]

Copy constructor.

Parameters:
V the original vector

Definition at line 403 of file TinyVector.hpp.

00404   {
00405     for (size_t i=0; i<N; i++) 
00406       __x[i] = V.__x[i];
00407   }

template<size_t N, typename T = real_t>
TinyVector< N, T >::~TinyVector (  )  [inline]

Destructor

Definition at line 413 of file TinyVector.hpp.

00414   {
00415     ;
00416   }


Member Function Documentation

template<size_t N, typename T = real_t>
size_t TinyVector< N, T >::size (  )  const [inline]

template<size_t N, typename T = real_t>
T& TinyVector< N, T >::operator[] ( const size_t &  i  )  [inline]

Access to the i th coordinate.

Parameters:
i the component number
Returns:
ith component

Definition at line 75 of file TinyVector.hpp.

00076   {
00077     ASSERT (i<N);
00078     return __x[i];
00079   }

template<size_t N, typename T = real_t>
const T& TinyVector< N, T >::operator[] ( const size_t &  i  )  const [inline]

Read-only access to the i th component.

Parameters:
i the component number
Returns:
ith component

Definition at line 88 of file TinyVector.hpp.

00089   {
00090     ASSERT (i<N);
00091     return __x[i];
00092   }

template<size_t N, typename T = real_t>
const TinyVector<N, T>& TinyVector< N, T >::operator= ( const TinyVector< N, T > &  V  )  [inline]

Makes the current vector equal to a given one

Parameters:
V the vector to copy
Returns:
the modified vector

Definition at line 101 of file TinyVector.hpp.

Referenced by Vertex::operator=().

00102   {
00103     for (size_t i=0; i<N; i++)
00104       __x[i] = V.__x[i];
00105     return (*this);
00106   }

template<size_t N, typename T = real_t>
const TinyVector<N, T>& TinyVector< N, T >::operator= ( const T &  t  )  [inline]

Copies the value t to every component of the vector

Parameters:
t the value to copy
Returns:
the result vector

Definition at line 115 of file TinyVector.hpp.

00116   {
00117     for (size_t i=0; i<N; i++)
00118       __x[i] = t;
00119     return (*this);
00120   }

template<size_t N, typename T = real_t>
TinyVector<N, T> TinyVector< N, T >::operator* ( const T &  t  )  const [inline]

Returns multiplication by a T from the right ...

Parameters:
t the value
Returns:
$ t U $ where $ U$ is the current vector

Definition at line 129 of file TinyVector.hpp.

00130   {
00131     TinyVector<N, T> W;
00132     for (size_t i=0; i<N; i++)
00133       W.__x[i] = __x[i] * t;
00134     return W;
00135   }

template<size_t N, typename T = real_t>
real_t TinyVector< N, T >::operator* ( const TinyVector< N, T > &  V  )  const [inline]

Computes the scalar product with another vector

Parameters:
V the other vector
Returns:
$ U\cdot V$

Definition at line 144 of file TinyVector.hpp.

00145   {
00146     ASSERT(typeid(T) == typeid(real_t));
00147     real_t s=0;
00148     for (size_t i=0; i<N; i++)
00149       s += __x[i] * V.__x[i];
00150     return s;
00151   }

template<size_t N, typename T = real_t>
const TinyVector<N, T>& TinyVector< N, T >::operator*= ( const T &  t  )  [inline]

Multiplies the TinyVector by a T

Parameters:
t the given value
Returns:
$ U := t U$

Definition at line 160 of file TinyVector.hpp.

Referenced by TinyVector< 3, T >::operator/=(), and TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator/=().

00161   {
00162     for (size_t i=0; i<N; i++)
00163       __x[i] *= t;
00164     return (*this);
00165   }

template<size_t N, typename T = real_t>
const TinyVector<N, T>& TinyVector< N, T >::operator/= ( const T &  t  )  [inline]

Multiplies the TinyVector by the inverse of a T

Parameters:
t the given value
Returns:
$ U := t^{-1} U$

Definition at line 174 of file TinyVector.hpp.

00175   {
00176     const T temp = 1./t;
00177     this->operator*=(temp);
00178     return (*this);
00179   }

template<size_t N, typename T = real_t>
TinyVector<N, T> TinyVector< N, T >::operator- ( const TinyVector< N, T > &  V  )  const [inline]

Computes the difference with an other vector

Parameters:
V the other vector
Returns:
$ U - V $

Definition at line 188 of file TinyVector.hpp.

00189   {
00190     TinyVector<N, T> v = 0;
00191     for (size_t i=0; i<N; i++)
00192       v[i] = __x[i] - V.__x[i];
00193     return v;
00194   }

template<size_t N, typename T = real_t>
const TinyVector<N, T>& TinyVector< N, T >::operator-= ( const TinyVector< N, T > &  V  )  [inline]

Substracts a vector.

Parameters:
V the vector to remove
Returns:
$ U := U - V$

Definition at line 203 of file TinyVector.hpp.

00204   {
00205     for (size_t i=0; i<N; i++)
00206       __x[i] -= V.__x[i];
00207     return (*this);
00208   }

template<size_t N, typename T = real_t>
TinyVector<N, T> TinyVector< N, T >::operator^ ( const TinyVector< N, T > &  V  )  const [inline]

Computes the vectorial product with a vector

Parameters:
V the given vector
Returns:
$ U \land V $

Definition at line 217 of file TinyVector.hpp.

00218   {
00219     TinyVector<N, T> W=0;
00220     for (size_t i=0; i<N; i++)
00221       W[i] += __x[(i+1)%N] * V.__x[(i+2)%N] - __x[(i+2)%N] * V.__x[(i+1)%N];
00222     return W;
00223   }

template<size_t N, typename T = real_t>
TinyVector<N, T> TinyVector< N, T >::operator+ ( const TinyVector< N, T > &  V  )  const [inline]

Computes the sum with another vector

Parameters:
V the other vector
Returns:
$ U+V $

Definition at line 232 of file TinyVector.hpp.

00233   {
00234     TinyVector<N, T> W(*this);
00235     for (size_t i=0; i<N; i++)
00236       W.__x[i] += V.__x[i];
00237     return W;
00238   }

template<size_t N, typename T = real_t>
TinyVector<N, T>& TinyVector< N, T >::operator+= ( const TinyVector< N, T > &  V  )  [inline]

Adds a vector

Parameters:
V the vector to add
Returns:
$ U := U+V$

Definition at line 247 of file TinyVector.hpp.

00247                                                                    {
00248     for (size_t i=0; i<N; i++)
00249       __x[i] += V.__x[i];
00250     return (*this);
00251   }

template<size_t N, typename T = real_t>
bool TinyVector< N, T >::operator== ( const TinyVector< N, T > &  V  )  const [inline]

Compares two vectors

Parameters:
V the vector to compare with
Returns:
true if vector matches
Note:
Use this function only for special purpose when vectors can really match (not if results of numerical computations).

Definition at line 263 of file TinyVector.hpp.

00264   {
00265     for (size_t i=0; i<N; i++) {
00266       if (__x[i] != V.__x[i]) {
00267         return false;
00268       }
00269     }
00270     return true;
00271   }

template<size_t N, typename T = real_t>
bool TinyVector< N, T >::operator!= ( const TinyVector< N, T > &  V  )  const [inline]

Compares 2 vectors. true if they are not exactly the same

Parameters:
V the vector to compare with
Returns:
true if vector do not match

Definition at line 280 of file TinyVector.hpp.

00281   {
00282     for (size_t i=0; i<N; i++) {
00283       if (__x[i] != V.__x[i]) {
00284         return true;
00285       }
00286     }
00287     return false;
00288   }

template<size_t N, typename T = real_t>
bool TinyVector< N, T >::operator< ( const TinyVector< N, T > &  V  )  const [inline]

Compares two vectors

Parameters:
V the vector to compare with
Returns:
true is the vector is smaller than the given one
Note:
this function uses an arbitrary order

Definition at line 299 of file TinyVector.hpp.

00300   {
00301     for (size_t i=0; i<N; ++i) {
00302       if(__x[i] != V.__x[i]) {
00303         return (__x[i] < V.__x[i]);
00304       }
00305     }
00306     return false;
00307   }


Friends And Related Function Documentation

template<size_t N, typename T = real_t>
TinyVector<N, T> sqrt ( const TinyVector< N, T > &  V  )  [friend]

Returns the square root of a vector. (ie: it returns the vector whoose componnents are square roots of arg)

Parameters:
V the given vector
Returns:
$ \left( V_0^{\frac{1}{2}}, \ldots , V_N^{\frac{1}{2}} \right) $

Definition at line 317 of file TinyVector.hpp.

00318   {
00319     using namespace std;
00320     TinyVector<N, T> W;
00321     for (size_t i=0; i<N; i++)
00322       W.__x[i] = sqrt(V.__x[i]);
00323     return W;
00324   }

template<size_t N, typename T = real_t>
T Norm ( const TinyVector< N, T > &  V  )  [friend]

Returns the Euclidean norm of the vector.

Parameters:
V the vector which norm is to compute
Returns:
$ ||V||_2 $

Definition at line 333 of file TinyVector.hpp.

00334   {
00335     T t = 0;
00336     for (size_t i=0; i<N; i++) {
00337       t += V.__x[i]*V.__x[i];
00338     }
00339 
00340     using namespace std;
00341     return sqrt(t);
00342   }

template<size_t N, typename T = real_t>
TinyVector<N, T> operator* ( const T &  a,
const TinyVector< N, T > &  V 
) [friend]

Returns the multiplication of a TinyVector by a T on the left.

Parameters:
a the multiplicative constant
V the vector to multiply
Returns:
$ a V $

Definition at line 352 of file TinyVector.hpp.

00353   {
00354     return (V*a);
00355   }

template<size_t N, typename T = real_t>
std::ostream& operator<< ( std::ostream &  os,
const TinyVector< N, T > &  V 
) [friend]

Prints out the transposed of a vector in a stream

Parameters:
os the given stream
V the vector
Returns:
the modified stream

Definition at line 365 of file TinyVector.hpp.

00367   {
00368     ASSERT (N>0);
00369     os << '(';
00370     for (size_t i=0; i<N-1; i++)
00371       os << V[i] << ", ";
00372     os << V[N-1] << ')';
00373     return os;
00374   }


Member Data Documentation

template<size_t N, typename T = real_t>
T TinyVector< N, T >::__x[N] [protected]

stored data

Definition at line 54 of file TinyVector.hpp.

Referenced by TinyVector< 1, T >::operator const T &(), TinyVector< 1, T >::operator T &(), TinyVector< 3, T >::operator!=(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator!=(), TinyVector< 3, T >::operator*(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator*(), TinyVector< 3, T >::operator*=(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator*=(), TinyVector< 3, T >::operator+(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator+(), TinyVector< 3, T >::operator+=(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator+=(), TinyVector< 3, T >::operator-(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator-(), TinyVector< 3, T >::operator-=(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator-=(), TinyVector< 3, T >::operator<(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator<(), TinyVector< 3, T >::operator=(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator=(), TinyVector< 3, T >::operator==(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator==(), TinyVector< 1, T >::operator[](), TinyVector< 3, T >::operator[](), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator[](), TinyVector< 3, T >::operator^(), TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::operator^(), TinyVector< 3, T >::TinyVector(), and TinyVector< StaticPow< 2, Dimension >::value, Octree::__Node * >::TinyVector().


The documentation for this class was generated from the following file:

Generated on Wed Nov 19 00:16:29 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6