It seems like it calculates the step size on the X-Axis wrong, the calculation is now:
double stepSize = (maxX - minX) / (pointCount);
so if you have 2 points to calculate on where
maxX=1 and minX=0 (only two points) then the step size is = 0.5 but is shoud actually have been 1.0
This gives the right result:
double stepSize = (maxX - minX) / (pointCount-1);