UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

39 lines (38 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LinearInterpolant = void 0; var _Interpolant = require("../Interpolant.js"); /** * A basic linear interpolant. * * @augments Interpolant */ class LinearInterpolant extends _Interpolant.Interpolant { /** * Constructs a new linear interpolant. * * @param {TypedArray} parameterPositions - The parameter positions hold the interpolation factors. * @param {TypedArray} sampleValues - The sample values. * @param {number} sampleSize - The sample size * @param {TypedArray} [resultBuffer] - The result buffer. */ constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset1 = i1 * stride, offset0 = offset1 - stride, weight1 = (t - t0) / (t1 - t0), weight0 = 1 - weight1; for (let i = 0; i !== stride; ++i) { result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1; } return result; } } exports.LinearInterpolant = LinearInterpolant;