Vector2< T > Class Template Reference

#include <vector2.h>

Collaboration diagram for Vector2< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Vector2 ()
 Vector2 (T x, T y)
GetX () const
GetY () const
bool IsZero (T val) const
bool operator== (const Vector2< T > &p2) const
bool operator!= (const Vector2< T > &p2) const
bool operator>= (const Vector2< T > &p2) const
bool operator<= (const Vector2< T > &p2) const
Vector2< T > operator+ (const Vector2< T > &p2) const
Vector2< T > operator- (const Vector2< T > &p2) const
Vector2< T > operator- () const
Vector2< T > operator * (const Vector2< T > &p2) const
Vector2< T > operator/ (const Vector2< T > &p2) const
Vector2< T > operator% (const Vector2< T > &p2) const
Vector2< T > operator+ (const T val) const
Vector2< T > operator- (const T val) const
Vector2< T > operator * (const T val) const
Vector2< T > operator/ (const T val) const
void operator+= (const T val)
void operator-= (const T val)
void operator *= (const T val)
void operator+= (const Vector2< T > &p2)
void operator-= (const Vector2< T > &p2)
Vector2< T > operator * (const Vector2< double > &p2)
Vector2< T > inf (const Vector2< T > &p2)
Vector2< T > min (const Vector2< T > &p2) const
Vector2< T > max (const Vector2< T > &p2) const
Vector2< T > clamp (const Vector2< T > &min, const Vector2< T > &max) const
double Distance (const Vector2< T > p2) const
double Norm () const
void Clear ()
void SetValues (T xx, T yy)
void SetValues (Vector2< T > v2)
bool IsXNull () const
bool IsYNull () const
bool IsNull () const
double ComputeAngle () const
double ComputeAngle (const Vector2< T > v2) const

Public Attributes

x
y

Static Private Attributes

static const double EPS_ZERO = 0.05

Detailed Description

template<class T>
class Vector2< T >

Class for storing a vector of two points x, y.

Definition at line 10 of file vector2.h.


Constructor & Destructor Documentation

template<class T>
Vector2< T >::Vector2 (  )  [inline]

Default constructor that will be a vector null (0, 0)

Definition at line 21 of file vector2.h.

00021                                 {
00022                         x = 0;
00023                         y = 0;
00024                 }

Here is the caller graph for this function:

template<class T>
Vector2< T >::Vector2 ( x,
y 
) [inline]

Constructor that build a new vector from two values, x and y.

Parameters:
x 
y 

Definition at line 32 of file vector2.h.

00032                                         {
00033                         this->x = x;
00034                         this->y = y;
00035                 }


Member Function Documentation

template<class T>
Vector2<T> Vector2< T >::clamp ( const Vector2< T > &  min,
const Vector2< T > &  max 
) const [inline]

Definition at line 265 of file vector2.h.

00265                                                                                            {
00266                         Vector2<T> r = *this;
00267                         r = r.max(min);
00268                         return r.min(max);
00269                 }

Here is the caller graph for this function:

template<class T>
void Vector2< T >::Clear (  )  [inline]

Definition at line 290 of file vector2.h.

00290                             {
00291                         x = 0;
00292                         y = 0;
00293                 }

Here is the caller graph for this function:

template<class T>
double Vector2< T >::ComputeAngle ( const Vector2< T >  v2  )  const [inline]

Parameters:
v2 

Definition at line 374 of file vector2.h.

00374                                                               {
00375                         Vector2<T> veq( v2.x - x, v2.y - y);
00376 
00377                         return veq.ComputeAngle();
00378                 }

template<class T>
double Vector2< T >::ComputeAngle (  )  const [inline]

Calcule l'angle en radian du point M dans le repère de centre O

Pour O=(0,0) :

Definition at line 342 of file vector2.h.

00342                                            {
00343                   double angle;
00344 
00345                   if( !IsZero( x ) )
00346                     if( !IsZero( y ) ){
00347                       angle = atan(double(y)/double(x));
00348                       if( x < 0 )
00349                         if( y > 0 )
00350                           angle += M_PI;
00351                         else
00352                           angle -= M_PI;
00353                     }
00354                     else
00355                       if( x > 0)
00356                         angle = 0;
00357                       else
00358                         angle = M_PI;
00359                   else
00360                     if( y > 0 )
00361                       angle = M_PI_2;
00362                     else if(y < 0)
00363                       angle = -M_PI_2;
00364                     else
00365                       angle = 0;
00366 
00367                   return angle;
00368                 }

Here is the caller graph for this function:

