The Box2 class describes a 2D rectangular region using integer coordinates. The Box2 class provides methods that return individual coordinates of the box, scale and translate it, retrieve its center, modify its size, and determine if points are inside the box. Box2 values are primarily used in the viewport graphics methods described in Viewport Drawing Methods.
Constructors
Box2 <x_integer> <y_integer> <w_integer> <h_integer>
Constructs a Box2 with the upper left corner at \[x,y\]
with width w
and height h
.
Box2 <upperleft_point2> <lowerRight_point2>
Constructs a Box2 object from the specified corners.
Example
upperLeft = [0, 0]
width = 60
height = 30
mybox1 = Box2 upperLeft.x upperLeft.y width height
upperLeft = [0, 0]
lowerRight = [59, 29]
mybox2 = Box2 upperLeft lowerRight
This will result in a box that looks like:
Properties
<Box2>.x: Integer
<Box2>.y: Integer
<Box2>.w: Integer
<Box2>.h: Integer
<Box2>.left: Integer, alias of x property
<Box2>.right: Integer
<Box2>.top: Integer, alias of y property
<Box2>.bottom: Integer
<Box2>.center: Point2, read-only
The right
property is calculated as right = x + w - 1
. The bottom
property is calculated as bottom = y + h - 1
. Setting the right
or bottom
property will normally change the w
and h
properties, respectively. However, if right
is set less than left
, the right
and left
values will be swapped, and then the new value will be used as the left
value. Likewise, if bottom
is set less than top
, the bottom
and top
values will be swapped, and then the new value will be used as the top
value.
Operators
<Box2> == <Box2>
<Box2> != <Box2>
Standard comparison operators. Two Box2 values are equal if all of their component values are equal.
<Box2> + (<Box2> | <point2> | <point2 array>)
New in 3ds Max 2022*: Expands the Box2 value to include the argument value.
Methods
scale <Box2> <float>
Scales the coordinates of the box about the center of the box.
translate <Box2> <point2>
Translates the coordinates of the box by the distance specified.
contains <Box2> <point2>
Determines if the point2 value is contained within the Box2. Returns true
if the point is inside the Box2 or on the Box2 edge; otherwise false
.
rectify <Box2>
Adjusts the coordinates of the box such that top
< bottom
and left
< right
.
empty <Box2>
Sets the Box2 to a special "empty" value.
isEmpty <Box2>
Returns true
if the Box2 contains the special "empty" value, false
otherwise.
enlargeBy <Box2> <integer>
: Makes the Box2 larger in each direction by the specified value. Available in in 3ds Max 2022 and later
<box2> expandToInclude <box2> (<box2> | <point2> | <point2 array>)
: Expands the Box2 to include the specified value. Available in in 3ds Max 2022 and later
<bool> intersects <Box2> <Box2>
Returns true if the two boxes intersect.
<Box2> copy <Box2>
Returns a copy of the Box2 value.