PHP 7.4.33
Preview: MonotonicInterpolant.js Size: 2.72 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-dnd-html5-backend/dist/MonotonicInterpolant.js
export class MonotonicInterpolant {
    interpolate(x) {
        const { xs , ys , c1s , c2s , c3s  } = this;
        // The rightmost point in the dataset should give an exact result
        let i = xs.length - 1;
        if (x === xs[i]) {
            return ys[i];
        }
        // Search for the interval x is in, returning the corresponding y if x is one of the original xs
        let low = 0;
        let high = c3s.length - 1;
        let mid;
        while(low <= high){
            mid = Math.floor(0.5 * (low + high));
            const xHere = xs[mid];
            if (xHere < x) {
                low = mid + 1;
            } else if (xHere > x) {
                high = mid - 1;
            } else {
                return ys[mid];
            }
        }
        i = Math.max(0, high);
        // Interpolate
        const diff = x - xs[i];
        const diffSq = diff * diff;
        return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq;
    }
    constructor(xs, ys){
        const { length  } = xs;
        // Rearrange xs and ys so that xs is sorted
        const indexes = [];
        for(let i = 0; i < length; i++){
            indexes.push(i);
        }
        indexes.sort((a, b)=>xs[a] < xs[b] ? -1 : 1
        );
        // Get consecutive differences and slopes
        const dys = [];
        const dxs = [];
        const ms = [];
        let dx;
        let dy;
        for(let i1 = 0; i1 < length - 1; i1++){
            dx = xs[i1 + 1] - xs[i1];
            dy = ys[i1 + 1] - ys[i1];
            dxs.push(dx);
            dys.push(dy);
            ms.push(dy / dx);
        }
        // Get degree-1 coefficients
        const c1s = [
            ms[0]
        ];
        for(let i2 = 0; i2 < dxs.length - 1; i2++){
            const m2 = ms[i2];
            const mNext = ms[i2 + 1];
            if (m2 * mNext <= 0) {
                c1s.push(0);
            } else {
                dx = dxs[i2];
                const dxNext = dxs[i2 + 1];
                const common = dx + dxNext;
                c1s.push(3 * common / ((common + dxNext) / m2 + (common + dx) / mNext));
            }
        }
        c1s.push(ms[ms.length - 1]);
        // Get degree-2 and degree-3 coefficients
        const c2s = [];
        const c3s = [];
        let m;
        for(let i3 = 0; i3 < c1s.length - 1; i3++){
            m = ms[i3];
            const c1 = c1s[i3];
            const invDx = 1 / dxs[i3];
            const common = c1 + c1s[i3 + 1] - m - m;
            c2s.push((m - c1 - common) * invDx);
            c3s.push(common * invDx * invDx);
        }
        this.xs = xs;
        this.ys = ys;
        this.c1s = c1s;
        this.c2s = c2s;
        this.c3s = c3s;
    }
}

//# sourceMappingURL=MonotonicInterpolant.js.map

Directory Contents

Dirs: 2 × Files: 33
Name Size Perms Modified Actions
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
utils DIR
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
221 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
230 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
755 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
354 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
915 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.27 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
59 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
283 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
607 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.74 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
24.85 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
43.96 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
276 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
377 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.08 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
169 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
301 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
926 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
210 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.72 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.40 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
186 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
194 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
430 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
433 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
3.79 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
7.68 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
408 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
924 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
2.03 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
270 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
46 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
363 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).