Box2

class Box2(val min: Vector2 = Vector2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), val max: Vector2 = Vector2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY))

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

The box is mutable and not thread-safe; confine an instance to a single thread, as in three.js.

The constructor stores the given vectors by reference (it does not copy them). Passing the same vector as both bounds, or sharing a vector with another object, means later mutations are visible through every alias. Use set or clone when you need independent storage.

Constructors

Link copied to clipboard
constructor(min: Vector2 = Vector2(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), max: Vector2 = Vector2(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY))

Properties

Link copied to clipboard

The upper (max) boundary of the box.

Link copied to clipboard

The lower (min) boundary of the box.

Functions

Link copied to clipboard
fun clampPoint(point: Vector2, target: Vector2): Vector2

Writes point clamped into this box's bounds into target.

Link copied to clipboard
fun clone(): Box2

Returns a new box with copied bounds (independent storage).

Link copied to clipboard

Returns true if this box fully contains box (an identical box counts as contained).

Link copied to clipboard

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

Link copied to clipboard
fun copy(box: Box2): Box2

Copies the bounds of box into this instance.

Link copied to clipboard

Returns the Euclidean distance from point to the nearest edge of this box (0 if inside). An empty box yields +Infinity.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Box2 with equal bounds.

Link copied to clipboard

Expands this box to include point.

Link copied to clipboard
fun expandByScalar(scalar: Double): Box2

Expands each dimension by scalar. A negative scalar contracts the box and can invert it (making it isEmpty).

Link copied to clipboard

Expands this box equilaterally by vector (x on both horizontal sides, y on both vertical sides).

Link copied to clipboard
fun getCenter(target: Vector2): Vector2

Writes the center of this box into target (the zero vector if empty).

Link copied to clipboard
fun getParameter(point: Vector2, target: Vector2): Vector2

Writes point as a proportion of this box's width and height into target.

Link copied to clipboard
fun getSize(target: Vector2): Vector2

Writes the width/height of this box into target (the zero vector if empty).

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun intersect(box: Box2): Box2

Intersects this box with box (keeps the overlapping region), making this box empty if there is no overlap.

Link copied to clipboard

Returns true if box intersects this box (touching edges count).

Link copied to clipboard

Returns true if this box encloses no volume. A box with equal lower and upper bounds is not empty. It still contains the single shared point.

Link copied to clipboard

Makes this box empty (encloses zero space): min = +infinity, max = -infinity.

Link copied to clipboard
fun set(min: Vector2, max: Vector2): Box2

Copies the values of min and max into this box's bounds.

Link copied to clipboard

Centers this box on center and sets its width and height to size.

Link copied to clipboard

Expands this box to enclose all the given points. An empty sequence leaves the box empty.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun translate(offset: Vector2): Box2

Translates this box by offset, moving both bounds.

Link copied to clipboard
fun union(box: Box2): Box2

Unions this box with box (grows to enclose both).