csRect Class Reference
[Geometry utilities]
Rectangle class: simple class for manipulating 2D rectangles.
More...
#include <csgeom/csrect.h>
Public Member Functions | |
void | AddAdjacent (const csRect &rect) |
Adds an adjacent rectangle if resulting rectangle will have a larger area. | |
void | AddAdjanced (const csRect &rect) |
int | Area () const |
Return area of this rectangle. | |
bool | ClipLine (int &x1, int &y1, int &x2, int &y2) |
Clip a line to make it fit to this rectangle. | |
bool | ClipLineGeneral (int &x1, int &y1, int &x2, int &y2) |
This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines). | |
bool | ClipLineSafe (int &x1, int &y1, int &x2, int &y2) |
Clip a line to make it fit to this rectangle. | |
bool | Contains (int x, int y) const |
Return true if a point lies within rectangle bounds. | |
bool | ContainsRel (int x, int y) const |
Return true if a relative point lies within rectangle bounds. | |
csRect (const csRect ©) | |
Copy constructor. | |
csRect (int ixmin, int iymin, int ixmax, int iymax) | |
Create a new rectangle. | |
csRect () | |
Create a empty rectangle. | |
bool | Equal (const csRect &other) const |
Same but compare with another csRect. | |
bool | Equal (int ixmin, int iymin, int ixmax, int iymax) const |
Return true if rectangle is the same. | |
void | Exclude (const csRect &other) |
Same but works on a csRect argument. | |
void | Exclude (int ixmin, int iymin, int ixmax, int iymax) |
Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle. | |
void | Extend (int x, int y) |
Extend rectangle so that it will include given point. | |
int | Height () const |
Return the height of rectangle. | |
void | Inset (int n) |
Contracts the whole rect by n units. | |
void | Intersect (const csRect &other) |
Intersect with another rectangle. | |
void | Intersect (int ixmin, int iymin, int ixmax, int iymax) |
Intersect with another rectangle. | |
bool | Intersects (const csRect &target) const |
Return true if rectangle intersects with target. | |
bool | IsEmpty () const |
Return true if rectangle is empty. | |
void | Join (const csRect &rect) |
Joins two rects by their minimum and maximum bounds. | |
void | MakeEmpty () |
Make rectangle empty. | |
void | Move (int dX, int dY) |
Move rectangle by deltaX, deltaY. | |
void | Normalize () |
Normalize a rectangle such that xmin <= xmax and ymin <= ymax. | |
bool | operator!= (const csRect &rect) const |
Test inequality of two rectangles. | |
bool | operator== (const csRect &rect) const |
Test equality of two rectangles. | |
void | Outset (int n) |
Expands the whole rect by n units. | |
void | Set (const csRect &target) |
Copy rectangle. | |
void | Set (int ixmin, int iymin, int ixmax, int iymax) |
Set rectangle to given ixmin,iymin,ixmax,iymax position. | |
void | SetPos (int x, int y) |
Set rectangle xmin,ymin position. | |
void | SetSize (int w, int h) |
Set rectangle size. | |
void | Subtract (const csRect &rect) |
Alternative subtraction: find maximal area of this rectangle that is not covered by argument. | |
void | Union (const csRect &other) |
Add a rectangle: find minimal rectangle that embeds both given rectangles. | |
void | Union (int ixmin, int iymin, int ixmax, int iymax) |
Add a rectangle: find minimal rectangle that embeds both given rectangles. | |
int | Width () const |
Return the width of rectangle. | |
virtual | ~csRect () |
Destructor. | |
Public Attributes | |
int | xmax |
int | xmin |
Rectangle bounds. | |
int | ymax |
int | ymin |
Detailed Description
Rectangle class: simple class for manipulating 2D rectangles.This class is somewhat similar to Box, but uses integer coordinates.
Example of a rectangle (xmin = 0, ymin = 0, xmax = 3, ymax = 2):
0 1 2 3 4 ... | | | | | | 0 --@@@@@--+--+-- @//|//|//@ | | 1 --@--+--+--@--+--+-- @//|//|//@ | | 2 --@@@@@--+--+-- | | | | | | 3 --+--+--+--+--+--+-- | | | | | | ...--+--+--+--+--+--+--Vertical line 'X=3' and horizontal line 'Y=2' does NOT belong to the rectangle.
Definition at line 53 of file csrect.h.
Constructor & Destructor Documentation
csRect::csRect | ( | ) |
Create a empty rectangle.
csRect::csRect | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) |
Create a new rectangle.
csRect::csRect | ( | const csRect & | copy | ) |
Copy constructor.
virtual csRect::~csRect | ( | ) | [virtual] |
Destructor.
Member Function Documentation
void csRect::AddAdjacent | ( | const csRect & | rect | ) |
Adds an adjacent rectangle if resulting rectangle will have a larger area.
void csRect::AddAdjanced | ( | const csRect & | rect | ) | [inline] |
int csRect::Area | ( | ) | const [inline] |
bool csRect::ClipLine | ( | int & | x1, | |
int & | y1, | |||
int & | x2, | |||
int & | y2 | |||
) |
Clip a line to make it fit to this rectangle.
This algorithm is inclusive (the clipped line will touch the borders). If this function returns false the line is fully outside the rectangle. Note: this function is only guaranteed to work correctly if the lines are not longer than an integer that fits in 16 bits.
bool csRect::ClipLineGeneral | ( | int & | x1, | |
int & | y1, | |||
int & | x2, | |||
int & | y2 | |||
) |
This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines).
It also doesn't check if the line is fully outside the box. Note: this function is only guaranteed to work correctly if the lines are not longer than an integer that fits in 16 bits.
bool csRect::ClipLineSafe | ( | int & | x1, | |
int & | y1, | |||
int & | x2, | |||
int & | y2 | |||
) |
Clip a line to make it fit to this rectangle.
This algorithm is inclusive (the clipped line will touch the borders). If this function returns false the line is fully outside the rectangle. Note: this function is guaranteed to work correctly even if the integer coordinates of the line are very big.
bool csRect::Contains | ( | int | x, | |
int | y | |||
) | const [inline] |
bool csRect::ContainsRel | ( | int | x, | |
int | y | |||
) | const [inline] |
bool csRect::Equal | ( | const csRect & | other | ) | const [inline] |
bool csRect::Equal | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) | const [inline] |
void csRect::Exclude | ( | const csRect & | other | ) | [inline] |
void csRect::Exclude | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) |
Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle.
If rectangle is fully covered by argument, it becomes empty.
void csRect::Extend | ( | int | x, | |
int | y | |||
) | [inline] |
int csRect::Height | ( | ) | const [inline] |
void csRect::Inset | ( | int | n | ) |
Contracts the whole rect by n units.
void csRect::Intersect | ( | const csRect & | other | ) | [inline] |
void csRect::Intersect | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) |
Intersect with another rectangle.
bool csRect::Intersects | ( | const csRect & | target | ) | const |
Return true if rectangle intersects with target.
bool csRect::IsEmpty | ( | ) | const [inline] |
void csRect::Join | ( | const csRect & | rect | ) |
Joins two rects by their minimum and maximum bounds.
void csRect::Move | ( | int | dX, | |
int | dY | |||
) | [inline] |
void csRect::Normalize | ( | ) | [inline] |
bool csRect::operator!= | ( | const csRect & | rect | ) | const [inline] |
bool csRect::operator== | ( | const csRect & | rect | ) | const [inline] |
void csRect::Outset | ( | int | n | ) |
Expands the whole rect by n units.
void csRect::Set | ( | const csRect & | target | ) | [inline] |
void csRect::Set | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) | [inline] |
void csRect::SetPos | ( | int | x, | |
int | y | |||
) | [inline] |
void csRect::SetSize | ( | int | w, | |
int | h | |||
) | [inline] |
void csRect::Subtract | ( | const csRect & | rect | ) |
Alternative subtraction: find maximal area of this rectangle that is not covered by argument.
void csRect::Union | ( | const csRect & | other | ) | [inline] |
void csRect::Union | ( | int | ixmin, | |
int | iymin, | |||
int | ixmax, | |||
int | iymax | |||
) |
Add a rectangle: find minimal rectangle that embeds both given rectangles.
int csRect::Width | ( | ) | const [inline] |
Member Data Documentation
int csRect::xmin |
The documentation for this class was generated from the following file:
- csgeom/csrect.h
Generated for Crystal Space by doxygen 1.4.7