private static int[] updateBandwidthInterval(double x, double[] xval, int[] bandwidthInterval)
{
bool updated = false;
int leftIndex = bandwidthInterval[0];
int rightIndex = bandwidthInterval[1];
// x > xval[rightIndex]
while (rightIndex < xval.Length - 1 && x > xval[rightIndex])
{
leftIndex++;
rightIndex++;
updated = true;
}
// The right edge should be adjusted if the next point to the right
// is closer to x than the leftmost point of the current interval
while (rightIndex < xval.Length - 1 && xval[rightIndex + 1] - x < x - xval[leftIndex])
{
leftIndex++;
rightIndex++;
updated = true;
}
if (updated)
{
return new int[] { leftIndex, rightIndex };
}
return null;
}