rectangle< T > Class Template Reference

#include <rectangle.h>

Inheritance diagram for rectangle< T >:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 rectangle ()
 rectangle (T x, T y, T width, T height)
 rectangle (Vector2< T > thePosition, Vector2< T > theSize)
void SetPosition (T x, T y)
void SetPosition (const Vector2< T > &newPos)
void SetPositionX (T x)
void SetPositionY (T y)
void SetSize (T sizeX, T sizeY)
void SetSizeX (T sizeX)
void SetSizeY (T sizeY)
void SetSize (Vector2< T > newSize)
rectangle< T > GetRectangle () const
Vector2< T > GetPosition () const
GetPositionX () const
GetPositionY () const
Vector2< T > GetSize () const
GetSizeX () const
GetSizeY () const
void Clip (const rectangle &cr)
bool Contains (const Vector2< T > p) const
bool Contains (const rectangle< T > &r2) const
bool Intersect (const rectangle< T > &r2) const
Vector2< T > GetTopLeftPoint () const
Vector2< T > GetTopRightPoint () const
Vector2< T > GetBottomLeftPoint () const
Vector2< T > GetBottomRightPoint () const
bool IsSizeZero () const

Protected Attributes

Vector2< T > position
Vector2< T > size

Detailed Description

template<class T>
class rectangle< T >

This template handle rectangles.

Parameters:
T Type for position and size of the Rectangle

Definition at line 36 of file rectangle.h.


Constructor & Destructor Documentation

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

Default constructor

Definition at line 48 of file rectangle.h.

00048                                   {
00049                 }

template<class T>
rectangle< T >::rectangle ( x,
y,
width,
height 
) [inline]

Constructor for building a new rectangle.

Parameters:
x Position among the x axe.
y Position among the y axe.
width Width of the new rectangle.
height Height of the new rectangle.

Definition at line 59 of file rectangle.h.

00059                                                              {
00060                         position.SetValues( x, y );
00061                         size.SetValues( width, height );
00062                 }

template<class T>
rectangle< T >::rectangle ( Vector2< T >  thePosition,
Vector2< T >  theSize 
) [inline]

Constructor for building a new rectangle with the position and size specified.

Parameters:
thePosition Position of the new rectangle.
theSize Size of the new rectangle.

Definition at line 70 of file rectangle.h.

00070                                                                             {
00071                         position = thePosition;
00072                         size = theSize;
00073                 }


Member Function Documentation

template<class T>
void rectangle< T >::Clip ( const rectangle< T > &  cr  )  [inline]

Clip the current rectangle using an other rectangle.

Parameters:
cr The rectangle used for clipping

Definition at line 183 of file rectangle.h.

00183                                                {
00184                         if( !Intersect(cr) ){
00185                                 size.x = 0;
00186                                 size.y = 0;
00187 
00188                                 return;
00189                         }
00190                         
00191                         Vector2<T> newPositionBR = GetBottomRightPoint();
00192 
00193                         if( position.x < cr.position.x )
00194                                 position.x = cr.position.x;
00195                         
00196                         if( position.x > cr.GetBottomRightPoint().x )
00197                                 position.x = cr.GetBottomRightPoint().x;
00198 
00199                         if( position.y < cr.position.y )
00200                                 position.y = cr.position.y;
00201                         
00202                         if( position.y > cr.GetBottomRightPoint().y )
00203                                 position.y = cr.GetBottomRightPoint().y;
00204 
00205                         if( newPositionBR.x < cr.position.x )
00206                                 newPositionBR.x = cr.position.x;
00207                         
00208                         if( newPositionBR.x > cr.GetBottomRightPoint().x )
00209                                 newPositionBR.x = cr.GetBottomRightPoint().x;
00210 
00211                         if( newPositionBR.y < cr.position.y )
00212                                 newPositionBR.y = cr.position.y;
00213                         
00214                         if( newPositionBR.y > cr.GetBottomRightPoint().y )
00215                                 newPositionBR.y = cr.GetBottomRightPoint().y;
00216 
00217                         size = newPositionBR - position + 1 ;
00218                         assert( cr.Contains( *this ) );
00219                 }

Here is the caller graph for this function:

template<class T>
bool rectangle< T >::Contains ( const rectangle< T > &  r2  )  const [inline]

Return true if r2 is contained in the current rectangle.

Parameters:
r2 The rectangle for witch the check if performed.

Definition at line 239 of file rectangle.h.

00239                                                                     {
00240                         if( r2.IsSizeZero() )
00241                                 return false;
00242                         
00243                         return Contains( r2.GetTopLeftPoint() ) &&
00244                                 Contains( r2.GetBottomRightPoint() );
00245                 }

template<class T>
bool rectangle< T >::Contains ( const Vector2< T >  p  )  const [inline]

Return true if the point p is contained in the rectangle.

Parameters:
p Point used to perform the check.

Definition at line 226 of file rectangle.h.

00226                                                                 {
00227                         if( IsSizeZero() )
00228                                 return false;
00229 
00230                         return p >= GetTopLeftPoint() &&
00231                                 p <= GetBottomRightPoint();
00232                 }

Here is the caller graph for this function:

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

Return the point in the bottom left corner of the rectangle.

If the rectangle has a size of zero, this point doesn't exist, so the program crash with a failled assertion.

Definition at line 301 of file rectangle.h.

00301                                                             {
00302                         assert( !IsSizeZero() );
00303                         Vector2<T> r = position;
00304 
00305                         r.y += size.y - 1;
00306 
00307                         return r;
00308                 }

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

Return the point in the top left corner of the rectangle.

If the rectangle has a size of zero, this point doesn't exist, so the program crash with a failled assertion.

Definition at line 315 of file rectangle.h.

