Skip to main content

Class: Box2

Represents a box in 2D space. Needing two Vec2 vectors describing the corners

Constructors#

constructor#

new Box2(p0?, p1?)

Creates a Box2 object using Vec2s. In case the parameters are not passed by, their values are pre-defined:

p0 is a Vec2 with Number.POSITIVE_INFINITY

p1 is a Vec2 with Number.NEGATIVE_INFINITY

Parameters#

NameTypeDescription
p0?Vec2A point representing the corners of a 2D box.
p1?Vec2A point representing the corners of a 2D box.

Defined in#

Math/Box2.ts:22

Properties#

p0#

p0: Vec2

Defined in#

Math/Box2.ts:8


p1#

p1: Vec2

Defined in#

Math/Box2.ts:9

Methods#

addPoint#

addPoint(point): void

Expands the Box2 to contain the new point.

Parameters#

NameTypeDescription
pointVec2A point represents the corners of a 2D box.

Returns#

void

Defined in#

Math/Box2.ts:78


center#

center(): Vec2

Returns the center point of a Box2.

Returns#

Vec2

  • Returns a Vec2.

Defined in#

Math/Box2.ts:109


diagonal#

diagonal(): Vec2

Returns the size of a Box2 - the same as size().

Returns#

Vec2

  • Returns a Vec2.

Defined in#

Math/Box2.ts:100


isValid#

isValid(): boolean

Returns true if the box has been expanded to contain a point.

Returns#

boolean

  • The return value.

Defined in#

Math/Box2.ts:64


reset#

reset(): void

Resets the box2 back to an uninitialized state.

see Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY

Returns#

void

Defined in#

Math/Box2.ts:52


set#

set(p0, p1): void

Sets both Vec2 points

Parameters#

NameTypeDescription
p0Vec2A point representing the corners of a 2D box.
p1Vec2A point representing the corners of a 2D box.

Returns#

void

Defined in#

Math/Box2.ts:41


size#

size(): number

Returns the length of the diagonal of the box.

Returns#

number

  • Returns the distance.

Defined in#

Math/Box2.ts:91


toJSON#

toJSON(): Record<string, Record<string, number>>

Encodes Box2 Class as a JSON object for persistence.

Returns#

Record<string, Record<string, number>>

  • The json object.

Defined in#

Math/Box2.ts:124


toString#

toString(): string

Calls toJSON method and stringifies it.

Returns#

string

  • The return value.

Defined in#

Math/Box2.ts:136