Class Box2
See Also: Class IPoint2, Data Types.
class Box2 : public RECT
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.
Methods:
Prototype:
Box2();
Remarks:
Constructs a Box2 object. The box is initialized such that it is 'empty'. See IsEmpty() below.
Prototype:
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.
Prototype:
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'.
Return Value:
TRUE if the box is empty; FALSE otherwise.
Prototype:
void SetEmpty();
Remarks:
Sets the box to 'empty'. This indicates the box has not had specific values set by the developer.
Prototype:
void Rectify();
Remarks:
Adjusts the coordinates of the box such that top<bottom and left<right.
Prototype:
void Scale(float f);
Remarks:
Scales the coordinates of the box about the center of the box.
Parameters:
float f
Specifies the scale factor.
Prototype:
void Translate(IPoint2 t);
Remarks:
Translate the box by the distance specified.
Parameters:
IPoint2 t
The distance to translate the box.
Prototype:
IPoint2 GetCenter()
Remarks:
Returns the center of the box (the midpoint between the box corners).
Prototype:
int x()
Remarks:
Returns the minimum x coordinate of the box.
Prototype:
int y()
Remarks:
Returns the minimum y coordinate.
Prototype:
int w()
Remarks:
Returns the width of the box.
Prototype:
int h()
Remarks:
Returns the height of the box.
Prototype:
void SetW(int w)
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.
Prototype:
void SetH(int h)
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.
Prototype:
void SetX(int x)
Remarks:
Sets the left coordinate of the box to x.
Parameters:
int x
The new value for the left coordinate.
Prototype:
void SetY(int y)
Remarks:
Set the top coordinate to y.
Parameters:
int y
The new value for the top coordinate.
Prototype:
void SetWH(int w, int h)
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.
Prototype:
void SetXY(int x, int y)
Remarks:
Sets both the left and top coordinates of the box.
Parameters:
int x
The new left coordinate.
int y
The new top coordinate.
Prototype:
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:
Prototype:
Box2& operator=(const RECT& r);
Box2& operator=(RECT& r);
Remarks:
Assignment operators. Copies the specified source RECT into this Box2 object.
Prototype:
Box2& operator+=(const Box2& b);
Remarks:
Expands this Box2 to completely include box b.
Prototype:
Box2& operator+=(const IPoint2& p);
Remarks:
Expands this Box2 to include point p.
Prototype:
int operator==( const Box2& b ) const
Remarks:
Equality operator. Determines whether b is equal to Box2. Returns nonzero if the boxes are equal; 0 otherwise.