Public Member Functions

Box2 Class Reference

Search for all occurrences

Detailed Description

See also:
Class IPoint2, Data Types.

Description:
This class describes a 2D rectangular region using integer coordinates. This class is sub-classed from RECT (from the Windows API). Box2 provides methods that return individual coordinates of the box, scale and translate it, retrieve its center, modify its size, expand it to include points or other boxes, and determine if points are inside the box. All methods are implemented by the system.

#include <box2.h>

Inheritance diagram for Box2:
Inheritance graph
[legend]

List of all members.

Public Member Functions

GEOMEXPORT  Box2 ()
GEOMEXPORT  Box2 (const IPoint2 a, const IPoint2 b)
GEOMEXPORT int  IsEmpty ()
GEOMEXPORT void  SetEmpty ()
GEOMEXPORT void  Rectify ()
GEOMEXPORT void  Scale (float f)
GEOMEXPORT void  Translate (IPoint2 t)
IPoint2  GetCenter ()
int  x ()
int  y ()
int  w ()
int  h ()
void  SetW (int w)
void  SetH (int h)
void  SetX (int x)
void  SetY (int y)
void  SetWH (int w, int h)
void  SetXY (int x, int y)
GEOMEXPORT Box2 operator= (const RECT &r)
GEOMEXPORT Box2 operator= (RECT &r)
GEOMEXPORT Box2 operator+= (const Box2 &b)
GEOMEXPORT Box2 operator+= (const IPoint2 &p)
int  operator== (const Box2 &b) const
GEOMEXPORT int  Contains (const IPoint2 &p) const

Constructor & Destructor Documentation

GEOMEXPORT Box2 ( )
Remarks:
Constructs a Box2 object. The box is initialized such that it is 'empty'. See IsEmpty() below.
GEOMEXPORT Box2 ( const IPoint2  a,
const IPoint2  b 
)
Remarks:
Constructs a Box2 object from the specified corners.
Parameters:
const IPoint2 a

The upper left corner of the box.

const IPoint2 b

The lower right corner of the box.

Member Function Documentation

GEOMEXPORT int IsEmpty ( )
Remarks:
Determines whether the box has been 'Set Empty' (see below). When a box is created using the default constructor it is set to 'empty'.
Returns:
TRUE if the box is empty; FALSE otherwise.
GEOMEXPORT void SetEmpty ( )
Remarks:
Sets the box to 'empty'. This indicates the box has not had specific values set by the developer.
GEOMEXPORT void Rectify ( )
Remarks:
Adjusts the coordinates of the box such that top<bottom and left<right.
GEOMEXPORT void Scale ( float  f )
Remarks:
Scales the coordinates of the box about the center of the box.
Parameters:
float f

Specifies the scale factor.
GEOMEXPORT void Translate ( IPoint2  t )
Remarks:
Translate the box by the distance specified.
Parameters:
IPoint2 t

The distance to translate the box.
IPoint2 GetCenter ( ) [inline]
Remarks:
Returns the center of the box (the midpoint between the box corners).
{ return IPoint2((left+right)/2, (top+bottom)/2); }
int x ( ) [inline]
Remarks:
Returns the minimum x coordinate of the box.
{ return min(left,right); }
int y ( ) [inline]
Remarks:
Returns the minimum y coordinate.
{ return min(top,bottom); }
int w ( ) [inline]
Remarks:
Returns the width of the box.
{ return abs(right-left)+1; }
int h ( ) [inline]
Remarks:
Returns the height of the box.
{ return abs(bottom-top)+1; }
void SetW ( int  w ) [inline]
Remarks:
Sets the box width to the width specified. The 'right' coordinate is adjusted such that:

right = left + w -1
Parameters:
int w

The new width for the box.
{ right = left + w -1; } 
void SetH ( int  h ) [inline]
Remarks:
Sets the height of the box to the height specified. The 'bottom' coordinate is adjusted such that:

bottom = top + h -1;
Parameters:
int h

The new height for the box.
{ bottom = top + h -1; } 
void SetX ( int  x ) [inline]
Remarks:
Sets the left coordinate of the box to x.
Parameters:
int x

The new value for the left coordinate.
{ left = x; }
void SetY ( int  y ) [inline]
Remarks:
Set the top coordinate to y.
Parameters:
int y

The new value for the top coordinate.
{ top = y; }
void SetWH ( int  w,
int  h 
) [inline]
Remarks:
Sets both the width and height of the box.
Parameters:
int w

The new width for the box.

int h

The new height of the box.
{ SetW(w); SetH(h); }
void SetXY ( int  x,
int  y 
) [inline]
Remarks:
Sets both the left and top coordinates of the box.
Parameters:
int x

The new left coordinate.

int y

The new top coordinate.
{ SetX(x); SetY(y); }
GEOMEXPORT Box2& operator= ( const RECT &  r )
Remarks:
Assignment operators. Copies the specified source RECT into this Box2 object.
GEOMEXPORT Box2& operator= ( RECT &  r )
Remarks:
Assignment operators. Copies the specified source RECT into this Box2 object.
GEOMEXPORT Box2& operator+= ( const Box2 b )
Remarks:
Expands this Box2 to completely include box b.
GEOMEXPORT Box2& operator+= ( const IPoint2 p )
Remarks:
Expands this Box2 to include point p.
int operator== ( const Box2 b ) const [inline]
Remarks:
Equality operator. Determines whether b is equal to Box2. Returns nonzero if the boxes are equal; 0 otherwise.
{   return (left==b.left && right==b.right && top==b.top && bottom==b.bottom); }
GEOMEXPORT int Contains ( const IPoint2 p ) const
Remarks:
Determines if the point passed is contained within the box. Returns nonzero if the point is inside the box; otherwise 0.
Operators:

Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2
Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2 Box2