Fix handling of endpoints in point-segment distance