Hide menu
Loading...
Searching...
No Matches
Box

Defines a 3D axis-aligned bounding box.

The box is defined by two corners: minCorner containing the minimum coordinates and maxCorner containing the maximum coordinates.

Constructors

Constructor

new Box(corner1?, corner2?): Box

Creates a box from two points.

The minimum corner is determined from the minimum values of each coordinate in the given points. The maximum corner is determined from the maximum values.

If no points are provided, the box is initialized with non-finite bounds: minCorner is set to (-Infinity, -Infinity, -Infinity) and maxCorner is set to (Infinity, Infinity, Infinity). This state is useful as an accumulator and becomes finite as soon as finite points are added.

Parameters

corner1?

Point

First corner.

corner2?

Point

Second corner.

Returns

Box

Properties

maxCorner

readonly maxCorner: Point

Maximum corner of the box.


minCorner

readonly minCorner: Point

Minimum corner of the box.

Accessors

center

Get Signature

get center(): Point

Center point of the box.

The center is the middle point of the diagonal between minCorner and maxCorner.

Returns

Point


xRange

Get Signature

get xRange(): number

Length of the range along the X axis.

Returns

number


yRange

Get Signature

get yRange(): number

Length of the range along the Y axis.

Returns

number


zRange

Get Signature

get zRange(): number

Length of the range along the Z axis.

Returns

number

Methods

add()

Call Signature

add(point): this

Adjusts the box corners so that it contains point.

Only finite coordinates of point are taken into account.

Parameters

point

Point

Added point.

Returns

this

Call Signature

add(box): this

Adjusts the box corners so that it contains box.

Parameters

box

Box

Added box.

Returns

this


clear()

clear(): this

Resets the box to its initial non-finite accumulator state, so that isInfinity() returns true.

Returns

this


clone()

clone(): Box

Creates a new box with the same minCorner and maxCorner as this box.

Returns

Box


copy()

copy(other): this

Copies the minCorner and maxCorner of other to this box.

The values of the points are copied without replacing the existing corner objects of this box.

Parameters

other

Box

Box to copy.

Returns

this


corner()

corner(index): Point

Returns one of the box corners:

  • Minimum corner if index equals 0
  • Maximum corner if index equals 1

Throws a RangeError if index is not in the range [0, 1].

Parameters

index

number

Corner index.

Returns

Point


enlarge()

Call Signature

enlarge(x, y, z): this

Enlarges the box dimensions by the specified values.

Each box extent is shifted by 0.5 of the specified value to the negative and positive side along the corresponding axis.

Parameters

x

number

Value along X axis.

y

number

Value along Y axis.

z

number

Value along Z axis.

Returns

this

Call Signature

enlarge(size): this

Enlarges the box dimensions by the specified value.

Each box extent is shifted by 0.5 * size to the negative and positive side along each axis.

Parameters

size

number

Shift value.

Returns

this


enlarged()

Call Signature

enlarged(x, y, z): Box

Returns a new box obtained by applying enlarge() to this box.

Parameters

x

number

Value along X axis.

y

number

Value along Y axis.

z

number

Value along Z axis.

Returns

Box

Call Signature

enlarged(size): Box

Returns a new box obtained by applying enlarge() to this box.

Parameters

size

number

Shift value.

Returns

Box


isIn()

isIn(point): boolean

Returns true if the point lies inside the box.

Parameters

point

Point

Checked point.

Returns

boolean


isInfinity()

isInfinity(): boolean

Returns true if at least one coordinate is not finite.

Returns

boolean


isIntersecting()

isIntersecting(other): boolean

Returns true if the other box has at least one common point with this box.

Parameters

other

Box

Checked box.

Returns

boolean


multiplied()

multiplied(scalar): Box

Returns a new box obtained by applying multiply() to this box.

Parameters

scalar

number

Scalar value.

Returns

Box


multiply()

multiply(scalar): this

Scales the box by a scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


range()

range(index): number

Returns the length of the range along the specified axis:

  • X axis if index equals 0
  • Y axis if index equals 1
  • Z axis if index equals 2

Throws a RangeError if index is not in the range [0, 2].

Parameters

index

number

Range index.

Returns

number


setRange()

setRange(index, min, max): this

Sets one range of the box to the specified values:

  • X axis if index equals 0
  • Y axis if index equals 1
  • Z axis if index equals 2

Throws a RangeError if index is not in the range [0, 2].

Parameters

index

number

Range index.

min

number

Minimum corner coordinate.

max

number

Maximum corner coordinate.

Returns

this


setXRange()

setXRange(min, max): this

Sets the range of box along X axis to the specified values.

Parameters

min

number

Minimum corner coordinate.

max

number

Maximum corner coordinate.

Returns

this


setYRange()

setYRange(min, max): this

Sets the range of box along Y axis to the specified values.

Parameters

min

number

Minimum corner coordinate.

max

number

Maximum corner coordinate.

Returns

this


setZRange()

setZRange(min, max): this

Sets the range of box along Z axis to the specified values.

Parameters

min

number

Minimum corner coordinate.

max

number

Maximum corner coordinate.

Returns

this


transform()

transform(transformation): this

Transforms the box.

If the transformation does not contain anything besides perhaps a translation, the box dimensions are kept as is and its position is recalculated accordingly.

If rotation or scale are present, all box corners are transformed and a new axis-aligned box containing them is built. If the box was infinite in one of the directions, the new box will also be infinite in the directions that result from applying the transformation to the original directions. The new box most likely has larger dimensions than the original.

For more accurate results, it is recommended to transform the objects the box was built from and only then calculate the box.

Parameters

transformation

Transformation

Transformation.

Returns

this


transformed()

transformed(transformation): Box

Returns a new box obtained by applying transform() to this box.

Parameters

transformation

Transformation

Transformation.

Returns

Box