This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// limits value to the range min..max | |
function clamp(val, min, max) { | |
return Math.max(min, Math.min(max, val)) | |
} | |
// Find the closest point to the circle within the rectangle | |
// Assumes axis alignment! ie rect must not be rotated | |
var closestX = clamp(circle.X, rectangle.x, rectangle.x + rectangle.width); | |
var closestY = clamp(circle.Y, rectangle.y, rectangle.y + rectangle.height); |