distance from point to polygon edge

Does anyone have a good algorithm for finding the closest distance from a point to the edge of a polygon? Preferably concave or convex.
I’ve just spent an hour digging through Google results but no luck.

i guess you can use the distance from a point to a line segment:


go through all the segments of the polygon finding the distance and take the nearest as the distance to the polygon. also you could test if it’s outside or inside the polygon using ofInsidePoly