boolean checkCollision(rect, circle)
{
closest.x = circle.x;
closest.y = circle.y;
if (circle.x < rect.x)
closest.x = rect.x;
else if (circle.x > rect.x + rect.width)
closest.x = rect.x + rect.width;
if (circle.y < rect.y)
closest.y = rect.y;
else if (circle.y > rect.y + rect.height)
closest.y = rect.y + rect.height;
delta.x = circle.x - closest.x;
delta.x = circle.y - closest.y;
distanceSquared = delta.x * delta.x + delta.y * delta.y;
radiusSquared = circle.radius * circle.radius;
return distanceSquared <= radiusSquared;
}
For me this is much more clearer. Can anyone explain the other method, posted here? Sadly it did unformat my pseudo-code in the comment.