template<class T>
double Vector2< T >::Distance ( const Vector2< T >  p2  )  const [inline]

Parameters:
p2 

Definition at line 275 of file vector2.h.

00275                                                                  {
00276                         double distPow2 = (p2.x-x)*(p2.x-x) + (p2.y-y)*(p2.y-y);
00277                         return sqrt( distPow2 );
00278                 }

Here is the caller graph for this function:

template<class T>
T Vector2< T >::GetX (  )  const [inline]

Return the x coordinate.

Definition at line 40 of file vector2.h.

00040                                      {
00041                         return x;
00042                 }

Here is the caller graph for this function:

template<class T>
T Vector2< T >::GetY (  )  const [inline]

Return the y coordinate.

Definition at line 47 of file vector2.h.

00047                                      {
00048                         return y;
00049                 }

Here is the caller graph for this function:

template<class T>
Vector2<T> Vector2< T >::inf ( const Vector2< T > &  p2  )  [inline]

Return the comparaison of two vector in the form of a vector.

Parameters:
p2 
Returns:
A vector in which the elements are equal to 1 where the comparaison is true, 0 elsewhere.

Definition at line 239 of file vector2.h.

00239                                                            {
00240                         return Vector2<T>( x < p2.x ? 1:0,
00241                                         y < p2.y ? 1:0);
00242                 }

Here is the caller graph for this function:

template<class T>
bool Vector2< T >::IsNull (  )  const [inline]

Definition at line 328 of file vector2.h.

00328                                    {
00329                         return IsXNull() && IsYNull();
00330                 }

Here is the caller graph for this function:

template<class T>
bool Vector2< T >::IsXNull (  )  const [inline]

Definition at line 314 of file vector2.h.

00314                                            {
00315                         return IsZero( x );
00316                 }

Here is the caller graph for this function:

template<class T>
bool Vector2< T >::IsYNull (  )  const [inline]

Definition at line 321 of file vector2.h.

00321                                            {
00322                         return IsZero( y );
00323                 }

Here is the caller graph for this function:

template<class T>
bool Vector2< T >::IsZero ( val  )  const [inline]

Definition at line 54 of file vector2.h.

00054                                                {
00055                         return (val == 0 || val <= VECTOR2_EPS_ZERO) &&
00056                                (-val <= VECTOR2_EPS_ZERO);
00057                 }

Here is the caller graph for this function:

template<class T>
Vector2<T> Vector2< T >::max ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 
Returns:

Definition at line 260 of file vector2.h.

00260                                                                  {
00261                         return Vector2<T>( x > p2.x? x:p2.x,
00262                                                y > p2.y? y:p2.y );
00263                 }

Here is the caller graph for this function:

template<class T>
Vector2<T> Vector2< T >::min ( const Vector2< T > &  p2  )  const [inline]

Return a vector made of the minimum coordinate of the two vectors. Ce clair ne pas ?

Parameters:
p2 
Returns:

Definition at line 251 of file vector2.h.

00251                                                                  {
00252                         return Vector2<T>( x < p2.x? x:p2.x,
00253                                         y < p2.y? y:p2.y );
00254                 }

Here is the caller graph for this function:

template<class T>
double Vector2< T >::Norm (  )  const [inline]

Definition at line 283 of file vector2.h.

00283                                    {
00284                         return Distance( Vector2(0,0) );
00285                 }

Here is the caller graph for this function:

template<class T>
Vector2<T> Vector2< T >::operator * ( const Vector2< double > &  p2  )  [inline]

Definition at line 224 of file vector2.h.

00224                                                                       {
00225                         Vector2<T> r;
00226 
00227                         r.x = (T)((double)x * p2.x);
00228                         r.y = (T)((double)y * p2.y);
00229 
00230                         return r;
00231                 }

template<class T>
Vector2<T> Vector2< T >::operator * ( const T  val  )  const [inline]

Definition at line 159 of file vector2.h.

00159                                                               {
00160                         return Vector2<T>(x * val, y * val);
00161                 }

template<class T>
Vector2<T> Vector2< T >::operator * ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 122 of file vector2.h.

00122                                                                        {
00123                         return Vector2<T>(x * p2.x, y * p2.y);
00124                 }

template<class T>
void Vector2< T >::operator *= ( const T  val  )  [inline]

Definition at line 195 of file vector2.h.

00195                                                    {
00196                         x *= val;
00197                         y *= val;
00198                 }

template<class T>
bool Vector2< T >::operator!= ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 72 of file vector2.h.

00072                                                                   {
00073                         return (x != p2.x) || (y != p2.y);
00074                 }

