# Box2 Values

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.

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

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.

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.