Skip to main content

Class: AABB

physics/aabb/aabb.AABB

Represents an axis aligned bounding box in 2D world space.

A minimum (bottom left) and maximum (top right) vertex is used to represent the AABB.

Constructors

constructor

โ€ข new AABB(min, max)

Creates a AABB with the given minimum and and maximum vertices.

Parameters

NameTypeDescription
minvec2The minimum vertex (bottom left)
maxvec2The maximum vertex (top right)

Defined in

src/physics/aabb/aabb.ts:29

โ€ข new AABB(a, b, margin)

Creates an AABB which contains both a and b, the created AABB is the union of a and b plus the margin.

Parameters

NameTypeDescription
aAABBAn AABB
bAABBAn AABB
marginnumberA margin to add to the min and max of the created AABB

Defined in

src/physics/aabb/aabb.ts:38

โ€ข new AABB(obj, margin)

Creates a AABB that bounds the vertices of the given object's collider.

Parameters

NameTypeDescription
objCollisionObjectCollisionObject to create AABB from
marginnumberA margin to add to the new min and max points

Defined in

src/physics/aabb/aabb.ts:46

Properties

margin

โ€ข margin: number

Defined in

src/physics/aabb/aabb.ts:16


max

โ€ข max: vec2

Defined in

src/physics/aabb/aabb.ts:14


min

โ€ข min: vec2

Defined in

src/physics/aabb/aabb.ts:13


obj

โ€ข obj: CollisionObject

A CollisionObject that is bound by the AABB.

Defined in

src/physics/aabb/aabb.ts:21

Methods

area

โ–ธ area(): number

Computes the area of the AABB.

Returns

number

The area of the AABB

Defined in

src/physics/aabb/aabb.ts:119


clipLine

โ–ธ Private clipLine(dim, v0, v1, fLow, fHigh): false | { fHigh: number = newFHigh; fLow: number = newFLow }

Clips a line based on the AABB's min and max to determine if the line intersects with the AABB.

Parameters

NameTypeDescription
dimnumberThe dimension to clip in (0 = x, 1 = y)
v0vec2The line's start point
v1vec2The line's end point
fLownumberThe current fLow
fHighnumberThe current fHigh

Returns

false | { fHigh: number = newFHigh; fLow: number = newFLow }

false when no intersection possible, otherwise new fLow and fHigh

Defined in

src/physics/aabb/aabb.ts:196


contains

โ–ธ contains(b): boolean

Determines wether or not the given AABB is contained within this AABB.

Parameters

NameTypeDescription
bAABBThe AABB to check

Returns

boolean

Defined in

src/physics/aabb/aabb.ts:182


intersects

โ–ธ intersects(b): boolean

Determines wether or not this AABB intersects with the given AABB.

Parameters

NameTypeDescription
bAABBThe AABB to check for intersection against

Returns

boolean

Defined in

src/physics/aabb/aabb.ts:131

โ–ธ intersects(point): boolean

Determines wether or not the given point intersects with this AABB.

Parameters

NameTypeDescription
pointvec2The point to check for intersection

Returns

boolean

Defined in

src/physics/aabb/aabb.ts:138

โ–ธ intersects(ray): boolean

Determines wether or not the given ray intersects with this AABB.

Parameters

NameTypeDescription
rayRayThe ray to check for intersection

Returns

boolean

Defined in

src/physics/aabb/aabb.ts:145


setMinMaxFromCollisionObj

โ–ธ setMinMaxFromCollisionObj(obj, margin): void

Sets the AABB's min and max so that the AABB contains the object's collider.

Parameters

NameTypeDescription
objCollisionObjectThe CollisionObject to bound
marginnumberA margin to add to the new min and max points

Returns

void

Defined in

src/physics/aabb/aabb.ts:65


union

โ–ธ union(a, b, margin?): void

Sets the AABB's min and max to the union of a and b.

Parameters

NameTypeDefault valueDescription
aAABBundefinedAn AABB
bAABBundefinedAn AABB
marginnumber0A margin to add to the new min and max points

Returns

void

Defined in

src/physics/aabb/aabb.ts:103