Function distanceToCurveSegment