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 CatmullRom = require('../CatmullRom');
|
|
|
|
|
2017-10-06 03:52:41 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Math.Interpolation.CatmullRom
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} v - [description]
|
|
|
|
* @param {number} k - [description]
|
|
|
|
*
|
|
|
|
* @return {number} [description]
|
|
|
|
*/
|
2016-12-07 17:16:59 +00:00
|
|
|
var CatmullRomInterpolation = function (v, k)
|
|
|
|
{
|
|
|
|
var m = v.length - 1;
|
|
|
|
var f = m * k;
|
|
|
|
var i = Math.floor(f);
|
|
|
|
|
|
|
|
if (v[0] === v[m])
|
|
|
|
{
|
|
|
|
if (k < 0)
|
|
|
|
{
|
|
|
|
i = Math.floor(f = m * (1 + k));
|
|
|
|
}
|
|
|
|
|
2017-09-21 01:30:35 +00:00
|
|
|
return CatmullRom(f - i, v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m]);
|
2016-12-07 17:16:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (k < 0)
|
|
|
|
{
|
2017-09-21 01:30:35 +00:00
|
|
|
return v[0] - (CatmullRom(-f, v[0], v[0], v[1], v[1]) - v[0]);
|
2016-12-07 17:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (k > 1)
|
|
|
|
{
|
2017-09-21 01:30:35 +00:00
|
|
|
return v[m] - (CatmullRom(f - m, v[m], v[m], v[m - 1], v[m - 1]) - v[m]);
|
2016-12-07 17:16:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 01:30:35 +00:00
|
|
|
return CatmullRom(f - i, v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2]);
|
2016-12-07 17:16:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CatmullRomInterpolation;
|