Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgl::FGRect Struct Reference

#include <base.h>

Inheritance diagram for fgl::FGRect:

Inheritance graph
[legend]
Collaboration diagram for fgl::FGRect:

Collaboration graph
[legend]
List of all members.

Detailed Description

The FGRect class defines a rectangle in the plane.

A rectangle is internally represented as an upper-left corner and a bottom-right corner, but it is normally expressed as an upper-left corner and a size.

The coordinate type is FGCOORD (defined in qwindowdefs.h as int). The minimum value of FGCOORD is FGCOORD_MIN (-2147483648) and the maximum value is FGCOORD_MAX (2147483647).

Note that the size (width and height) of a rectangle might be different from what you are used to. If the top-left corner and the bottom-right corner are the same, the height and the width of the rectangle will both be 1.

Generally, @ e{width = right - left + 1} and {height = bottom - top + 1}. We designed it this way to make it correspond to rectangular spaces used by drawing functions in which the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.

The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.

A FGRect can be constructed with a set of left, top, width and height integers, from two FGPoints or from a FGPoint and a FGSize. After creation the dimensions can be changed, e.g. with setLeft(), setRight(), setTop() and setBottom(), or by setting sizes, e.g. setWidth(), setHeight() and setSize(). The dimensions can also be changed with the move functions, e.g. moveBy(), moveCenter(), moveBottomRight(), etc. You can also add coordinates to a rectangle with addCoords().

You can test to see if a FGRect contains a specific point with contains(). You can also test to see if two FGRects intersect with intersects() (see also intersect()). To get the bounding rectangle of two FGRects use unite().

See also:
FGPoint
Examples:

gradient.cpp, and regress.cpp.


Public Member Functions

 FGRect ()
 FGRect (const FGRect &old)
 FGRect (int xpos, int ypos, int width, int height)
 FGRect (int width, int height)
 FGRect (const FGPoint r0, const FGPoint r1)
 FGRect (const FGSize &sz)
 FGRect (const FGCircle &c)
 FGRect (const FGDrawBuffer &sprite)
bool isValid (void) const
bool isNull (void) const
bool isEmpty (void) const
FGRect normalize (void) const
FGCOORD left (void) const
FGCOORD right (void) const
FGCOORD top (void) const
FGCOORD bottom (void) const
FGPoint topLeft (void) const
FGPoint bottomRight (void) const
FGPoint topRight (void) const
FGPoint bottomLeft (void) const
FGPoint center (void) const
FGRect operator| (const FGRect &r) const
FGRect operator & (const FGRect &r) const
FGRectoperator|= (const FGRect &r)
FGRectoperator &= (const FGRect &r)
bool contains (const FGPoint &p, bool proper=false) const
bool contains (int x, int y, bool proper=false) const
bool contains (const FGRect &r, bool proper=false) const
FGRect unite (const FGRect &r) const
FGRect intersect (const FGRect &r) const
bool intersects (const FGRect &r) const

Public Attributes

FGCOORD w
FGCOORD h

Friends

bool operator== (const FGRect &, const FGRect &)
bool operator!= (const FGRect &, const FGRect &)


Constructor & Destructor Documentation

fgl::FGRect::FGRect  )  [inline]
 

Constructs an invalid rectangle.

fgl::FGRect::FGRect const FGRect old  )  [inline]
 

copy

fgl::FGRect::FGRect int  xpos,
int  ypos,
int  width,
int  height
[inline]
 

Constructs a rectangle with the top, left corner and width and height.

Example (creates two identical rectangles):

        FGRect r1( FGPoint(100,200), FGPoint(110,215) );
        FGRect r2( 100, 200, 11, 16 );

fgl::FGRect::FGRect int  width,
int  height
[inline]
 

Constructs a rectangle with the top left corner at (0,0) and width and height.

fgl::FGRect::FGRect const FGPoint  r0,
const FGPoint  r1
[inline]
 

Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.

fgl::FGRect::FGRect const FGSize sz  )  [inline]
 

Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.

fgl::FGRect::FGRect const FGCircle c  )  [inline]
 

Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.


Member Function Documentation

FGCOORD fgl::FGRect::bottom void   )  const [inline]
 

Returns the bottom coordinate of the rectangle.

See also:
setBottom(), top(), bottomLeft(), bottomRight()

FGPoint fgl::FGRect::bottomLeft void   )  const [inline]
 

Returns the bottom-left position of the rectangle.

See also:
setBottomLeft(), moveBottomLeft(), topRight(), bottom(), left()

FGPoint fgl::FGRect::bottomRight void   )  const [inline]
 

Returns the bottom-right position of the rectangle.

See also:
setBottomRight(), moveBottomRight(), topLeft(), right(), bottom()

FGPoint fgl::FGRect::center void   )  const [inline]
 

Returns the center point of the rectangle.

