I am working on my Computer Graphics assignment and wanted to know if there was a more optimized way of determining the closest point along an edge to a given point. Here is how I am doing it currently:
I am doing a mouse press (green dot) and then doing a mouse release (blue dot). I want to find the closest point along the edge of the window to the blue dot.
I create four lines with each of the corners (each purple dot) [[TopLeft, Bottom Left], [BottomLeft, BottomRight], ...] and then do a line-line intersection with the green dot to blue dot to each of the lines. From there I take the distance between the blue dot and the intersecting point from the line-line test, and selecting the smallest point.
I wanted to know if there was a better solution to finding this point. Maybe something like this? Where I can extend the line in either direction, find the two red dots, and select the one closest to the blue dot?

