TinyVector< 3, T > Class Template Reference

#include <TinyVector.hpp>

Collaboration diagram for TinyVector< 3, T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Protected Attributes

__x [3]
 stored data

Private Types

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

Friends

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


Detailed Description

template<class T>
class TinyVector< 3, T >

Definition at line 429 of file TinyVector.hpp.


Member Typedef Documentation

template<class T>
typedef T TinyVector< 3, T >::ValueType [private]

The type of values stored in the TinyVector.

Definition at line 432 of file TinyVector.hpp.


Member Enumeration Documentation

template<class T>
anonymous enum [private]

Enumerator:
Dimension  The dimension of the vector

Definition at line 434 of file TinyVector.hpp.

00434        {
00435     Dimension = 3               
00436   };


Constructor & Destructor Documentation

template<class T>
TinyVector< 3, T >::TinyVector ( const T &  x1,
const T &  x2,
const T &  x3 
) [inline]

Constructs the vector using three values

Parameters:
x1 first component
x2 second component
x3 third component

Definition at line 771 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00772   {
00773     __x[0] = x1;
00774     __x[1] = x2;
00775     __x[2] = x3;
00776   }

template<class T>
TinyVector< 3, T >::TinyVector (  )  [inline]

Default constructor.

Note:
data are not initialized

Definition at line 783 of file TinyVector.hpp.

00784   {
00785     ;
00786   }

template<class T>
TinyVector< 3, T >::TinyVector ( const T &  t  )  [inline]

Construct the vector setting its coordinates to t.

Parameters:
t the given value

Definition at line 793 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00794   {
00795     for (size_t i=0; i<3; i++)
00796       __x[i] = t;
00797   }

template<class T>
TinyVector< 3, T >::TinyVector ( const TinyVector< 3, T > &  V  )  [inline]

Copy constructor.

Parameters:
V the original vector

Definition at line 804 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00805   {
00806     for (size_t i=0; i<3; i++) 
00807       __x[i] = V.__x[i];
00808   }

template<class T>
TinyVector< 3, T >::~TinyVector (  )  [inline]

Destructor

Definition at line 814 of file TinyVector.hpp.

00815   {
00816     ;
00817   }


Member Function Documentation

template<class T>
size_t TinyVector< 3, T >::size (  )  const [inline]

Read-only access to the dimension of the TinyVector.

Returns:
3

Definition at line 449 of file TinyVector.hpp.

00450   {
00451     return 3;
00452   }

template<class T>
T& TinyVector< 3, T >::operator[] ( const size_t &  i  )  [inline]

Access to the i th coordinate.

Parameters:
i the component number
Returns:
ith component

Definition at line 461 of file TinyVector.hpp.

References TinyVector< N, T >::__x, and ASSERT.

00462   {
00463     ASSERT (i<3);
00464     return __x[i];
00465   }

template<class T>
const T& TinyVector< 3, 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 474 of file TinyVector.hpp.

References TinyVector< N, T >::__x, and ASSERT.

00475   {
00476     ASSERT (i<3);
00477     return __x[i];
00478   }

