# Box2

Represents an axis-aligned bounding box (AABB) in 2D space.

## Constructor

### Box2(min : Vector2, max : Vector2)

min — (optional) Vector2 representing the lower (x, y) boundary of the box. Default is `(+Infinity, +Infinity)`.
max — (optional) Vector2 representing the upper (x, y) boundary of the box. Default is `(-Infinity, -Infinity)`.

Creates a Box2 bounded by min and max.

## Properties

### # .min : Vector2

Vector2 representing the lower (x, y) boundary of the box.
Default is `(+Infinity, +Infinity)`.

### # .max : Vector2

Vector2 representing the lower upper (x, y) boundary of the box.
Default is `(-Infinity, -Infinity)`.

## Methods

### # .clampPoint(point : Vector2, target : Vector2) → Vector2

pointVector2 to clamp.
target — the result will be copied into this Vector2.

Clamps the point within the bounds of this box.

### # .clone() → Box2

Returns a new Box2 with the same min and max as this one.

### # .containsBox(box : Box2) → Boolean

boxBox2 to test for inclusion.

Returns true if this box includes the entirety of box. If this and box are identical, this function also returns true.

### # .containsPoint(point : Vector2) → Boolean

pointVector2 to check for inclusion.

Returns true if the specified point lies within or on the boundaries of this box.

### # .copy(box : Box2) → this

Copies the min and max from box to this box.

### # .distanceToPoint(point : Vector2) → Float

pointVector2 to measure distance to.

Returns the distance from any edge of this box to the specified point. If the point lies inside of this box, the distance will be `0`.

### # .equals(box : Box2) → Boolean

box — Box to compare with this one.

Returns true if this box and box share the same lower and upper bounds.

### # .expandByPoint(point : Vector2) → this

pointVector2 that should be included in the box.

Expands the boundaries of this box to include point.

### # .expandByScalar(scalar : Float) → this

scalar — Distance to expand the box by.

Expands each dimension of the box by scalar. If negative, the dimensions of the box will be contracted.

### # .expandByVector(vector : Vector2) → this

vectorVector2 to expand the box by.

Expands this box equilaterally by vector. The width of this box will be expanded by the x component of vector in both directions. The height of this box will be expanded by the y component of vector in both directions.

### # .getCenter(target : Vector2) → Vector2

target — the result will be copied into this Vector2.

Returns the center point of the box as a Vector2.

### # .getParameter(point : Vector2, target : Vector2) → Vector2

pointVector2.
target — the result will be copied into this Vector2.

Returns a point as a proportion of this box's width and height.

### # .getSize(target : Vector2) → Vector2

target — the result will be copied into this Vector2.

Returns the width and height of this box.

### # .intersect(box : Box2) → this

box — Box to intersect with.

Returns the intersection of this and box, setting the upper bound of this box to the lesser of the two boxes' upper bounds and the lower bound of this box to the greater of the two boxes' lower bounds.

### # .intersectsBox(box : Box2) → Boolean

box — Box to check for intersection against.

Determines whether or not this box intersects box.

### # .isEmpty() → Boolean

Returns true if this box includes zero points within its bounds. Note that a box with equal lower and upper bounds still includes one point, the one both bounds share.

### # .makeEmpty() → this

Makes this box empty.

### # .set(min : Vector2, max : Vector2) → this

min — (required) Vector2 representing the lower (x, y) boundary of the box.
max — (required) Vector2 representing the upper (x, y) boundary of the box.

Sets the lower and upper (x, y) boundaries of this box. Please note that this method only copies the values from the given objects.

### # .setFromCenterAndSize(center : Vector2, size : Vector2) → this

center — Desired center position of the box (Vector2).
size — Desired x and y dimensions of the box (Vector2).

Centers this box on center and sets this box's width and height to the values specified in size.

### # .setFromPoints(points : Array) → this

points — Array of Vector2s that the resulting box will contain.

Sets the upper and lower bounds of this box to include all of the points in points.

### # .translate(offset : Vector2) → this

offset — Direction and distance of offset.

Adds offset to both the upper and lower bounds of this box, effectively moving this box offset units in 2D space.

### # .union(box : Box2) → this

box — Box that will be unioned with this box.

Unions this box with box, setting the upper bound of this box to the greater of the two boxes' upper bounds and the lower bound of this box to the lesser of the two boxes' lower bounds.