The special case for the interpolation to the last point was being used for every point in the last segment, because of the rounding. Instead, make the function slightly more complicated to properly handle the correct interolation in the cyclic and non-cyclic cases.