Home Reference Source
import {Box3} from 'math-ds'
public class | source

Box3

A 3D box.

Constructor Summary

Public Constructor
public

Constructs a new box.

Member Summary

Public Members
public

The upper bounds.

public

The lower bounds.

Method Summary

Public Methods
public

Applies the given matrix to this box.

public

clampPoint(point: Vector3, target: Vector3): Vector3

Clamps the given point to the boundaries of this box.

public

clone(): Box3

Clones this box.

public

Checks if the given box lies inside this box.

public

Checks if the given point lies inside this box.

public

copy(b: Box3): Box3

Copies the values of a given box.

public

Calculates the distance from this box to the given point.

public

Checks if this box equals the given one.

public

Expands this box by the given point.

public

Expands this box by the given scalar.

public

Expands this box by the given vector.

public

Computes the center of this box.

public

getSize(target: Vector3): Vector3

Computes the size of this box.

public

Intersects this box with the given one.

public

Checks if this box intersects the given one.

public

Checks if this box intersects the given plane.

public

Checks if this box intersects the given sphere.

public

Indicates whether this box is truly empty.

public

Makes this box empty.

public

set(min: Vector3, max: Vector3): Box3

Sets the values of this box.

public

Defines this box by the given center and size.

public

setFromPoints(points: Vector3[]): Box3

Defines this box by the given points.

public

Computes the bounding box of the given sphere.

public

translate(offset: Vector3): Box3

Translates this box.

public

union(b: Box3): Box3

Expands this box by combining it with the given one.

Public Constructors

public constructor(min: Vector3, max: Vector3) source

Constructs a new box.

Params:

NameTypeAttributeDescription
min Vector3
  • optional

The lower bounds.

max Vector3
  • optional

The upper bounds.

Public Members

public max: Vector3 source

The upper bounds.

public min: Vector3 source

The lower bounds.

Public Methods

public applyMatrix4(m: Matrix4): Box3 source

Applies the given matrix to this box.

Params:

NameTypeAttributeDescription
m Matrix4

The matrix.

Return:

Box3

This box.

public clampPoint(point: Vector3, target: Vector3): Vector3 source

Clamps the given point to the boundaries of this box.

Params:

NameTypeAttributeDescription
point Vector3

A point.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The clamped point.

public clone(): Box3 source

Clones this box.

Return:

Box3

A clone of this box.

public containsBox(b: Box3): Boolean source

Checks if the given box lies inside this box.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Boolean

Whether this box contains the given one.

public containsPoint(p: Vector3): Boolean source

Checks if the given point lies inside this box.

Params:

NameTypeAttributeDescription
p Vector3

A point.

Return:

Boolean

Whether this box contains the point.

public copy(b: Box3): Box3 source

Copies the values of a given box.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Box3

This box.

public distanceToPoint(p: Vector3): Number source

Calculates the distance from this box to the given point.

Params:

NameTypeAttributeDescription
p Vector3

A point.

Return:

Number

The distance.

public equals(b: Box3): Boolean source

Checks if this box equals the given one.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Boolean

Whether this box equals the given one.

public expandByPoint(p: Vector3): Box3 source

Expands this box by the given point.

Params:

NameTypeAttributeDescription
p Vector3

A point.

Return:

Box3

This box.

public expandByScalar(s: Number): Box3 source

Expands this box by the given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Box3

This box.

public expandByVector(v: Vector3): Box3 source

Expands this box by the given vector.

Params:

NameTypeAttributeDescription
v Vector3

A vector.

Return:

Box3

This box.

public getCenter(target: Vector3): Vector3 source

Computes the center of this box.

Params:

NameTypeAttributeDescription
target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

A vector that describes the center of this box.

public getSize(target: Vector3): Vector3 source

Computes the size of this box.

Params:

NameTypeAttributeDescription
target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

A vector that describes the size of this box.

public intersect(b: Box3): Box3 source

Intersects this box with the given one.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Box3

This box.

public intersectsBox(b: Box3): Boolean source

Checks if this box intersects the given one.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Boolean

Whether the boxes intersect.

public intersectsPlane(p: Plane): Boolean source

Checks if this box intersects the given plane.

Computes the minimum and maximum dot product values. If those values are on the same side (back or front) of the plane, then there is no intersection.

Params:

NameTypeAttributeDescription
p Plane

A plane.

Return:

Boolean

Whether the box intersects the plane.

public intersectsSphere(s: Sphere): Boolean source

Checks if this box intersects the given sphere.

Params:

NameTypeAttributeDescription
s Sphere

A sphere.

Return:

Boolean

Whether the box intersects the sphere.

public isEmpty(): Box3 source

Indicates whether this box is truly empty.

This is a more robust check for emptiness since the volume can get positive with two negative axes.

Return:

Box3

This box.

public makeEmpty(): Box3 source

Makes this box empty.

The lower bounds are set to infinity and the upper bounds to negative infinity to create an infinitely small box.

Return:

Box3

This box.

public set(min: Vector3, max: Vector3): Box3 source

Sets the values of this box.

Params:

NameTypeAttributeDescription
min Vector3

The lower bounds.

max Vector3

The upper bounds.

Return:

Box3

This box.

public setFromCenterAndSize(center: Vector3, size: Number): Box3 source

Defines this box by the given center and size.

Params:

NameTypeAttributeDescription
center Vector3

The center.

size Number

The size.

Return:

Box3

This box.

public setFromPoints(points: Vector3[]): Box3 source

Defines this box by the given points.

Params:

NameTypeAttributeDescription
points Vector3[]

The points.

Return:

Box3

This box.

public setFromSphere(sphere: Sphere): Box3 source

Computes the bounding box of the given sphere.

Params:

NameTypeAttributeDescription
sphere Sphere

A sphere.

Return:

Box3

This box.

public translate(offset: Vector3): Box3 source

Translates this box.

Params:

NameTypeAttributeDescription
offset Vector3

The offset.

Return:

Box3

This box.

public union(b: Box3): Box3 source

Expands this box by combining it with the given one.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Box3

This box.