See also:
moveCenter(), topLeft(), bottomRight(), topRight(), bottomLeft()

bool fgl::FGRect::contains const FGRect r,
bool  proper = false
const
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns TRUE if the rectangle r is inside this rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if r is entirely inside (not on the edge).

See also:
unite(), intersect(), intersects()

bool fgl::FGRect::contains int  x,
int  y,
bool  proper = false
const
 

Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if the point is entirely inside (not on the edge).

bool fgl::FGRect::contains const FGPoint p,
bool  proper = false
const
 

Returns TRUE if the point p is inside or on the edge of the rectangle; otherwise returns FALSE.

If proper is TRUE, this function returns TRUE only if p is inside (not on the edge).

FGRect fgl::FGRect::intersect const FGRect r  )  const
 

Returns the intersection of this rectangle and rectangle r. {r.intersect(s)} is equivalent to {r&s}.

bool fgl::FGRect::intersects const FGRect r  )  const [inline]
 

Returns TRUE if this rectangle intersects with rectangle r (there is at least one pixel that is within both rectangles); otherwise returns FALSE.

See also:
intersect(), contains()

bool fgl::FGRect::isEmpty void   )  const [inline]
 

Returns TRUE if the rectangle is empty; otherwise returns FALSE.

An empty rectangle has a left() > right() or top() > bottom().

An empty rectangle is not valid. {isEmpty() == !isValid()}

See also:
isNull(), isValid(), normalize()

bool fgl::FGRect::isNull void   )  const [inline]
 

Returns TRUE if the rectangle is a null rectangle; otherwise returns FALSE.

A null rectangle has both the width and the height set to 0, that is right() == left() - 1 and bottom() == top() - 1.

Note that if right() == left() and bottom() == top(), then the rectangle has width 1 and height 1.

A null rectangle is also empty.

A null rectangle is not valid.

See also:
isEmpty(), isValid()

Reimplemented from fgl::FGPoint.

bool fgl::FGRect::isValid void   )  const [inline]
 

Returns TRUE if the rectangle is valid; otherwise returns FALSE.

A valid rectangle has a left() <= right() and top() <= bottom().

Note that non-trivial operations like intersections are not defined for invalid rectangles.

{isValid() == !isEmpty()}

See also:
isNull(), isEmpty(), normalize()

FGCOORD fgl::FGRect::left void   )  const [inline]
 

Returns the left coordinate of the rectangle. Identical to x().

See also:
setLeft(), right(), topLeft(), bottomLeft()

FGRect fgl::FGRect::normalize void   )  const [inline]
 

Returns a normalized rectangle, i.e. a rectangle that has a non-negative width and height.

It swaps left and right if left() > right(), and swaps top and bottom if top() > bottom().

See also:
isValid()

FGRect fgl::FGRect::operator & const FGRect r  )  const
 

Returns the intersection of this rectangle and rectangle r.

Returns an empty rectangle if there is no intersection.

See also:
operator&=(), operator|(), isEmpty(), intersects(), contains()

FGRect & fgl::FGRect::operator &= const FGRect r  ) 
 

Intersects this rectangle with rectangle r.

FGRect fgl::FGRect::operator| const FGRect r  )  const
 

Returns the bounding rectangle of this rectangle and rectangle r.

The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.

See also:
operator|=(), operator&(), intersects(), contains()

FGRect & fgl::FGRect::operator|= const FGRect r  ) 
 

Unites this rectangle with rectangle r.

FGCOORD fgl::FGRect::right void   )  const [inline]
 

Returns the right coordinate of the rectangle.

See also:
setRight(), left(), topRight(), bottomRight()

FGCOORD fgl::FGRect::top void   )  const [inline]
 

Returns the top coordinate of the rectangle. Identical to y().

See also:
setTop(), bottom(), topLeft(), topRight()

FGPoint fgl::FGRect::topLeft void   )  const [inline]
 

Returns the top-left position of the rectangle.

See also:
setTopLeft(), moveTopLeft(), bottomRight(), left(), top()

FGPoint fgl::FGRect::topRight void   )  const [inline]
 

See also:
setTopRight(), moveTopRight(), bottomLeft(), top(), right()

FGRect fgl::FGRect::unite const FGRect r  )  const
 

Returns the bounding rectangle of this rectangle and rectangle r. {r.unite(s)} is equivalent to {r|s}.


Friends And Related Function Documentation

bool operator!= const FGRect ,
const FGRect
[friend]
 

Returns:
TRUE if r1 and r2 are different; otherwise returns FALSE.

bool operator== const FGRect ,
const FGRect
[friend]
 

Returns:
TRUE if r1 and r2 are equal; otherwise returns FALSE.


Generated on Wed Feb 9 11:31:38 2005 for OpenGUI by  doxygen 1.4.0