Skip to content

Box2 ​

Axis-aligned bounding box defined by minimum and maximum corners.

Box2 represents a 2D region bounded by two corners: min and max. It is used for view rectangles, viewport regions, and intersection checks. A default-constructed box is empty and intersection treats boxes as half-open intervals.

Constructor ​

Creates a box from optional corner points. The corners are cloned. When a corner is omitted the box starts empty.

ts
new Box2(min?, max?): Box2;
ParameterDescription
min?: vec2The minimum corner.
max?: vec2The maximum corner.

Properties ​

min ​

Minimum corner of the box.

ts
min: vec2;

max ​

Maximum corner of the box.

ts
max: vec2;

Methods ​

clone() Box2 ​

Returns a deep copy of the box.

ts
clone(): Box2;

isEmpty() boolean ​

Returns true when the box encloses no area.

ts
isEmpty(): boolean;

intersects() boolean ​

Tests whether two boxes overlap. Boxes are treated as half-open intervals so touching edges do not count as overlap.

ts
static intersects(a, b): boolean;
ParameterDescription
a: Box2The first box.
b: Box2The second box.

equals() boolean ​

Tests whether two boxes have exactly equal corners.

ts
static equals(a, b): boolean;
ParameterDescription
a: Box2The first box.
b: Box2The second box.

floor() Box2 ​

Returns a copy with both corners floored componentwise.

ts
floor(): Box2;

toRect() ​

Converts the box to an x, y, width, height rectangle.

ts
toRect(): {
  x: number;
  y: number;
  width: number;
  height: number;
};

Released under the MIT License