It finds the closest point on a square from outside the square. I used this to determine the gravity source in my game Super Scratch Cat Galaxy: https://scratch.mit.edu/projects/1011545320/