UNPKG

arcade-physics

Version:
39 lines 1.29 kB
"use strict"; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Linear_1 = __importDefault(require("../Linear")); /** * A linear interpolation method. * * @function Phaser.Math.Interpolation.Linear * @since 3.0.0 * @see {@link https://en.wikipedia.org/wiki/Linear_interpolation} * * @param {number[]} v - The input array of values to interpolate between. * @param {!number} k - The percentage of interpolation, between 0 and 1. * * @return {!number} The interpolated value. */ const LinearInterpolation = (v, k) => { const m = v.length - 1; const f = m * k; const i = Math.floor(f); if (k < 0) { return (0, Linear_1.default)(v[0], v[1], f); } else if (k > 1) { return (0, Linear_1.default)(v[m], v[m - 1], m - f); } else { return (0, Linear_1.default)(v[i], v[i + 1 > m ? m : i + 1], f - i); } }; exports.default = LinearInterpolation; //# sourceMappingURL=LinearInterpolation.js.map