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

Constructs an axis-aligned bounding box.

min
max
BoundingBox.fromPoints(points)BoundingBox

Constructs the smallest bounding box that contains points.

points
Vec[]

An array of points

Properties

.minVec

The minimum position contained within the bounding box.

.maxVec

The maximum position contained within the bounding box.

Methods

.clone()BoundingBox

Returns a copy of the bounding box.

.center()Vec

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

.size()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

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

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

point

The point to contain

.expandToIncludeBoundingBox(box)BoundingBox

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

box

The bounding box to contain

.expandScalar(distance)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

Returns true if point is contained within this bounding box.

.containsBoundingBox(box)boolean

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

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

BoundingBox.booleanIntersect(boxes)(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 | undefined)[]

An array of bounding boxes to intersect

BoundingBox.booleanUnion(boxes)(BoundingBox | undefined)

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

boxes
(BoundingBox | undefined)[]

An array of bounding boxes to union