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.setWidthandsetHeightresize around the center.setLeft,setRight,setTop, andsetBottomresize while preserving the opposite edge.setBoundsreconstructs the rectangle from explicit bounds.
AABBs are mutable and recyclable. Instances should not be retained after
calling recycle.
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. |
Methods
(static) recycle(aabb)
Returns an AABB to the cache.
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.
Returns:
- Type:
-
platypus.AABB
collides(aabb) → {boolean}
Returns whether this AABB overlaps another AABB.
Edge-touching does not count as a collision.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
aabb |
platypus.AABB
|
The AABB to test. |
Returns:
- Type:
-
boolean
move(x, y)
Moves the AABB to the specified location.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number
|
The new x position. |
y |
number
|
The new y position. |
moveX(x)
Moves the AABB horizontally.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number
|
The new x position. |
moveXBy(deltaX)
Moves the AABB horizontally by a delta value.
Parameters:
| Name | Type | Description |
|---|---|---|
deltaX |
number
|
The change in x position. |
moveY(y)
Moves the AABB vertically.
Parameters:
| Name | Type | Description |
|---|---|---|
y |
number
|
The new y position. |
moveYBy(deltaY)
Moves the AABB vertically by a delta value.
Parameters:
| Name | Type | Description |
|---|---|---|
deltaY |
number
|
The change in y position. |
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.
resize(width, height)
Resizes the AABB around its center position.
Parameters:
| Name | Type | Description |
|---|---|---|
width |
number
|
The new width. |
height |
number
|
The new height. |
set(aabb)
Copies values from another AABB.
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.
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.
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.
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.
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.
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.
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.
Parameters:
| Name | Type | Description |
|---|---|---|
top |
number
|
The new top edge. |
setWidth(width)
Sets the width of the AABB while preserving its center position.
Parameters:
| Name | Type | Description |
|---|---|---|
width |
number
|
The new width. |