template<class T>
const TinyVector<3, T>& TinyVector< 3, T >::operator= ( const TinyVector< 3, 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 487 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00488   {
00489     for (size_t i=0; i<3; i++)
00490       __x[i] = V.__x[i];
00491     return (*this);
00492   }

template<class T>
const TinyVector<3, T>& TinyVector< 3, 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 501 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00502   {
00503     for (size_t i=0; i<3; i++)
00504       __x[i] = t;
00505     return (*this);
00506   }

template<class T>
TinyVector<3, T> TinyVector< 3, 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 515 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00516   {
00517     TinyVector<3,T> W;
00518     for (size_t i=0; i<3; i++) {
00519       W.__x[i] = __x[i] * t;
00520     }
00521     return W;
00522   }

template<class T>
real_t TinyVector< 3, T >::operator* ( const TinyVector< 3, T > &  V  )  const [inline]

Computes the scalar product with another vector

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

Definition at line 531 of file TinyVector.hpp.

References TinyVector< N, T >::__x, and ASSERT.

00532   {
00533     ASSERT(typeid(T) == typeid(real_t));
00534     real_t s=0;
00535     for (size_t i=0; i<3; i++)
00536       s += __x[i] * V.__x[i];
00537     return s;
00538   }

template<class T>
TinyVector<3, T>& TinyVector< 3, T >::operator*= ( const T &  t  )  [inline]

Multiplies the TinyVector by a T

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

Definition at line 547 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00548   {
00549     for (size_t i=0; i<3; i++)
00550       __x[i] *= t;
00551     return (*this);
00552   }

template<class T>
TinyVector<3, T>& TinyVector< 3, 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 561 of file TinyVector.hpp.

References TinyVector< N, T >::operator*=().

00562   {
00563     const T temp = 1./t;
00564     this->operator*=(temp);
00565     return (*this);
00566   }

Here is the call graph for this function:

template<class T>
TinyVector<3, T> TinyVector< 3, T >::operator- ( const TinyVector< 3, T > &  V  )  const [inline]

Computes the difference with an other vector

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

Definition at line 575 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00576   {
00577     TinyVector<3, T> v = 0;
00578     for (size_t i=0; i<3; i++)
00579       v[i] = __x[i] - V.__x[i];
00580     return v;
00581   }

template<class T>
TinyVector<3, T> TinyVector< 3, T >::operator- (  )  const [inline]

Returns the opposed TinyVector.

Returns:
$ -X $

Definition at line 589 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00590   {
00591     return (TinyVector<3, T> (-__x[0],-__x[1],-__x[2]));
00592   }

template<class T>
const TinyVector<3, T>& TinyVector< 3, T >::operator-= ( const TinyVector< 3, T > &  V  )  [inline]

Substracts a vector.

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

Definition at line 601 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00602   {
00603     for (size_t i=0; i<3; i++)
00604       __x[i] -= V.__x[i];
00605     return (*this);
00606   }

template<class T>
TinyVector<3, T> TinyVector< 3, T >::operator^ ( const TinyVector< 3, T > &  V  )  const [inline]

Computes the vectorial product with a vector

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

Definition at line 615 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00616   {
00617     TinyVector<3, T> W(0);
00618     for (size_t i=0; i<3; i++)
00619       W[i] += __x[(i+1)%3] * V.__x[(i+2)%3] - __x[(i+2)%3] * V.__x[(i+1)%3];
00620     return W;
00621   }

template<class T>
TinyVector<3, T> TinyVector< 3, T >::operator+ ( const TinyVector< 3, T > &  V  )  const [inline]

Computes the sum with another vector

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

Definition at line 630 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00631   {
00632     TinyVector<3, T> W(*this);
00633     for (size_t i=0; i<3; i++)
00634       W.__x[i] += V.__x[i];
00635     return W;
00636   }

template<class T>
const TinyVector<3, T>& TinyVector< 3, T >::operator+= ( const TinyVector< 3, T > &  V  )  [inline]

Adds a vector

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

Definition at line 645 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00646   {
00647     for (size_t i=0; i<3; i++)
00648       __x[i] += V.__x[i];
00649     return (*this);
00650   }

template<class T>
bool TinyVector< 3, T >::operator== ( const TinyVector< 3, 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 662 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00663   {
00664     return ((__x[0]==V.__x[0])&&(__x[1]==V.__x[1])&&(__x[2]==V.__x[2]));
00665   }

template<class T>
bool TinyVector< 3, T >::operator!= ( const TinyVector< 3, 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 674 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00675   {
00676     return ((__x[0]!=V.__x[0])||(__x[1]!=V.__x[1])||(__x[2]!=V.__x[2]));
00677   }

template<class T>
bool TinyVector< 3, T >::operator< ( const TinyVector< 3, 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 688 of file TinyVector.hpp.

References TinyVector< N, T >::__x.

00689   {
00690     for (size_t i=0; i<3; ++i) {
00691       if(__x[i] != V.__x[i]) {
00692         return (__x[i] < V.__x[i]);
00693       }
00694     }
00695     return false;
00696   }


Friends And Related Function Documentation

template<class T>
TinyVector<3, T> sqrt ( const TinyVector< 3, 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 706 of file TinyVector.hpp.

00707   {
00708     using namespace std;
00709     TinyVector<3, T> W;
00710     for (size_t i=0; i<3; i++)
00711       W.__x[i] = sqrt(V.__x[i]);
00712     return W;
00713   }

template<class T>
real_t Norm ( const TinyVector< 3, 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 722 of file TinyVector.hpp.

00723   {
00724     ASSERT(typeid(T) == typeid(real_t));
00725     real_t d = 0;
00726     for (size_t i=0; i<3; i++)
00727       d += V.__x[i]*V.__x[i];
00728     using namespace std;
00729     return sqrt(d);
00730   }

template<class T>
TinyVector<3, T> operator* ( const real_t &  a,
const TinyVector< 3, 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 740 of file TinyVector.hpp.

00742   {
00743     return (V*a);
00744   }

template<class T>
std::ostream& operator<< ( std::ostream &  os,
const TinyVector< 3, 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 754 of file TinyVector.hpp.

00756   {
00757     os << '(';
00758     for (size_t i=0; i<3-1; i++)
00759       os << V[i] << ", ";
00760     os << V[3-1] << ')';
00761     return os;
00762   }


Member Data Documentation

template<class T>
T TinyVector< 3, T >::__x[3] [protected]

stored data

Definition at line 440 of file TinyVector.hpp.


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

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