interpolateArray method
Makes an array data
larger by linear interpolation.
newSize
is the desired size after interpolation.
Returns a new array of newSize
.
Works evens if newSize
is smaller than data
size, but this is not a true
compression preserving minima an maxima. See CompressedArray1D instead.
Implementation
static Float64List interpolateArray(Float64List data, int newSize) {
Float64List newData = new Float64List(newSize);
double springFactor = ((data.length - 1) / (newSize - 1));
newData[0] = data[0]; // for new allocation
for (var i = 1; i < newSize - 1; i++) {
double tmp = i * springFactor;
int before = tmp.floor();
int after = tmp.ceil();
double atPoint = tmp - before;
newData[i] = linearInterpolate(data[before], data[after], atPoint);
}
newData[newSize - 1] = data[data.length - 1]; // for new allocation
return newData;
}