2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-12-07 17:16:59 +00:00
|
|
|
var Linear = require('../Linear');
|
|
|
|
|
2017-10-06 03:52:41 +00:00
|
|
|
/**
|
2018-04-02 15:54:46 +00:00
|
|
|
* A Linear Interpolation Method.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.Interpolation.Linear
|
|
|
|
* @since 3.0.0
|
2018-04-02 15:54:46 +00:00
|
|
|
* @see https://en.wikipedia.org/wiki/Linear_interpolation
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-04-02 15:54:46 +00:00
|
|
|
* @param {number[]} v - The input array of values to interpolate between.
|
|
|
|
* @param {!number} k - The percentage of interploation, between 0 and 1.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-04-02 15:54:46 +00:00
|
|
|
* @return {!number} The interpolated value.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2016-12-07 17:16:59 +00:00
|
|
|
var LinearInterpolation = function (v, k)
|
|
|
|
{
|
|
|
|
var m = v.length - 1;
|
|
|
|
var f = m * k;
|
|
|
|
var i = Math.floor(f);
|
|
|
|
|
|
|
|
if (k < 0)
|
|
|
|
{
|
|
|
|
return Linear(v[0], v[1], f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k > 1)
|
|
|
|
{
|
|
|
|
return Linear(v[m], v[m - 1], m - f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Linear(v[i], v[(i + 1 > m) ? m : i + 1], f - i);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = LinearInterpolation;
|