00315                                                              {
00316                         assert( !IsSizeZero() );
00317                         return position + size - 1;
00318                 }

Here is the caller graph for this function:

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

Return the position of the rectangle.

Definition at line 151 of file rectangle.h.

00151                                                      {
00152                         return position;
00153                 }

Here is the caller graph for this function:

template<class T>
T rectangle< T >::GetPositionX (  )  const [inline]

Definition at line 155 of file rectangle.h.

00155                                              {
00156                         return position.x;                      
00157                 }

Here is the caller graph for this function:

template<class T>
T rectangle< T >::GetPositionY (  )  const [inline]

Definition at line 159 of file rectangle.h.

00159                                              {
00160                         return position.y;
00161                 }

Here is the caller graph for this function:

template<class T>
rectangle<T> rectangle< T >::GetRectangle (  )  const [inline]

Definition at line 144 of file rectangle.h.

00144                                                         {
00145                         return *this;
00146                 }

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

Return the size of the rectangle.

Definition at line 166 of file rectangle.h.

00166                                                  {
00167                         return size;
00168                 }

Here is the caller graph for this function:

template<class T>
T rectangle< T >::GetSizeX (  )  const [inline]

Definition at line 170 of file rectangle.h.

00170                                          {
00171                         return size.x;
00172                 }

Here is the caller graph for this function:

template<class T>
T rectangle< T >::GetSizeY (  )  const [inline]

Definition at line 174 of file rectangle.h.

00174                                          {
00175                         return size.y;
00176                 }

Here is the caller graph for this function:

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

Return the point in the top left corner of the rectangle.

If the rectangle has a size of zero, this point doesn't exist, so the program crash with a failled assertion.

Definition at line 275 of file rectangle.h.

00275                                                          {
00276                         assert( !IsSizeZero() );
00277                         return position;
00278                 }

Here is the caller graph for this function:

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

Return the point in the top right corner of the rectangle.

If the rectangle has a size of zero, this point doesn't exist, so the program crash with a failled assertion.

Definition at line 286 of file rectangle.h.

00286                                                           {
00287                         assert( !IsSizeZero() );
00288                         Vector2<T> r = position;
00289 
00290                         r.x += size.x - 1;
00291 
00292                         return r;
00293                 }

template<class T>
bool rectangle< T >::Intersect ( const rectangle< T > &  r2  )  const [inline]

Return true if there is an intersection between the current rectangle and the r2 rectangle.

Parameters:
r2 The second rectangle.

Definition at line 253 of file rectangle.h.

00253                                                                      {
00254                         if( IsSizeZero() || r2.IsSizeZero() )
00255                                 return false;
00256                         
00257                         Vector2<T> r1BR = GetBottomRightPoint();
00258                         Vector2<T> r2BR = r2.GetBottomRightPoint();
00259                         Vector2<T> r1TL = GetTopLeftPoint();
00260                         Vector2<T> r2TL = r2.GetTopLeftPoint();
00261 
00262                         if( r1BR.x < r2TL.x || r1BR.y < r2TL.y ||
00263                                    r2BR.x < r1TL.x || r2BR.y < r1TL.y ) 
00264                                 return false;
00265 
00266                         return true;
00267                 }

Here is the caller graph for this function:

template<class T>
bool rectangle< T >::IsSizeZero (  )  const [inline]

Return true if the rectangle has a size of zero.

Definition at line 323 of file rectangle.h.

00323                                               {
00324                         return size.IsXNull() || size.IsYNull();
00325                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetPosition ( const Vector2< T > &  newPos  )  [inline]

Change the position of the rectangle.

Parameters:
newPos The new position of the rectangle.

Definition at line 90 of file rectangle.h.

00090                                                                  {
00091                         position = newPos;
00092                 }

template<class T>
void rectangle< T >::SetPosition ( x,
y 
) [inline]

Set the position of the rectangle.

Parameters:
x New X position.
y New Y position.

Definition at line 81 of file rectangle.h.

00081                                                  {
00082                         position.SetValues(x, y);
00083                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetPositionX ( x  )  [inline]

Change the x position of the rectangle.

Parameters:
x New X position.

Definition at line 99 of file rectangle.h.

00099                                              {
00100                         position.x = x;
00101                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetPositionY ( y  )  [inline]

Change the y position of the rectangle.

Parameters:
y New Y position.

Definition at line 108 of file rectangle.h.

00108                                              {
00109                         position.y = y;
00110                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetSize ( Vector2< T >  newSize  )  [inline]

Definition at line 140 of file rectangle.h.

00140                                                        {
00141                         size = newSize;
00142                 }

template<class T>
void rectangle< T >::SetSize ( sizeX,
sizeY 
) [inline]

Set the size of the rectangle.

Parameters:
sizeX new size among the x axe.
sizeY new size among the y axe.

Definition at line 118 of file rectangle.h.

00118                                                      {
00119                         size.SetValues(sizeX, sizeY);
00120                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetSizeX ( sizeX  )  [inline]

Change the X size of the rectangle.

Parameters:
x New size among x axe.

Definition at line 127 of file rectangle.h.

00127                                              {
00128                         size.x = sizeX;
00129                 }

Here is the caller graph for this function:

template<class T>
void rectangle< T >::SetSizeY ( sizeY  )  [inline]

Change the Y size of the rectangle.

Parameters:
y New size among y axe.

Definition at line 136 of file rectangle.h.

00136                                              {
00137                         size.y = sizeY;
00138                 }

Here is the caller graph for this function:


Member Data Documentation

template<class T>
Vector2<T> rectangle< T >::position [protected]

Position of the rectangle.

Definition at line 40 of file rectangle.h.

template<class T>
Vector2<T> rectangle< T >::size [protected]

Size of the rectangle.

Definition at line 42 of file rectangle.h.


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