Claw  1.7.3
Public Types | Public Member Functions | Public Attributes | List of all members
claw::math::rectangle< T > Class Template Reference

A class representing a rectangle by his x,y coordinates, width and height. More...

#include <rectangle.hpp>

Public Types

typedef T value_type
 The type of the values we store.
typedef rectangle< value_typeself_type
 The type of the current class.

Public Member Functions

 rectangle ()
 Constructor.
template<typename U >
 rectangle (const rectangle< U > &that)
 Copy constructor.
template<typename U >
 rectangle (const box_2d< U > &that)
 Constructor from a box.
 rectangle (const value_type &_x, const value_type &_y, const value_type &_width, const value_type &_height)
 Constructor with initialization.
template<typename U >
 rectangle (const coordinate_2d< U > &pos, const value_type &_width, const value_type &_height)
 Constructor with initialization.
template<typename U >
 rectangle (const coordinate_2d< U > &pos, const coordinate_2d< U > &size)
 Constructor with initialization.
template<typename U >
rectangle< U > cast_value_type_to () const
 Get a copy of the rectangle by converting its members to a given type.
bool operator== (const self_type &that) const
 Tell if this rectangle equals an other rectangle.
bool operator!= (const self_type &that) const
 Tell if this rectangle equals an other rectangle.
value_type area () const
 Calculate the rectangle's area.
bool includes (const coordinate_2d< value_type > &p) const
 Tell if a point is in a rectangle.
bool includes (const self_type &r) const
 Tell if a rectangle is in a rectangle.
bool intersects (const self_type &r) const
 Tell if there is an intersection of two rectangles.
self_type intersection (const self_type &r) const
 Intersection of two rectangles.
self_type join (const self_type &r) const
 Get the smallest rectangle bounding both this rectangle and another one.
void set (const value_type &new_x, const value_type &new_y, const value_type &new_width, const value_type &new_height)
 set new position and size to the rectangle.
value_type left () const
 Get the x-coordinate of the left edge.
value_type right () const
 Get the x-coordinate of the right edge.
value_type bottom () const
 Get the y-coordinate of the bottom edge.
value_type top () const
 Get the y-coordinate of the top edge.
coordinate_2d< value_typesize () const
 Get the size of the rectangle.

Public Attributes

coordinate_2d< value_typeposition
 value_typeop left coordinates.
value_type width
 Width.
value_type height
 Height.

Detailed Description

template<class T>
class claw::math::rectangle< T >

A class representing a rectangle by his x,y coordinates, width and height.

This class considers that the y-axis increases from the top to the bottom (like a screen).

Author
Julien Jorge

Definition at line 51 of file rectangle.hpp.

Constructor & Destructor Documentation

template<class T >
template<class U >
claw::math::rectangle< T >::rectangle ( const rectangle< U > &  that)

Copy constructor.

Parameters
thatRectangle to copy from.

Definition at line 49 of file rectangle.tpp.

template<class T >
template<class U >
claw::math::rectangle< T >::rectangle ( const box_2d< U > &  that)

Constructor from a box.

Parameters
thatThe box to copy from.

Definition at line 62 of file rectangle.tpp.

template<class T >
claw::math::rectangle< T >::rectangle ( const value_type _x,
const value_type _y,
const value_type _width,
const value_type _height 
)

Constructor with initialization.

Parameters
_xRectangle's X-coordinate.
_yRectangle's Y-coordinate.
_widthRectangle's width.
_heightRectangle's height.

Definition at line 79 of file rectangle.tpp.

template<class T >
template<typename U >
claw::math::rectangle< T >::rectangle ( const coordinate_2d< U > &  pos,
const value_type _width,
const value_type _height 
)

Constructor with initialization.

Parameters
posThe position of the rectangle.
_widthRectangle's width.
_heightRectangle's height.

Definition at line 96 of file rectangle.tpp.

template<class T >
template<typename U >
claw::math::rectangle< T >::rectangle ( const coordinate_2d< U > &  pos,
const coordinate_2d< U > &  size 
)

Constructor with initialization.

Parameters
posThe position of the rectangle.
sizeThe size of the rectangle.

Definition at line 112 of file rectangle.tpp.

Member Function Documentation

template<class T >
template<typename U >
claw::math::rectangle< U > claw::math::rectangle< T >::cast_value_type_to ( ) const

Get a copy of the rectangle by converting its members to a given type.

Consider the following code:

rectangle<float> a;

...

rectangle<int> b(a);

The copy constructor will be called, and your compiler should print some warnings in your console. These warnings have a meaning, so we don't want to make them disapear by adding explicit type conversion inside the rectangle class nor adding a cast operator that will be used silently by the compiler.

If you really want to convert the type, this method will explicitly cast the member variables.

Definition at line 140 of file rectangle.tpp.

template<class T >
bool claw::math::rectangle< T >::includes ( const coordinate_2d< value_type > &  p) const

Tell if a point is in a rectangle.

Parameters
pThe supposed included point.

Definition at line 187 of file rectangle.tpp.

References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

template<class T >
bool claw::math::rectangle< T >::includes ( const self_type r) const

Tell if a rectangle is in a rectangle.

Parameters
rThe supposed included rectangle.

Definition at line 199 of file rectangle.tpp.

References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.

template<class T >
claw::math::rectangle< T > claw::math::rectangle< T >::intersection ( const self_type r) const

Intersection of two rectangles.

Parameters
rThe supposed intersecting rectangle.

Definition at line 227 of file rectangle.tpp.

Referenced by claw::graphic::image::fill(), claw::graphic::image::merge(), and claw::graphic::image::partial_copy().

template<class T >
bool claw::math::rectangle< T >::intersects ( const self_type r) const
template<class T >
claw::math::rectangle< T > claw::math::rectangle< T >::join ( const self_type r) const

Get the smallest rectangle bounding both this rectangle and another one.

Parameters
rThe other rectangle.

Definition at line 248 of file rectangle.tpp.

References claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::left(), claw::math::rectangle< T >::right(), and claw::math::rectangle< T >::top().

template<class T >
bool claw::math::rectangle< T >::operator!= ( const self_type that) const

Tell if this rectangle equals an other rectangle.

Parameters
thatThe rectangle to compare to.

Definition at line 164 of file rectangle.tpp.

template<class T >
bool claw::math::rectangle< T >::operator== ( const self_type that) const

Tell if this rectangle equals an other rectangle.

Parameters
thatThe rectangle to compare to.

Definition at line 152 of file rectangle.tpp.

References claw::math::rectangle< T >::height, claw::math::rectangle< T >::position, and claw::math::rectangle< T >::width.

template<class T >
void claw::math::rectangle< T >::set ( const value_type new_x,
const value_type new_y,
const value_type new_width,
const value_type new_height 
)

set new position and size to the rectangle.

Parameters
new_xNew x-coordinate.
new_yNew y-coordinate.
new_widthNew width.
new_heightNew height.

Definition at line 270 of file rectangle.tpp.


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