# BoundingBox

An axis-aligned rectangle. Usually used to represent the minimum and maximum extent of some geometry on the `x` and `y` axes.

## Constructors

BoundingBox(min,max)→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Constructs an axis-aligned bounding box.

`min`

`[Vec](https://cuttle.xyz/learn/reference/Vec)`

`max`

`[Vec](https://cuttle.xyz/learn/reference/Vec)`

BoundingBox.fromPoints(points)→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Constructs the smallest bounding box that contains `points`.

`points`

`[Vec](https://cuttle.xyz/learn/reference/Vec)[]`

An array of points

## Properties

.min[Vec](https://cuttle.xyz/learn/reference/Vec)

The minimum position contained within the bounding box.

.max[Vec](https://cuttle.xyz/learn/reference/Vec)

The maximum position contained within the bounding box.

## Methods

.clone()→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Returns a copy of the bounding box.

.center()→[Vec](https://cuttle.xyz/learn/reference/Vec)

Returns the center point of the bounding box (the average of `min` and `max`).

.size()→[Vec](https://cuttle.xyz/learn/reference/Vec)

Returns a vector representing the size (`Vec(width, height)`) of the bounding box.

.width()→number

Returns the width of the bounding box.

.height()→number

Returns the height of the bounding box.

.area()→number

Returns the signed area of the bounding box.

This is equivalent to `box.width() * box.height()`. If `min` is greater than `max`, the area will be negative.

.isFinite()→boolean

Returns `true` if the `min` and `max` of this bounding box are finite real numbers (not `NaN` or `Infinity`).

.canonicalize()→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Ensures that the `min` is less than `max`, and `max` is greater than `min`. This special case is considered to be the "canonical" configuration.

.expandToIncludePoint(point)→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Grows this bounding box so that `point` is contained within it.

`point`

`[Vec](https://cuttle.xyz/learn/reference/Vec)`

The point to contain

.expandToIncludeBoundingBox(box)→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Grows this bounding box to that `box` is contained within it.

`box`

`[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)`

The bounding box to contain

.expandScalar(distance)→[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)

Grows this bounding box by a scalar `distance` on every side.

`distance`

`number`

The distance to expand by. Negative values with "shrink" this box.

.containsPoint(point)→boolean

`point`

`[Vec](https://cuttle.xyz/learn/reference/Vec)`

Returns `true` if `point` is contained within this bounding box.

.containsBoundingBox(box)→boolean

`box`

`[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)`

Returns `true` if `box` is fully contained within the bounding box. If `box` is exactly equal, it counts as being fully contained.

.overlapsBoundingBox(box)→boolean

`box`

`[BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox)`

Returns `true` if any part of `box` overlaps the bounding box.

BoundingBox.booleanIntersect(boxes)→([BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox) | undefined)

Constructs a bounding box by intersecting two or more bounding boxes. The resulting bounding box will enclose the area shared by the input bounding boxes. If the input bounding boxes do not all intersect, this will return `undefined`. Undefined entries in the array are ignored.

`boxes`

`([BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox) | undefined)[]`

An array of bounding boxes to intersect

BoundingBox.booleanUnion(boxes)→([BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox) | undefined)

Constructs a bounding box that encloses all the given bounding boxes. Undefined entries in the array are ignored.

`boxes`

`([BoundingBox](https://cuttle.xyz/learn/reference/BoundingBox) | undefined)[]`

An array of bounding boxes to union