AABB vs AABB (Axis-Aligned Bounding Box)
AABB vs AABB (Axis-Aligned Bounding Box)¶
function aabbOverlap(a, b):
return a.left < b.right and
a.right > b.left and
a.top < b.bottom and
a.bottom > b.top
AABB overlap works because two Axis Aligned rectangles fail to overlap only if one is entirely to the left, right, above, or below the other. Checking the negation of all four "definitely separate" conditions gives you overlap. This is O(1) and why AABB is the default first check in almost every engine.