Circle vs AABB
Circle vs AABB¶
function circleAabbOverlap(circle, box):
closestX = clamp(circle.x, box.left, box.right)
closestY = clamp(circle.y, box.top, box.bottom)
dx = circle.x - closestX
dy = circle.y - closestY
return (dx*dx + dy*dy) < circle.radius^2
Circle-AABB finds the closest point on the box to the circle's center by clamping the circle's coordinates into the box's range, then does a normal circle-point distance check against that closest point. This correctly handles all cases: circle over a corner, circle over an edge, or center inside the box.