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

Box2

A 2D 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

clampPoint(point: Vector2, target: Vector2): Vector2

Clamps the given point to the boundaries of this box.

public

clone(): Box2

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: Box2): Box2

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 bounding sphere of this box.

public

Computes the center of this box.

public

getSize(target: Vector2): Vector2

Computes the size of this box.

public

Intersects this box with the given one.

public

Checks if this box intersects the given one.

public

Indicates whether this box is truly empty.

public

Makes this box empty.

public

set(min: Vector2, max: Vector2): Box2

Sets the values of this box.

public

Defines this box by the given center and size.

public

setFromPoints(points: Vector2[]): Box2

Defines this box by the given points.

public

translate(offset: Vector2): Box2

Translates this box.

public

union(b: Box2): Box2

Expands this box by combining it with the given one.

Public Constructors

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

Constructs a new box.

Params:

NameTypeAttributeDescription
min Vector2
  • optional

The lower bounds.

max Vector2
  • optional

The upper bounds.

Public Members

public max: Vector2 source

The upper bounds.

public min: Vector2 source

The lower bounds.

Public Methods

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

Clamps the given point to the boundaries of this box.

Params:

NameTypeAttributeDescription
point Vector2

A point.

target Vector2
  • optional

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

Return:

Vector2

The clamped point.

public clone(): Box2 source

Clones this box.

Return:

Box2

A clone of this box.

public containsBox(b: Box2): Boolean source

Checks if the given box lies inside this box.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Boolean

Whether this box contains the given one.

public containsPoint(p: Vector2): Boolean source

Checks if the given point lies inside this box.

Params:

NameTypeAttributeDescription
p Vector2

A point.

Return:

Boolean

Whether this box contains the point.

public copy(b: Box2): Box2 source

Copies the values of a given box.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Box2

This box.

public distanceToPoint(p: Vector2): Number source

Calculates the distance from this box to the given point.

Params:

NameTypeAttributeDescription
p Vector2

A point.

Return:

Number

The distance.

public equals(b: Box2): Boolean source

Checks if this box equals the given one.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Boolean

Whether this box equals the given one.

public expandByPoint(p: Vector2): Box2 source

Expands this box by the given point.

Params:

NameTypeAttributeDescription
p Vector2

A point.

Return:

Box2

This box.

public expandByScalar(s: Number): Box2 source

Expands this box by the given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Box2

This box.

public expandByVector(v: Vector2): Box2 source

Expands this box by the given vector.

Params:

NameTypeAttributeDescription
v Vector2

A vector.

Return:

Box2

This box.

public getBoundingSphere(target: Sphere): Sphere source

Computes the bounding sphere of this box.

Params:

NameTypeAttributeDescription
target Sphere
  • optional

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

Return:

Sphere

The bounding sphere of this box.

public getCenter(target: Vector2): Vector2 source

Computes the center of this box.

Params:

NameTypeAttributeDescription
target Vector2
  • optional

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

Return:

Vector2

A vector that describes the center of this box.

public getSize(target: Vector2): Vector2 source

Computes the size of this box.

Params:

NameTypeAttributeDescription
target Vector2
  • optional

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

Return:

Vector2

A vector that describes the size of this box.

public intersect(b: Box2): Box2 source

Intersects this box with the given one.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Box2

This box.

public intersectsBox(b: Box2): Boolean source

Checks if this box intersects the given one.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Boolean

Whether the boxes intersect.

public isEmpty(): Box2 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:

Box2

This box.

public makeEmpty(): Box2 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:

Box2

This box.

public set(min: Vector2, max: Vector2): Box2 source

Sets the values of this box.

Params:

NameTypeAttributeDescription
min Vector2

The lower bounds.

max Vector2

The upper bounds.

Return:

Box2

This box.

public setFromCenterAndSize(center: Vector2, size: Number): Box2 source

Defines this box by the given center and size.

Params:

NameTypeAttributeDescription
center Vector2

The center.

size Number

The size.

Return:

Box2

This box.

public setFromPoints(points: Vector2[]): Box2 source

Defines this box by the given points.

Params:

NameTypeAttributeDescription
points Vector2[]

The points.

Return:

Box2

This box.

public translate(offset: Vector2): Box2 source

Translates this box.

Params:

NameTypeAttributeDescription
offset Vector2

The offset.

Return:

Box2

This box.

public union(b: Box2): Box2 source

Expands this box by combining it with the given one.

Params:

NameTypeAttributeDescription
b Box2

A box.

Return:

Box2

This box.