Function distanceToLineSegment