CanvasClean.LoessInterpolator.updateBandwidthInterval C# (CSharp) Method

updateBandwidthInterval() private static method

Given an Index interval into xval that embraces a certain number of points closest to a value less than x, update the interval so that it embraces the same number of points closest to x.
private static updateBandwidthInterval ( double x, double xval, int bandwidthInterval ) : int[]
x double Assumed to be greater than xval[bandwidthInterval[0]] but may be greater than xval[bandwidthInterval[1]]
xval double Assumed sorted in ascending order
bandwidthInterval int
return int[]
        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;
        }