#include <rectangle.hpp>
Definition at line 46 of file rectangle.hpp.
Public Types | |
typedef T | value_type |
The type of the values we store. | |
typedef rectangle< value_type > | self_type |
The type of the current class. | |
Public Member Functions | |
rectangle () | |
Constructor. | |
template<typename U> | |
rectangle (const rectangle< U > &that) | |
Copy constructor. | |
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. | |
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. | |
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 | right () const |
Get the x-coordinate of the right edge. | |
value_type | bottom () const |
Get the y-coordinate of the bottom edge. | |
coordinate_2d< value_type > | size () const |
Get the size of the rectangle. | |
Public Attributes | |
coordinate_2d< value_type > | position |
value_typeop left coordinates. | |
value_type | width |
Width. | |
value_type | height |
Height. | |
Private Member Functions | |
void | x_intersection (const self_type &r, self_type &result) const |
X-intersection of two rectangles. | |
void | y_intersection (const self_type &r, self_type &result) const |
Y-intersection of two rectangles. |
typedef T claw::math::rectangle< T >::value_type |
typedef rectangle<value_type> claw::math::rectangle< T >::self_type |
claw::math::rectangle< T >::rectangle | ( | ) | [inline] |
claw::math::rectangle< T >::rectangle | ( | const rectangle< U > & | that | ) | [inline] |
claw::math::rectangle< T >::rectangle | ( | const value_type & | _x, | |
const value_type & | _y, | |||
const value_type & | _width, | |||
const value_type & | _height | |||
) | [inline] |
Constructor with initialization.
_x | Rectangle's X-coordinate. | |
_y | Rectangle's Y-coordinate. | |
_width | Rectangle's width. | |
_height | Rectangle's height. |
Definition at line 65 of file rectangle.tpp.
00067 : position(_x, _y), width(_width), height(_height) 00068 { 00069 00070 } // rectangle::rectangle() [constructor with values]
claw::math::rectangle< T >::rectangle | ( | const coordinate_2d< U > & | pos, | |
const value_type & | _width, | |||
const value_type & | _height | |||
) | [inline] |
Constructor with initialization.
pos | The position of the rectangle. | |
_width | Rectangle's width. | |
_height | Rectangle's height. |
Definition at line 82 of file rectangle.tpp.
00084 : position(pos), width(_width), height(_height) 00085 { 00086 00087 } // rectangle::rectangle() [constructor from position and size]
claw::math::rectangle< T >::rectangle | ( | const coordinate_2d< U > & | pos, | |
const coordinate_2d< U > & | size | |||
) | [inline] |
claw::math::rectangle< U > claw::math::rectangle< T >::cast_value_type_to | ( | ) | const [inline] |
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 wan't 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 126 of file rectangle.tpp.
References claw::math::rectangle< T >::height, claw::math::rectangle< T >::position, and claw::math::rectangle< T >::width.
00127 { 00128 return claw::math::rectangle<U> 00129 ( position.cast_value_type_to<U>(), (U)width, (U)height ); 00130 } // rectangle::cast_value_type_to()
claw::math::rectangle< T >::value_type claw::math::rectangle< T >::area | ( | ) | const [inline] |
Calculate the rectangle's area.
Definition at line 138 of file rectangle.tpp.
References claw::math::rectangle< T >::height, and claw::math::rectangle< T >::width.
bool claw::math::rectangle< T >::includes | ( | const coordinate_2d< value_type > & | p | ) | const [inline] |
Tell if a point is in a rectangle.
p | The supposed included point. |
Definition at line 150 of file rectangle.tpp.
References claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::position, claw::math::rectangle< T >::right(), claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
Referenced by claw::math::rectangle< T >::includes().
00151 { 00152 return (position.x <= p.x) && (right() >= p.x) 00153 && (position.y <= p.y) && (bottom() >= p.y); 00154 } // rectangle::includes()
bool claw::math::rectangle< T >::includes | ( | const self_type & | r | ) | const [inline] |
Tell if a rectangle is in a rectangle.
r | The supposed included rectangle. |
Definition at line 162 of file rectangle.tpp.
References claw::math::box_2d< T >::first_point, claw::math::rectangle< T >::includes(), and claw::math::box_2d< T >::second_point.
00163 { 00164 box_2d<value_type> his_box(r); 00165 00166 return includes(his_box.first_point) && includes(his_box.second_point); 00167 } // rectangle::includes() [rectangle]
bool claw::math::rectangle< T >::intersects | ( | const self_type & | r | ) | const [inline] |
Tell if there is an intersection of two rectangles.
r | The supposed intersecting rectangle. |
Definition at line 175 of file rectangle.tpp.
References claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::position, and claw::math::rectangle< T >::right().
Referenced by claw::math::rectangle< T >::intersection(), and claw::graphic::image::partial_copy().
00176 { 00177 return (right() >= r.position.x) 00178 && (r.right() >= position.x) 00179 && (bottom() >= r.position.y) 00180 && (r.bottom() >= position.y); 00181 } // rectangle::intersects()
claw::math::rectangle< T > claw::math::rectangle< T >::intersection | ( | const self_type & | r | ) | const [inline] |
Intersection of two rectangles.
r | The supposed intersecting rectangle. |
Definition at line 190 of file rectangle.tpp.
References claw::math::rectangle< T >::intersects(), claw::math::rectangle< T >::x_intersection(), and claw::math::rectangle< T >::y_intersection().
Referenced by claw::graphic::image::partial_copy().
00191 { 00192 self_type result; 00193 00194 if ( intersects(r) ) 00195 { 00196 x_intersection(r, result); 00197 y_intersection(r, result); 00198 } 00199 00200 return result; 00201 } // rectangle::intersection()
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 | |||
) | [inline] |
set new position and size to the rectangle.
new_x | New x-coordinate. | |
new_y | New y-coordinate. | |
new_width | New width. | |
new_height | New height. |
Definition at line 213 of file rectangle.tpp.
References claw::math::rectangle< T >::height, claw::math::rectangle< T >::position, and claw::math::rectangle< T >::width.
00215 { 00216 position.x = new_x; 00217 position.y = new_y; 00218 width = new_width; 00219 height = new_height; 00220 } // rectangle::set()
claw::math::rectangle< T >::value_type claw::math::rectangle< T >::right | ( | ) | const [inline] |
Get the x-coordinate of the right edge.
Definition at line 228 of file rectangle.tpp.
References claw::math::rectangle< T >::position, and claw::math::rectangle< T >::width.
Referenced by claw::math::rectangle< T >::includes(), claw::math::rectangle< T >::intersects(), and claw::math::rectangle< T >::x_intersection().
claw::math::rectangle< T >::value_type claw::math::rectangle< T >::bottom | ( | ) | const [inline] |
Get the y-coordinate of the bottom edge.
Definition at line 239 of file rectangle.tpp.
References claw::math::rectangle< T >::height, and claw::math::rectangle< T >::position.
Referenced by claw::math::rectangle< T >::includes(), claw::math::rectangle< T >::intersects(), and claw::math::rectangle< T >::y_intersection().
claw::math::coordinate_2d< typename claw::math::rectangle< T >::value_type > claw::math::rectangle< T >::size | ( | ) | const [inline] |
Get the size of the rectangle.
Definition at line 250 of file rectangle.tpp.
References claw::math::rectangle< T >::height, and claw::math::rectangle< T >::width.
00251 { 00252 return claw::math::coordinate_2d<value_type>(width, height); 00253 } // rectangle::size()
void claw::math::rectangle< T >::x_intersection | ( | const self_type & | r, | |
self_type & | result | |||
) | const [inline, private] |
X-intersection of two rectangles.
Definition at line 262 of file rectangle.tpp.
References claw::math::rectangle< T >::position, claw::math::rectangle< T >::right(), claw::math::rectangle< T >::width, and claw::math::rectangle< T >::x_intersection().
Referenced by claw::math::rectangle< T >::intersection(), and claw::math::rectangle< T >::x_intersection().
00264 { 00265 if (position.x <= r.position.x) 00266 { 00267 result.position.x = r.position.x; 00268 00269 if (right() >= r.right()) 00270 result.width = r.width; 00271 else 00272 result.width = right() - r.position.x; 00273 } 00274 else 00275 r.x_intersection(*this, result); 00276 00277 } // rectangle::x_intersection()
void claw::math::rectangle< T >::y_intersection | ( | const self_type & | r, | |
self_type & | result | |||
) | const [inline, private] |
Y-intersection of two rectangles.
Definition at line 286 of file rectangle.tpp.
References claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::height, claw::math::rectangle< T >::position, and claw::math::rectangle< T >::y_intersection().
Referenced by claw::math::rectangle< T >::intersection(), and claw::math::rectangle< T >::y_intersection().
00288 { 00289 if (position.y <= r.position.y) 00290 { 00291 result.position.y = r.position.y; 00292 00293 if (bottom() >= r.bottom()) 00294 result.height = r.height; 00295 else 00296 result.height = bottom() - r.position.y; 00297 } 00298 else 00299 r.y_intersection(*this, result); 00300 00301 } // rectangle::y_intersection()
coordinate_2d<value_type> claw::math::rectangle< T >::position |
value_typeop left coordinates.
Definition at line 94 of file rectangle.hpp.
Referenced by claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::cast_value_type_to(), claw::math::rectangle< T >::includes(), claw::math::rectangle< T >::intersects(), claw::graphic::image::partial_copy(), claw::math::rectangle< T >::right(), claw::math::rectangle< T >::set(), claw::math::rectangle< T >::x_intersection(), and claw::math::rectangle< T >::y_intersection().
value_type claw::math::rectangle< T >::width |
Width.
Definition at line 97 of file rectangle.hpp.
Referenced by claw::math::rectangle< T >::area(), claw::math::rectangle< T >::cast_value_type_to(), claw::graphic::image::partial_copy(), claw::math::rectangle< T >::right(), claw::math::rectangle< T >::set(), claw::math::rectangle< T >::size(), and claw::math::rectangle< T >::x_intersection().
value_type claw::math::rectangle< T >::height |
Height.
Definition at line 100 of file rectangle.hpp.
Referenced by claw::math::rectangle< T >::area(), claw::math::rectangle< T >::bottom(), claw::math::rectangle< T >::cast_value_type_to(), claw::graphic::image::partial_copy(), claw::math::rectangle< T >::set(), claw::math::rectangle< T >::size(), and claw::math::rectangle< T >::y_intersection().