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

Defines a 3D axis-aligned bounding box.

The box is defined via two corners - minCorner and maxCorner

  • containing minimum and maximum coordinates respectively.

Constructors

new Box()

new Box(corner1?, corner2?): Box

Creates a box from 2 points. Minimum corner is determined from the minimum values for each coordinate in the given points. Maximum corner is determined from the maximum values.

Default is infinity box where minimum corner is a point with all coordinates equal to Number.NEGATIVE_INFINITY and maximum corner is a point with all coordinates equal to Number.POSITIVE_INFINITY.

Parameters

corner1?

Point

First corner.

corner2?

Point

Second corner.

Returns

Box

Properties

maxCorner

maxCorner: Point


minCorner

minCorner: Point

Accessors

center

Get Signature

get center(): Point

Returns a center point - a middle of the diagonal between minCorner and maxCorner.

Returns

Point


xRange

Get Signature

get xRange(): number

Returns the length of range along X axis.

Returns

number


yRange

Get Signature

get yRange(): number

Returns the length of range along Y axis.

Returns

number


zRange

Get Signature

get zRange(): number

Returns the length of range along Z axis.

Returns

number

Methods

add()

Call Signature

add(point): this

Adjusts the box corners so that it contains point. Takes into account only finite coordinates of point.

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. Assigns infinite values to the coordinates, so that isInfinity() returns true.

Returns

this


clone()

clone(): Box

Creates new Box object with coordinates same as this.

Returns

Box


copy()

copy(other): this

Copies the coordinates of the other box to this.

Parameters

other

Box

Copied object.

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 exception if index is not in range [0, 1].

Parameters

index

number

Corner index.

Returns

Point


enlarge()

Call Signature

enlarge(x, y, z): this

Enlarge the box dimensions by specified values. Each box extent is shifted by 0.5 of the specified shift value to the negative and positive side along respective 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

Enlarge the box dimensions by specified value. Each box extent is shifted by 0.5 x size to the negative and positive side along respective axis.

Parameters

size

number

Shift value.

Returns

this


enlarged()

Call Signature

enlarged(x, y, z): Box

Returns new Box object received by performing an enlarge() operation to this object.

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 new Box object received by performing an enlarge() operation to this object.

Parameters

size

number

Shift value.

Returns

Box


getRange()

getRange(index): number

Returns the length of range along specified axis:

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

Throws exception if index is not in range [0, 2].

Parameters

index

number

Range index.

Returns

number


intersects()

intersects(other): boolean

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

Parameters

other

Box

Checked box.

Returns

boolean


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 infinite.

Returns

boolean


multiplied()

multiplied(scalar): Box

Returns new Box object received by performing a multiply() operation to this object.

Parameters

scalar

number

Scalar value.

Returns

Box


multiply()

multiply(scalar): this

Scales box by scalar value.

Parameters

scalar

number

Scalar value.

Returns

this


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 exception if index is not in 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 are results of applying the transformation to the original directions. The new box most likely has larger dimensions than the original.

For more accurate results, it's recommended instead to transform the arguments the box was built from and only then calculate the box.

Parameters

transformation

Transformation

Transformation.

Returns

this


transformed()

transformed(transformation): Box

Returns new Box object received by performing a transform() operation to this object.

Parameters

transformation

Transformation

Transformation.

Returns

Box