Box2 Class Reference

#include <box2.h>

Class Description

See also
Class IPoint2.

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.
+ Inheritance diagram for Box2:

Public Member Functions

 Box2 ()
 
 Box2 (const IPoint2 &a, const IPoint2 &b)
 
int IsEmpty ()
 
void SetEmpty ()
 
void Rectify ()
 
void Scale (float f)
 
void Translate (IPoint2 t)
 
IPoint2 GetCenter () const
 
int x () const
 
int y () const
 
int w () const
 
int h () const
 
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)
 
Box2operator= (const RECT &r)
 
Box2operator= (RECT &r)
 
Box2operator+= (const Box2 &b)
 
Box2operator+= (const IPoint2 &p)
 
int operator== (const Box2 &b) const
 
bool operator!= (const Box2 &b) const
 
int Contains (const IPoint2 &p) const
 
bool IntersectsLine (int x0, int y0, int x1, int y1) const
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Constructor & Destructor Documentation

Box2 ( )
Remarks
Constructs a Box2 object. The box is initialized such that it is 'empty'. See IsEmpty() below.
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

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.
void SetEmpty ( )
Remarks
Sets the box to 'empty'. This indicates the box has not had specific values set by the developer.
void Rectify ( )
Remarks
Adjusts the coordinates of the box such that top<bottom and left<right.
void Scale ( float  f)
Remarks
Scales the coordinates of the box about the center of the box.
Parameters:
float f

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

The distance to translate the box.
IPoint2 GetCenter ( ) const
inline
Remarks
Returns the center of the box (the midpoint between the box corners).
67 { return IPoint2((left+right)/2, (top+bottom)/2); }
Definition: ipoint2.h:32
int x ( ) const
inline
Remarks
Returns the minimum x coordinate of the box.
69 { return ((left < right) ? left : right); }
int y ( ) const
inline
Remarks
Returns the minimum y coordinate.
71 { return ((top < bottom) ? top : bottom); }
int w ( ) const
inline
Remarks
Returns the width of the box.
73 { return abs(right-left)+1; }
int h ( ) const
inline
Remarks
Returns the height of the box.
75 { 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.
83 { right = left + w -1; }
int w() const
Definition: box2.h:73
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.
90 { bottom = top + h -1; }
int h() const
Definition: box2.h:75
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.
95 { left = x; }
int x() const
Definition: box2.h:69
void SetY ( int  y)
inline
Remarks
Set the top coordinate to y.
Parameters:
int y

The new value for the top coordinate.
100 { top = y; }
int y() const
Definition: box2.h:71
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.
107 { SetW(w); SetH(h); }
void SetH(int h)
Definition: box2.h:90
int w() const
Definition: box2.h:73
int h() const
Definition: box2.h:75
void SetW(int w)
Definition: box2.h:83
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.
114 { SetX(x); SetY(y); }
void SetY(int y)
Definition: box2.h:100
void SetX(int x)
Definition: box2.h:95
int x() const
Definition: box2.h:69
int y() const
Definition: box2.h:71
Box2& operator= ( const RECT &  r)
Remarks
Assignment operators. Copies the specified source RECT into this Box2 object.
Box2& operator= ( RECT &  r)
Remarks
Assignment operators. Copies the specified source RECT into this Box2 object.
Box2& operator+= ( const Box2 b)
Remarks
Expands this Box2 to completely include box b.
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.
129 { return (left==b.left && right==b.right && top==b.top && bottom==b.bottom); }
bool operator!= ( const Box2 b) const
inline
Remarks
Inequality operator. Determines whether b is different from Box2. Returns true iff the boxes are different.
132 { return !(operator==(b)); }
int operator==(const Box2 &b) const
Definition: box2.h:129
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:
bool IntersectsLine ( int  x0,
int  y0,
int  x1,
int  y1 
) const
Remarks
Intersection test between a line and a rectangle. Returns true if they intersecting.
Parameters:
int x0

Line start x coordinate.

int y0

Line start y coordinate. int x1

Line end x coordinate.

int y1

Line end y coordinate.