I've been trying to implement Douglas-Peucker algorithm into my code and I'm able to translate pseudocode into Swift, except for the shortestDistanceToSegment function. Only Swift version I could find was answered here but I don't understand what that actually does.
I need a function that gets three points as arguments (point and both ends of line) and returns the shortest distance between a CGPoint and a line segment. Some explanation about what (and why) the code does would great but not necessary.