Rectangle. More...
#include <rrect.h>
Public Member Functions | |
RRect (void) | |
RRect (const RRect &rect) | |
RRect (const RPoint &pt1, const RPoint &pt2) | |
RRect (tCoord x1, tCoord y1, tCoord x2, tCoord y2) | |
int | Compare (const RRect &rect) const |
void | Set (const RPoint &pt1, const RPoint &pt2) |
void | Set (tCoord x1, tCoord y1, tCoord x2, tCoord y2) |
RPoint | GetPt1 (void) const |
tCoord | GetX1 (void) const |
tCoord | GetY1 (void) const |
RPoint | GetPt2 (void) const |
tCoord | GetX2 (void) const |
tCoord | GetY2 (void) const |
tCoord | GetWidth (void) const |
tCoord | GetHeight (void) const |
RSize | GetSize (void) const |
void | SetWidth (tCoord width) |
void | SetHeight (tCoord height) |
void | SetShape (tCoord x, tCoord y, tCoord w, tCoord h) |
tCoord | GetArea (void) const |
bool | operator== (const RRect &rect) const |
bool | operator!= (const RRect &rect) const |
void | Translation (const RPoint &pt) |
void | Translation (tCoord x, tCoord y) |
void | SetPos (const RPoint &pt) |
void | SetPos (tCoord x, tCoord y) |
RRect & | operator+= (const RPoint &pt) |
RRect & | operator-= (const RPoint &pt) |
bool | Clip (const RRect &clip) |
bool | Clip (const RPoint &limits) |
bool | Overlap (const RRect &rect) const |
bool | IsIn (const RPoint &pt, bool overlap=true) const |
bool | IsIn (tCoord x, tCoord y, bool overlap=true) const |
bool | IsIn (const RRect &rect, bool overlap=true) const |
RRect & | operator= (const RRect &rect) |
void | ChangeOrientation (const tOrientation o) |
Private Member Functions | |
void | ReOrder (void) |
Private Attributes | |
RPoint | Pt1 |
RPoint | Pt2 |
Detailed Description
Rectangle.
This class implements a rectangle. In practice, Pt1 is always the bottom/left point while Pt2 is always the upper/right point.
Constructor & Destructor Documentation
RRect | ( | void | ) |
Construct a rectangle with two points at (0,0).
Construct a rectangle from another one.
- Parameters
-
rect The rectangle used as reference.
Construct a rectangle with two points.
- Parameters
-
pt1 First point used. pt2 Second point used.
Construct a rectangle from four coordinates.
- Parameters
-
x1 First X-coordinate. y1 First Y-coordinate. x2 Second X-coordinate. y2 Second Y-coordinate.
Member Function Documentation
|
private |
ReOrder de points if necessary to follow the convention.
int Compare | ( | const RRect & | rect | ) | const |
Compare two rectangles. This function is used with the class RContainer.
- Parameters
-
rect Rectangle used for the comparison.
- Returns
- -1 The left-bottom point of the current polygon is more at the left (at the bottom) of the other one. If identical, the second points are compared.
- 0 if there have the points.
- +1 The left-bottom point of the current line is more at the right ( upper) of the other one. If identical, the second points are compared.
Set the coordinates of the rectangle.
- Parameters
-
pt1 First point used. pt2 Second point used.
Set the coordinates of the rectangle.
- Parameters
-
x1 The most left position. y1 The most bottom position x2 The most right position. y2 The most up position.
tCoord GetX1 | ( | void | ) | const |
- Returns
- the left limit.
tCoord GetY1 | ( | void | ) | const |
- Returns
- the bottom limit.
tCoord GetX2 | ( | void | ) | const |
- Returns
- the right limit.
tCoord GetY2 | ( | void | ) | const |
- Returns
- the upper limit.
tCoord GetWidth | ( | void | ) | const |
Return the width of the rectangle. The width includes the border, i.e. a rectangle where X1=X2 has a width of 1.
tCoord GetHeight | ( | void | ) | const |
Return the height of the rectangle. The height includes the border, i.e. a rectangle where Y1=Y2 has a height of 1.
RSize GetSize | ( | void | ) | const |
- Returns
- the size of the rectangle.
void SetWidth | ( | tCoord | width | ) |
Set the width of the rectangle. The method adapts the X-coordinate of Pt2. The width includes the border, i.e. a width of 1 means that X2=X1.
- Parameters
-
width New width.
void SetHeight | ( | tCoord | height | ) |
Set the height of the rectangle. The method adapts the Y-coordinate of Pt2. The height includes the border, i.e. a width of 1 means that Y2=Y1.
- Parameters
-
height New height.
Set the coordinates of the rectangle based on a shape.
- Parameters
-
x The most left position. y The most bottom position w Width. h Height.
tCoord GetArea | ( | void | ) | const |
Return the area of the rectangle.
bool operator== | ( | const RRect & | rect | ) | const |
The equal operator.
bool operator!= | ( | const RRect & | rect | ) | const |
The non-equal operator.
void Translation | ( | const RPoint & | pt | ) |
Make a translation of the rectangle.
- Parameters
-
pt The point representing the vector used.
Make a translation of the rectangle.
- Parameters
-
x The x to add. y The y to add.
void SetPos | ( | const RPoint & | pt | ) |
Put a rectangle at a given position.
- Parameters
-
pt New position.
Put a rectangle at a given position.
- Parameters
-
x X position. y Y position.
Make a translation of the rectangle.
- Parameters
-
pt The point representing the vector used.
Make a minus translation of the rectangle.
- Parameters
-
pt The point representing the vector used.
bool Clip | ( | const RRect & | clip | ) |
Adapt the rectangle to be contained in a given region.
- Parameters
-
clip The region used as reference.
- Returns
- The function returns true if the rectangle was clipped.
bool Clip | ( | const RPoint & | limits | ) |
Adapt the rectangle to be contained in a given region.
- Parameters
-
limits The point representing the right/up limits of the region.
- Returns
- The function returns true if the rectangle was clipped.
bool Overlap | ( | const RRect & | rect | ) | const |
This function returns true if the two rectangles overlapped.
- Parameters
-
rect Reference rectangle.
bool IsIn | ( | const RPoint & | pt, |
bool | overlap = true |
||
) | const |
This function returns true if a given point is in the rectangle.
- Parameters
-
pt Point to analyze. overlap Specify if the point can be on one of the edges. By default, it is true.
This function returns true if a given point is in the rectangle.
- Parameters
-
x X position of the point. y Y position of the point. overlap Specify if the point can be on one of the edges. By default, it is true.
bool IsIn | ( | const RRect & | rect, |
bool | overlap = true |
||
) | const |
This function returns true if a given rect is in the rectangle.
- Parameters
-
rect Rectangle. overlap Specify if the rectangle may overlap, i.e. some of its points are on an edge of the other one. By default, it is true.
void ChangeOrientation | ( | const tOrientation | o | ) |
Modify the rectangle to a certain orientation.
- Parameters
-
o The orientation.
Field Documentation
|
private |
The First point of the line.
|
private |
The second point of the line.