Trying to snap to a polyine at its bending point ...
Trying to snap to a polyine (or other curve) at its bending point to get the distance is not applicable in this question.
Your routine can surely get the closest point at the curve, no worry about the start point or the end point. Howerver, we have to make sure we are in a WCS, otherwise we will get it wrong. What do you reckon?