intersectAABB2D

View sourceintersectAABB2D(a: BoundingBox2D, b: BoundingBox2D): boolean

Returns whether two BoundingBox2D values overlap.

The x and y intervals are tested independently with inclusive comparisons. Boxes that share an edge or corner therefore return true; boxes separated on either axis return false. The helper reads the bounds without mutating either value and does not validate or reorder their coordinates.

Examples

import { BoundingBox2D, intersectAABB2D } from '@wimaengine/geometry'

const a = new BoundingBox2D(0, 0, 2, 2)
const b = new BoundingBox2D(2, 1, 4, 3)
intersectAABB2D(a, b) // true: the boxes share an x edge

Parameters

NameDescriptionDefault
a

First box.

—
b

Second box.

—

Returns

Whether the boxes overlap on both axes, including at an edge or corner.