Claw
1.7.3
|
A rectangle represented by two points in a 2D space. More...
#include <box_2d.hpp>
Public Types | |
typedef T | value_type |
The type of the values we store. | |
typedef coordinate_2d< value_type > | point_type |
The type of the coordinates of the points representing the corners. | |
typedef box_2d< value_type > | self_type |
The type of the current class. |
Public Member Functions | |
box_2d () | |
Constructor. | |
box_2d (const self_type &that) | |
Copy constructor. | |
box_2d (const rectangle< value_type > &that) | |
Constructor from a rectangle. | |
box_2d (const point_type &p1, const point_type &p2) | |
Constructor from two points. | |
box_2d (const value_type &x1, const value_type &y1, const value_type &x2, const value_type &y2) | |
Constructor with initialization. | |
void | set (const value_type &x1, const value_type &y1, const value_type &x2, const value_type &y2) |
Set the coordinates of the two points. | |
template<typename U > | |
box_2d< U > | cast_value_type_to () const |
Get a copy of the box by converting its members to a given type. | |
value_type | area () const |
Calculate the box's area. | |
bool | includes (const coordinate_2d< value_type > &p) const |
Tell if a point is in a box. | |
bool | includes (const self_type &r) const |
Tell if a box_2d is in a box_2d. | |
bool | intersects (const self_type &r) const |
Tell if there is an intersection of two boxes. | |
self_type | intersection (const self_type &r) const |
Intersection of two box_2ds. | |
self_type | join (const self_type &r) const |
Join two box_2ds. | |
bool | empty () const |
Tell if the box has a dimension equal to zero. | |
value_type | top () const |
Get the y-coordinate of the top edge. | |
value_type | bottom () const |
Get the y-coordinate of the bottom edge. | |
value_type | left () const |
Get the x-coordinate of the left edge. | |
value_type | right () const |
Get the x-coordinate of the right edge. | |
point_type | top_left () const |
Get the coordinate of the top-left corner. | |
point_type | top_right () const |
Get the coordinate of the top-right corner. | |
point_type | bottom_left () const |
Get the coordinate of the bottom-left corner. | |
point_type | bottom_right () const |
Get the coordinate of the bottom-right corner. | |
void | top (const value_type &p) |
Move the top edge at a given position. | |
void | bottom (const value_type &p) |
Move the bottom edge at a given position. | |
void | left (const value_type &p) |
Move the left edge at a given position. | |
void | right (const value_type &p) |
Move the right edge at a given position. | |
void | top_left (const coordinate_2d< value_type > &p) |
Move the top-left corner at a given position. | |
void | top_right (const coordinate_2d< value_type > &p) |
Move the top-right corner at a given position. | |
void | bottom_left (const coordinate_2d< value_type > &p) |
Move the bottom-left corner at a given position. | |
void | bottom_right (const coordinate_2d< value_type > &p) |
Move the bottom-right corner at a given position. | |
void | shift_x (const value_type &d) |
Shift the position of the box on the x-axis. | |
void | shift_y (const value_type &d) |
Shift the position of the box on the y-axis. | |
value_type | width () const |
Return box' width. | |
value_type | height () const |
Return box' height. | |
coordinate_2d< value_type > | size () const |
Get the size of the box_2d. | |
bool | operator== (const self_type &vect) const |
Equality operator. | |
bool | operator!= (const self_type &vect) const |
Difference operator. | |
self_type | operator+ (const point_type &vect) const |
Translation. | |
self_type | operator- (const point_type &vect) const |
Translation. | |
self_type & | operator+= (const point_type &vect) |
Translation. | |
self_type & | operator-= (const point_type &vect) |
Translation. |
Public Attributes | |
point_type | first_point |
The first of the two points, representing one corner. | |
point_type | second_point |
The second of the two points, representing an other corner. |
A rectangle represented by two points in a 2D space.
Definition at line 46 of file box_2d.hpp.
claw::math::box_2d< T >::box_2d | ( | const self_type & | that | ) |
claw::math::box_2d< T >::box_2d | ( | const rectangle< value_type > & | that | ) |
Constructor from a rectangle.
that | Rectangle to copy from. |
Definition at line 61 of file box_2d.tpp.
claw::math::box_2d< T >::box_2d | ( | const point_type & | p1, |
const point_type & | p2 | ||
) |
Constructor from two points.
p1 | The first point. |
p2 | The second point. |
Definition at line 75 of file box_2d.tpp.
claw::math::box_2d< T >::box_2d | ( | const value_type & | x1, |
const value_type & | y1, | ||
const value_type & | x2, | ||
const value_type & | y2 | ||
) |
Constructor with initialization.
x1 | X-coordinate of the first point. |
y1 | Y-coordinate of the first point. |
x2 | X-coordinate of the second point. |
y2 | Y-coordinate of the second point. |
Definition at line 90 of file box_2d.tpp.
void claw::math::box_2d< T >::bottom | ( | const value_type & | p | ) |
Move the bottom edge at a given position.
p | The position. |
Definition at line 336 of file box_2d.tpp.
void claw::math::box_2d< T >::bottom_left | ( | const coordinate_2d< value_type > & | p | ) |
Move the bottom-left corner at a given position.
p | The position. |
Definition at line 396 of file box_2d.tpp.
References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
void claw::math::box_2d< T >::bottom_right | ( | const coordinate_2d< value_type > & | p | ) |
Move the bottom-right corner at a given position.
p | The position. |
Definition at line 409 of file box_2d.tpp.
References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
claw::math::box_2d< U > claw::math::box_2d< T >::cast_value_type_to | ( | ) | const |
Get a copy of the box by converting its members to a given type.
Consider the following code:
box_2d<float> a;
...
box_2d<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 box_2d 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 136 of file box_2d.tpp.
bool claw::math::box_2d< T >::includes | ( | const coordinate_2d< value_type > & | p | ) | const |
Tell if a point is in a box.
p | The supposed included point. |
Definition at line 160 of file box_2d.tpp.
References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
bool claw::math::box_2d< T >::includes | ( | const self_type & | r | ) | const |
Tell if a box_2d is in a box_2d.
r | The supposed included box_2d. |
Definition at line 172 of file box_2d.tpp.
References claw::math::box_2d< T >::first_point, and claw::math::box_2d< T >::second_point.
claw::math::box_2d< T > claw::math::box_2d< T >::intersection | ( | const self_type & | r | ) | const |
Intersection of two box_2ds.
r | The supposed intersecting box_2d. |
Definition at line 196 of file box_2d.tpp.
References CLAW_PRECOND.
bool claw::math::box_2d< T >::intersects | ( | const self_type & | r | ) | const |
Tell if there is an intersection of two boxes.
r | The supposed intersecting box. |
Definition at line 183 of file box_2d.tpp.
References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().
claw::math::box_2d< T > claw::math::box_2d< T >::join | ( | const self_type & | r | ) | const |
Join two box_2ds.
r | The box to join with. |
Definition at line 218 of file box_2d.tpp.
References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().
void claw::math::box_2d< T >::left | ( | const value_type & | p | ) |
Move the left edge at a given position.
p | The position. |
Definition at line 347 of file box_2d.tpp.
bool claw::math::box_2d< T >::operator!= | ( | const self_type & | that | ) | const |
claw::math::box_2d< T > claw::math::box_2d< T >::operator+ | ( | const point_type & | vect | ) | const |
claw::math::box_2d< T > & claw::math::box_2d< T >::operator+= | ( | const point_type & | vect | ) |
claw::math::box_2d< T > claw::math::box_2d< T >::operator- | ( | const point_type & | vect | ) | const |
Translation.
vect | The vector to substract to points. |
Definition at line 492 of file box_2d.tpp.
claw::math::box_2d< T > & claw::math::box_2d< T >::operator-= | ( | const point_type & | vect | ) |
Translation.
vect | The vector to substract to points. |
Definition at line 517 of file box_2d.tpp.
bool claw::math::box_2d< T >::operator== | ( | const self_type & | that | ) | const |
Equality operator.
that | Box to compare to. |
Definition at line 456 of file box_2d.tpp.
References claw::math::box_2d< T >::bottom(), claw::math::box_2d< T >::left(), claw::math::box_2d< T >::right(), and claw::math::box_2d< T >::top().
void claw::math::box_2d< T >::right | ( | const value_type & | p | ) |
Move the right edge at a given position.
p | The position. |
Definition at line 358 of file box_2d.tpp.
void claw::math::box_2d< T >::set | ( | const value_type & | x1, |
const value_type & | y1, | ||
const value_type & | x2, | ||
const value_type & | y2 | ||
) |
Set the coordinates of the two points.
x1 | X-coordinate of the first point. |
y1 | Y-coordinate of the first point. |
x2 | X-coordinate of the second point. |
y2 | Y-coordinate of the second point. |
Definition at line 107 of file box_2d.tpp.
References claw::math::box_2d< T >::set().
Referenced by claw::math::box_2d< T >::set().
void claw::math::box_2d< T >::shift_x | ( | const value_type & | d | ) |
Shift the position of the box on the x-axis.
d | The movement length. |
Definition at line 421 of file box_2d.tpp.
void claw::math::box_2d< T >::shift_y | ( | const value_type & | d | ) |
Shift the position of the box on the y-axis.
d | The movement length. |
Definition at line 433 of file box_2d.tpp.
void claw::math::box_2d< T >::top | ( | const value_type & | p | ) |
Move the top edge at a given position.
p | The position. |
Definition at line 325 of file box_2d.tpp.
void claw::math::box_2d< T >::top_left | ( | const coordinate_2d< value_type > & | p | ) |
Move the top-left corner at a given position.
p | The position. |
Definition at line 370 of file box_2d.tpp.
References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.
void claw::math::box_2d< T >::top_right | ( | const coordinate_2d< value_type > & | p | ) |
Move the top-right corner at a given position.
p | The position. |
Definition at line 383 of file box_2d.tpp.
References claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.