Rectangle. More...

#include <rrect.h>

Collaboration diagram for RRect:
[legend]

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)
 
RRectoperator+= (const RPoint &pt)
 
RRectoperator-= (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
 
RRectoperator= (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).

RRect ( const RRect rect)

Construct a rectangle from another one.

Parameters
rectThe rectangle used as reference.
RRect ( const RPoint pt1,
const RPoint pt2 
)

Construct a rectangle with two points.

Parameters
pt1First point used.
pt2Second point used.
RRect ( tCoord  x1,
tCoord  y1,
tCoord  x2,
tCoord  y2 
)

Construct a rectangle from four coordinates.

Parameters
x1First X-coordinate.
y1First Y-coordinate.
x2Second X-coordinate.
y2Second Y-coordinate.

Member Function Documentation

void ReOrder ( void  )
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
rectRectangle 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.
void Set ( const RPoint pt1,
const RPoint pt2 
)

Set the coordinates of the rectangle.

Parameters
pt1First point used.
pt2Second point used.
void Set ( tCoord  x1,
tCoord  y1,
tCoord  x2,
tCoord  y2 
)

Set the coordinates of the rectangle.

Parameters
x1The most left position.
y1The most bottom position
x2The most right position.
y2The most up position.
RPoint GetPt1 ( void  ) const

Get the (bottom,left) point.

Returns
RPoint
tCoord GetX1 ( void  ) const
Returns
the left limit.
tCoord GetY1 ( void  ) const
Returns
the bottom limit.
RPoint GetPt2 ( void  ) const

Get the (upper,right) point.

Returns
RPoint
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
widthNew 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
heightNew height.
void SetShape ( tCoord  x,
tCoord  y,
tCoord  w,
tCoord  h 
)

Set the coordinates of the rectangle based on a shape.

Parameters
xThe most left position.
yThe most bottom position
wWidth.
hHeight.
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
ptThe point representing the vector used.
void Translation ( tCoord  x,
tCoord  y 
)

Make a translation of the rectangle.

Parameters
xThe x to add.
yThe y to add.
void SetPos ( const RPoint pt)

Put a rectangle at a given position.

Parameters
ptNew position.
void SetPos ( tCoord  x,
tCoord  y 
)

Put a rectangle at a given position.

Parameters
xX position.
yY position.
RRect& operator+= ( const RPoint pt)

Make a translation of the rectangle.

Parameters
ptThe point representing the vector used.
RRect& operator-= ( const RPoint pt)

Make a minus translation of the rectangle.

Parameters
ptThe point representing the vector used.
bool Clip ( const RRect clip)

Adapt the rectangle to be contained in a given region.

Parameters
clipThe 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
limitsThe 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
rectReference rectangle.
bool IsIn ( const RPoint pt,
bool  overlap = true 
) const

This function returns true if a given point is in the rectangle.

Parameters
ptPoint to analyze.
overlapSpecify if the point can be on one of the edges. By default, it is true.
bool IsIn ( tCoord  x,
tCoord  y,
bool  overlap = true 
) const

This function returns true if a given point is in the rectangle.

Parameters
xX position of the point.
yY position of the point.
overlapSpecify 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
rectRectangle.
overlapSpecify if the rectangle may overlap, i.e. some of its points are on an edge of the other one. By default, it is true.
RRect& operator= ( const RRect rect)

The assign Operator.

void ChangeOrientation ( const tOrientation  o)

Modify the rectangle to a certain orientation.

Parameters
oThe orientation.

Field Documentation

RPoint Pt1
private

The First point of the line.

RPoint Pt2
private

The second point of the line.