Circle Rect Collision

//Javascript
function rect_circle_collision(center, r, v1, v2){ //v1 and v2 must be opposite vertices
  let closest = {
    x : max(v1.x, min(center.x, v2.x)),
    y : max(v1.y, min(center.y, v2.y))
  };
  return (closest.x - center.x) ** 2 + (closest.y - center.y) ** 2 <= r; 
}
Kind Katipo