make sure distanceSquaredToSegment does not divide by zero and return NaN as the distance