AABB

platypus. AABB

new AABB(x, y, width, height) → {platypus.AABB}

Defines an axis-aligned bounding box (AABB) used for collision checks, containment tests, and spatial calculations.

The AABB stores both center-based coordinates (x, y, width, height) and edge-based coordinates (left, top, right, bottom) for fast access during collision operations.

Position values (x, y) always represent the center of the rectangle.

Mutation Semantics:

  • move* methods translate the AABB.
  • setWidth and setHeight resize around the center.
  • setLeft, setRight, setTop, and setBottom resize while preserving the opposite edge.
  • setBounds reconstructs the rectangle from explicit bounds.

AABBs are mutable and recyclable. Instances should not be retained after calling recycle.

Source:
Parameters:
Name Type Description
x number | platypus.AABB

The x position of the AABB center, or an existing AABB to copy.

y number

The y position of the AABB center.

width number

The width of the AABB.

height number

The height of the AABB.

Returns:
Type:
platypus.AABB

Returns the instantiated AABB.

Methods

(static) recycle(aabb)

Returns an AABB to the cache.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to recycle.

(static) setUp() → {platypus.AABB}

Returns an AABB from cache or creates a new one if none are available.

Source:
Returns:
Type:
platypus.AABB

collides(aabb) → {boolean}

Returns whether this AABB overlaps another AABB.

Edge-touching does not count as a collision.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to test.

Returns:
Type:
boolean

collidesPoint(x, y) → {boolean}

Returns whether this AABB overlaps the provided point.

Edge-touching does not count as collision.

Source:
Parameters:
Name Type Description
x number

The x coordinate.

y number

The y coordinate.

Returns:
Type:
boolean

contains(aabb) → {boolean}

Returns whether this AABB completely contains another AABB.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to test.

Returns:
Type:
boolean

containsPoint(x, y) → {boolean}

Returns whether this AABB contains the provided point.

Edge-touching counts as containment.

Source:
Parameters:
Name Type Description
x number

The x coordinate.

y number

The y coordinate.

Returns:
Type:
boolean

containsVector(vector) → {boolean}

Returns whether this AABB contains the provided vector.

Source:
Parameters:
Name Type Description
vector platypus.Vector

The vector to test.

Returns:
Type:
boolean

equals(aabb) → {boolean}

Returns whether this AABB matches another AABB exactly.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to compare against.

Returns:
Type:
boolean

getIntersection(aabb) → {platypus.AABB}

Returns a new AABB representing the overlapping area between two AABBs.

If no overlap exists, an empty AABB is returned.

The returned AABB is pooled and should be recycled when no longer needed.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to intersect against.

Returns:
Type:
platypus.AABB

getIntersectionArea(aabb) → {number}

Returns the overlapping area between two AABBs.

Returns 0 if no overlap exists.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to intersect against.

Returns:
Type:
number

include(aabb)

Expands this AABB so that it encloses both its current area and the provided AABB.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to include.

includeVector(…vectors)

Expands this AABB so that it encloses the provided point or points.

Source:
Parameters:
Name Type Attributes Description
vectors platypus.Vector <repeatable>

The vectors to include.

intersects(aabb) → {boolean}

Returns whether this AABB intersects another AABB.

Edge-touching counts as an intersection.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to test.

Returns:
Type:
boolean

move(x, y)

Moves the AABB to the specified location.

Source:
Parameters:
Name Type Description
x number

The new x position.

y number

The new y position.

moveX(x)

Moves the AABB horizontally.

Source:
Parameters:
Name Type Description
x number

The new x position.

moveXBy(deltaX)

Moves the AABB horizontally by a delta value.

Source:
Parameters:
Name Type Description
deltaX number

The change in x position.

moveY(y)

Moves the AABB vertically.

Source:
Parameters:
Name Type Description
y number

The new y position.

moveYBy(deltaY)

Moves the AABB vertically by a delta value.

Source:
Parameters:
Name Type Description
deltaY number

The change in y position.

recycle()

Relinquishes properties of the AABB and recycles it.

Source:

reset()

Marks the AABB as empty so it may be reused or recycled.

Existing positional values are retained internally for performance reasons and should not be considered valid while empty === true.

Source:

resize(width, height)

Resizes the AABB around its center position.

Source:
Parameters:
Name Type Description
width number

The new width.

height number

The new height.

set(aabb)

Copies values from another AABB.

Source:
Parameters:
Name Type Description
aabb platypus.AABB

The AABB to copy values from.

setAll(x, y, width, height)

Sets all of the properties of the AABB.

Source:
Parameters:
Name Type Description
x number

The x position of the AABB center.

y number

The y position of the AABB center.

width number

The width of the AABB.

height number

The height of the AABB.

setBottom(bottom)

Sets the bottom edge of the AABB while preserving the top edge.

This operation resizes the AABB vertically.

Source:
Parameters:
Name Type Description
bottom number

The new bottom edge.

setBounds(left, top, right, bottom)

Sets all four bounds of the AABB directly.

Unlike edge mutators such as setLeft or setTop, this method completely reconstructs the rectangle from authoritative edge values.

Source:
Parameters:
Name Type Description
left number

The left edge.

top number

The top edge.

right number

The right edge.

bottom number

The bottom edge.

setHeight(height)

Sets the height of the AABB while preserving its center position.

Source:
Parameters:
Name Type Description
height number

The new height.

setLeft(left)

Sets the left edge of the AABB while preserving the right edge.

This operation resizes the AABB horizontally.

Source:
Parameters:
Name Type Description
left number

The new left edge.

setRight(right)

Sets the right edge of the AABB while preserving the left edge.

This operation resizes the AABB horizontally.

Source:
Parameters:
Name Type Description
right number

The new right edge.

setTop(top)

Sets the top edge of the AABB while preserving the bottom edge.

This operation resizes the AABB vertically.

Source:
Parameters:
Name Type Description
top number

The new top edge.

setWidth(width)

Sets the width of the AABB while preserving its center position.

Source:
Parameters:
Name Type Description
width number

The new width.

toString() → {string}

Returns a string representation of the AABB.

Source:
Returns:
Type:
string