template<class T>
Vector2<T> Vector2< T >::operator% ( const Vector2< T > &  p2  )  const [inline]

Definition at line 134 of file vector2.h.

00134                                                                        {
00135                         return Vector2<T>(x % p2.x, y % p2.y);
00136                 }

template<class T>
Vector2<T> Vector2< T >::operator+ ( const T  val  )  const [inline]

Parameters:
val 

Definition at line 144 of file vector2.h.

00144                                                               {
00145                         return Vector2<T>(x + val, y + val);
00146                 }

template<class T>
Vector2<T> Vector2< T >::operator+ ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 98 of file vector2.h.

00098                                                                        {
00099                         return Vector2<T>(x + p2.x, y + p2.y);
00100                 }

template<class T>
void Vector2< T >::operator+= ( const Vector2< T > &  p2  )  [inline]

Parameters:
p2 

Definition at line 206 of file vector2.h.

00206                                                             {
00207                         x += p2.x;
00208                         y += p2.y;
00209                 }

template<class T>
void Vector2< T >::operator+= ( const T  val  )  [inline]

Parameters:
val 

Definition at line 178 of file vector2.h.

00178                                                    {
00179                         x += val;
00180                         y += val;
00181                 }

template<class T>
Vector2<T> Vector2< T >::operator- ( const T  val  )  const [inline]

Parameters:
val 

Definition at line 152 of file vector2.h.

00152                                                               {
00153                         return Vector2<T>(x - val, y - val);
00154                 }

template<class T>
Vector2<T> Vector2< T >::operator- (  )  const [inline]

Returns:
the negative value of ourself

Definition at line 114 of file vector2.h.

00114                                                    {
00115                         return Vector2<T>(-x, -y);
00116                 }

template<class T>
Vector2<T> Vector2< T >::operator- ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 106 of file vector2.h.

00106                                                                        {
00107                         return Vector2<T>(x - p2.x, y - p2.y);
00108                 }

template<class T>
void Vector2< T >::operator-= ( const Vector2< T > &  p2  )  [inline]

Parameters:
p2 

Definition at line 214 of file vector2.h.

00214                                                             {
00215                         x -= p2.x;
00216                         y -= p2.y;
00217                 }

template<class T>
void Vector2< T >::operator-= ( const T  val  )  [inline]

Parameters:
val 

Definition at line 187 of file vector2.h.

00187                                                    {
00188                         x -= val;
00189                         y += val;
00190                 }

template<class T>
Vector2<T> Vector2< T >::operator/ ( const T  val  )  const [inline]

Parameters:
val 

Definition at line 167 of file vector2.h.

00167                                                               {
00168                         return Vector2<T>(x / val, y / val);
00169         }

template<class T>
Vector2<T> Vector2< T >::operator/ ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 130 of file vector2.h.

00130                                                                        {
00131                         return Vector2<T>(x / p2.x, y / p2.y);
00132                 }

template<class T>
bool Vector2< T >::operator<= ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 88 of file vector2.h.

00088                                                                   {
00089                         return (x <= p2.x) && (y <= p2.y);
00090                 }

template<class T>
bool Vector2< T >::operator== ( const Vector2< T > &  p2  )  const [inline]

Definition at line 64 of file vector2.h.

00064                                                                   {
00065                         return IsZero(x - p2.x) && IsZero(y - p2.y);
00066                 }

template<class T>
bool Vector2< T >::operator>= ( const Vector2< T > &  p2  )  const [inline]

Parameters:
p2 

Definition at line 80 of file vector2.h.

00080                                                                   {
00081                         return (x >= p2.x) && (y >= p2.y);
00082                 }

template<class T>
void Vector2< T >::SetValues ( Vector2< T >  v2  )  [inline]

Definition at line 306 of file vector2.h.

00306                                               {
00307                         x = v2.x;
00308                         y = v2.y;
00309                 }

template<class T>
void Vector2< T >::SetValues ( xx,
yy 
) [inline]

Definition at line 298 of file vector2.h.

00298                                             {
00299                         x = xx;
00300                         y = yy;
00301                 }

Here is the caller graph for this function:


Member Data Documentation

template<class T>
const double Vector2< T >::EPS_ZERO = 0.05 [static, private]

Definition at line 13 of file vector2.h.

template<class T>
T Vector2< T >::x

Definition at line 16 of file vector2.h.

template<class T>
T Vector2< T >::y

Definition at line 16 of file vector2.h.


The documentation for this class was generated from the following file:
Generated on Mon Jan 1 14:28:03 2007 for Wormux by  doxygen 1.4.7