3ds Max C++ API Reference
Loading...
Searching...
No Matches
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
 

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).
69 {
70 return IPoint2((left + right) / 2, (top + bottom) / 2);
71 }
Definition: ipoint2.h:30

◆ x()

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

◆ y()

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

◆ w()

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

◆ h()

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

◆ 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.
100 {
101 right = left + w - 1;
102 }
int w() const
Definition: box2.h:83

◆ 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.
110 {
111 bottom = top + h - 1;
112 }
int h() const
Definition: box2.h:88

◆ 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.
118 {
119 left = x;
120 }
int x() const
Definition: box2.h:73

◆ SetY()

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

The new value for the top coordinate.
126 {
127 top = y;
128 }
int y() const
Definition: box2.h:78

◆ 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.
136 {
137 SetW(w);
138 SetH(h);
139 }
void SetH(int h)
Definition: box2.h:109
void SetW(int w)
Definition: box2.h:99

◆ 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.
147 {
148 SetX(x);
149 SetY(y);
150 }
void SetY(int y)
Definition: box2.h:125
void SetX(int x)
Definition: box2.h:117

◆ 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.
166 {
167 return (left == b.left && right == b.right && top == b.top && bottom == b.bottom);
168 }
float float b
Definition: texutil.h:51

◆ 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.
172 {
173 return !(operator==(b));
174 }
bool operator==(const Box2 &b) const
Definition: box2.h:165

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