3ds Max C++ API Reference
Box2 Class Reference

#include <box2.h>

+ Inheritance diagram for Box2:

Public Member Functions

 Box2 ()
 
 Box2 (const IPoint2 &a, const IPoint2 &b)
 
bool 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)
 
bool operator== (const Box2 &b) const
 
bool operator!= (const Box2 &b) const
 
bool 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...
 

Detailed 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.

Constructor & Destructor Documentation

◆ Box2() [1/2]

Box2 ( )
Remarks
Constructs a Box2 object. The box is initialized such that it is 'empty'. See IsEmpty() below.

◆ Box2() [2/2]

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

◆ IsEmpty()

bool 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.

◆ SetEmpty()

void SetEmpty ( )
Remarks
Sets the box to 'empty'. This indicates the box has not had specific values set by the developer.

◆ Rectify()

void Rectify ( )
Remarks
Adjusts the coordinates of the box such that top<bottom and left<right.

◆ Scale()

void Scale ( float  f)
Remarks
Scales the coordinates of the box about the center of the box.
Parameters:
float f

Specifies the scale factor.

◆ Translate()

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

The distance to translate the box.

◆ GetCenter()

IPoint2 GetCenter ( ) const
inline
Remarks
Returns the center of the box (the midpoint between the box corners).
71  {
72  return IPoint2((left + right) / 2, (top + bottom) / 2);
73  }
Definition: ipoint2.h:33

◆ x()

int x ( ) const
inline
Remarks
Returns the minimum x coordinate of the box.
76  {
77  return ((left < right) ? left : right);
78  }

◆ y()

int y ( ) const
inline
Remarks
Returns the minimum y coordinate.
81  {
82  return ((top < bottom) ? top : bottom);
83  }

◆ w()

int w ( ) const
inline
Remarks
Returns the width of the box.
86  {
87  return abs(right - left) + 1;
88  }

◆ h()

int h ( ) const
inline
Remarks
Returns the height of the box.
91  {
92  return abs(bottom - top) + 1;
93  }

◆ SetW()

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.
102  {
103  right = left + w - 1;
104  }
int w() const
Definition: box2.h:85

◆ SetH()

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.
112  {
113  bottom = top + h - 1;
114  }
int h() const
Definition: box2.h:90

◆ SetX()

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.
120  {
121  left = x;
122  }
int x() const
Definition: box2.h:75

◆ SetY()

void SetY ( int  y)
inline
Remarks
Set the top coordinate to y.
Parameters:
int y

The new value for the top coordinate.
128  {
129  top = y;
130  }
int y() const
Definition: box2.h:80

◆ SetWH()

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.
138  {
139  SetW(w);
140  SetH(h);
141  }
void SetH(int h)
Definition: box2.h:111
void SetW(int w)
Definition: box2.h:101

◆ SetXY()

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.
149  {
150  SetX(x);
151  SetY(y);
152  }
void SetY(int y)
Definition: box2.h:127
void SetX(int x)
Definition: box2.h:119

◆ operator=() [1/2]

Box2& operator= ( const RECT &  r)
Remarks
Assignment operators. Copies the specified source RECT into this Box2 object.

◆ operator=() [2/2]

Box2& operator= ( RECT &  r)
Remarks
Assignment operators. Copies the specified source RECT into this Box2 object.

◆ operator+=() [1/2]

Box2& operator+= ( const Box2 b)
Remarks
Expands this Box2 to completely include box b.

◆ operator+=() [2/2]

Box2& operator+= ( const IPoint2 p)
Remarks
Expands this Box2 to include point p.

◆ operator==()

bool operator== ( const Box2 b) const
inline
Remarks
Equality operator. Determines whether b is equal to this box. Returns true if the boxes are equal; false otherwise.
168  {
169  return (left == b.left && right == b.right && top == b.top && bottom == b.bottom);
170  }

◆ operator!=()

bool operator!= ( const Box2 b) const
inline
Remarks
Inequality operator. Determines whether b is different from this box. Returns true if the boxes are different.
174  {
175  return !(operator==(b));
176  }
bool operator==(const Box2 &b) const
Definition: box2.h:167

◆ Contains()

bool Contains ( const IPoint2 p) const
Remarks
Determines if the point passed is contained within the box. Returns true if the point is inside the box; otherwise false.

◆ IntersectsLine()

bool IntersectsLine ( int  x0,
int  y0,
int  x1,
int  y1 
) const
Remarks
Intersection test between a line and a rectangle. Returns true if they intersect.
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.