last update 20 Sep 2009 |
#include <cvrRectangle.h>
Public Types | |
typedef T | value_type |
typedef S | side_type |
Public Member Functions | |
rectangle () | |
rectangle (const point< T > &ul, const point< T > &br) | |
rectangle (const T &left, const T &top, const T &right, const T &bottom) | |
rectangle (const T &size) | |
template<typename U , class US > | |
rectangle (const rectangle< U, US > &other) | |
bool | set (const T &left, const T &top, const T &right, const T &bottom) |
bool | set (const point< T > &ul, const point< T > &br) |
bool | setConsistent (const T &left, const T &top, const T &right, const T &bottom) |
bool | setConsistent (const point< T > &ul, const point< T > &br) |
Location and Dimensions | |
void | resize (const point< T > &dim) |
void | resize (const T &x, const T &y) |
point< T > | getDimensions () const |
typeInfo< T > ::square_accumulation_type | getArea () const |
point< T > | getCenter () const |
void | setCenter (point< T > center) |
void | ensureConsistency () |
bool | isConsistent () const |
void | shift (const point< T > &delta) |
void | shift (const rectangle< T, S > &other, const point< T > &delta) |
Simple operations | |
bool | contains (const point< T > &p) const |
bool | contains (const T &x, const T &y) const |
Duplication | |
rectangle< T, S > & | copy (const rectangle< T, S > &other) |
template<class U , class SU > | |
rectangle< T, S > & | castFrom (const rectangle< U, SU > &other) |
rectangle< T, S > & | operator= (const rectangle< T, S > &other) |
Comparison | |
bool | operator== (const rectangle< T, S > &other) const |
bool | operator!= (const rectangle< T, S > &other) const |
Geometrical combination | |
rectangle< T, S > & | intersect (const rectangle< T, S > &tRect) |
bool | overlaps (const rectangle< T, S > &tRect) const |
bool | isClose (const rectangle< T, S > &tRect, const point< T > &dist) const |
rectangle< T, S > & | operator&= (const rectangle< T, S > &tRect) |
rectangle< T, S > | operator& (const rectangle< T, S > &tRect) |
rectangle< T, S > & | join (const rectangle< T, S > &tRect) |
rectangle< T, S > & | operator|= (const rectangle< T, S > &tRect) |
rectangle< T, S > | operator| (const rectangle< T, S > &tRect) |
Public Attributes | |
The two corners of the rectangle | |
point< T > | ul |
point< T > | br |
A rectangle is described by a pair of points: the upper-left and bottom-right corners.
A consistent rectangle will have the x and y coordinates of its upper- left corner smaller than the ones of its bottom-right corner (note the use of a left coordinate system, as usual with imaging systems).
You can always check if a rectangle is consistent with the method isConsistent()
or even force its consistency with ensureConsistency()
.
This is a template class, where the first template parameter T
denotes the type used for the two points, which will be of type point<T>
. For example, the type rectangle<int> (which has the alias irectangle) contains to ipoints (point<int>) as corner representation. You can access the type T through the public type value_type
.
The second template parameter S is optional and allows the rectangle to behave correctly in a discrete integer grid or in a continuous real grid (please see the cvr::rectangleSide policy for more information).
typedef S cvr::rectangle< T, S >::side_type |
Type used for the side policy.
typedef T cvr::rectangle< T, S >::value_type |
Type used in each coordinate of the two internal points.
cvr::rectangle< T, S >::rectangle | ( | ) |
Default constructor.
The two points ul and br will be initialized with (0,0)
cvr::rectangle< T, S >::rectangle | ( | const point< T > & | ul, | |
const point< T > & | br | |||
) |
Constructor with two points.
ul | upper left corner | |
br | bottom right corner |
cvr::rectangle< T, S >::rectangle | ( | const T & | left, | |
const T & | top, | |||
const T & | right, | |||
const T & | bottom | |||
) |
Construct a rectangle via separate coordinates.
left | left side coordinate | |
top | top side coordinate | |
right | right side coordinate | |
bottom | bottom side coordinate |
cvr::rectangle< T, S >::rectangle | ( | const T & | size | ) |
Construct a square with the given side size.
If the size is even and T is an integer type, the rectangle will be created from -|_size/2_| to size + |_size/2_| in both coordinates x and y.
cvr::rectangle< T, S >::rectangle | ( | const rectangle< U, US > & | other | ) | [inline] |
Copy constructor.
rectangle<T,S>& cvr::rectangle< T, S >::castFrom | ( | const rectangle< U, SU > & | other | ) | [inline] |
Cast from a rectangle of another type.
bool cvr::rectangle< T, S >::contains | ( | const T & | x, | |
const T & | y | |||
) | const [inline] |
Check if the given coordinates are inside this rectangle.
(border included!)
bool cvr::rectangle< T, S >::contains | ( | const point< T > & | p | ) | const [inline] |
Check if point<T> p is inside this rectangle.
(border inclusive!)
rectangle<T,S>& cvr::rectangle< T, S >::copy | ( | const rectangle< T, S > & | other | ) |
Copy member.
void cvr::rectangle< T, S >::ensureConsistency | ( | ) |
Ensure consistency of upper-left and bottom-right corners.
A rectangle<T,S> is called "consistent" if the upper-left point<T> has lower coordinate-values than the bottom-right point<T>.
typeInfo<T>::square_accumulation_type cvr::rectangle< T, S >::getArea | ( | ) | const [inline] |
Get the area of this rectangle.
This value is always positive, regardless of the position of the upper left and bottom right corner. A rectangle whose corners coincide has an area of 1 for fixed point types or 0 for floating point ones.
For floating point values the size is just x2-x1, because of the assumtion that the rectangle lies on a real valued 2D space.
point<T> cvr::rectangle< T, S >::getCenter | ( | ) | const [inline] |
Get center of rectangle<T,S>.
point<T> cvr::rectangle< T, S >::getDimensions | ( | ) | const [inline] |
Get dimensions of rectangle<T,S>.
If one coordinate of the two points coincide and the rectangle contains fixed point typed points, the returned dimension is one. For floating point types this case will return 0.
For floating point values the size is just x2-x1, because of the assumtion that the rectangle lies on a real valued 2D space.
rectangle<T,S>& cvr::rectangle< T, S >::intersect | ( | const rectangle< T, S > & | tRect | ) |
Intersection of this rectangle with tRect.
(the largest rectangle which is contained both inside this rectangle and inside tRect).
The result will be left in this instance. If the rectangles do not intersect, the resul will be inconsistent, so you should call isConsistent() to check for this case unless you know for sure that it cannot occur.
bool cvr::rectangle< T, S >::isClose | ( | const rectangle< T, S > & | tRect, | |
const point< T > & | dist | |||
) | const |
bool cvr::rectangle< T, S >::isConsistent | ( | ) | const [inline] |
Check for consistent rectangle<T,S>.
rectangle<T,S>& cvr::rectangle< T, S >::join | ( | const rectangle< T, S > & | tRect | ) |
bool cvr::rectangle< T, S >::operator!= | ( | const rectangle< T, S > & | other | ) | const [inline] |
Test for inequality.
rectangle<T,S> cvr::rectangle< T, S >::operator& | ( | const rectangle< T, S > & | tRect | ) | [inline] |
rectangle<T,S>& cvr::rectangle< T, S >::operator&= | ( | const rectangle< T, S > & | tRect | ) | [inline] |
This rectangle is set to the intersection of himself with tRect.
(alias for intersect)
rectangle<T,S>& cvr::rectangle< T, S >::operator= | ( | const rectangle< T, S > & | other | ) | [inline] |
Alias for copy.
bool cvr::rectangle< T, S >::operator== | ( | const rectangle< T, S > & | other | ) | const [inline] |
Test for equality.
rectangle<T,S> cvr::rectangle< T, S >::operator| | ( | const rectangle< T, S > & | tRect | ) |
rectangle<T,S>& cvr::rectangle< T, S >::operator|= | ( | const rectangle< T, S > & | tRect | ) | [inline] |
bool cvr::rectangle< T, S >::overlaps | ( | const rectangle< T, S > & | tRect | ) | const |
void cvr::rectangle< T, S >::resize | ( | const T & | x, | |
const T & | y | |||
) |
Resize rectangle<T,S> with new dimensions, but keep its center.
void cvr::rectangle< T, S >::resize | ( | const point< T > & | dim | ) |
Resize rectangle<T,S> with new dimensions, but keep its center.
bool cvr::rectangle< T, S >::set | ( | const point< T > & | ul, | |
const point< T > & | br | |||
) | [inline] |
Set the corners via two points.
You must ensure that the data is consistent, i.e. ul.x < br.x and ul.y < br.y. See setConsistent().
ul | upper left corner | |
br | bottom right corner |
bool cvr::rectangle< T, S >::set | ( | const T & | left, | |
const T & | top, | |||
const T & | right, | |||
const T & | bottom | |||
) | [inline] |
Set the corners via separate coordinates.
You must ensure that the data is consistent, i.e. left < right and top < bottom. See setConsistent().
left | left side coordinate | |
top | top side coordinate | |
right | right side coordinate | |
bottom | bottom side coordinate |
void cvr::rectangle< T, S >::setCenter | ( | point< T > | center | ) |
Set the center of this rectangle.
bool cvr::rectangle< T, S >::setConsistent | ( | const point< T > & | ul, | |
const point< T > & | br | |||
) | [inline] |
Set the corners via two points.
This method ensures consistency of the resulting rectangle, no matter if the given data implies negative sides.
ul | upper left corner | |
br | bottom right corner |
bool cvr::rectangle< T, S >::setConsistent | ( | const T & | left, | |
const T & | top, | |||
const T & | right, | |||
const T & | bottom | |||
) | [inline] |
Set the corners via separate coordinates.
This method ensures consistency of the resulting rectangle, no matter if the given data implies negative sides.
left | left side coordinate | |
top | top side coordinate | |
right | right side coordinate | |
bottom | bottom side coordinate |
void cvr::rectangle< T, S >::shift | ( | const rectangle< T, S > & | other, | |
const point< T > & | delta | |||
) | [inline] |
void cvr::rectangle< T, S >::shift | ( | const point< T > & | delta | ) | [inline] |
Shift rectangle<T,S> by delta.
delta | The shift amount to be added to both corners |
point<T> cvr::rectangle< T, S >::br |
Bottom-right point<T>.
point<T> cvr::rectangle< T, S >::ul |
Upper-left point<T>.