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}
|
|
|
|
*/
|
|
|
|
|
2017-10-06 03:52:41 +00:00
|
|
|
/**
|
2018-05-24 17:11:18 +00:00
|
|
|
* Calculate a smoother percentage of interpolation of `x` between `min` and `max`.
|
2018-05-23 09:46:16 +00:00
|
|
|
*
|
2018-05-24 17:11:18 +00:00
|
|
|
* The function receives the number `x` as an argument and returns 0 if `x` is less than or equal to the left edge,
|
|
|
|
* 1 if `x` is greater than or equal to the right edge, and smoothly interpolates, using a Hermite polynomial,
|
|
|
|
* between 0 and 1 otherwise.
|
2018-05-23 09:46:16 +00:00
|
|
|
*
|
|
|
|
* Produces an even smoother interpolation than {@link Phaser.Math.SmoothStep}.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.SmootherStep
|
|
|
|
* @since 3.0.0
|
2018-05-24 17:11:18 +00:00
|
|
|
* @see {@link https://en.wikipedia.org/wiki/Smoothstep#Variations}
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-24 17:11:18 +00:00
|
|
|
* @param {number} x - The input value.
|
|
|
|
* @param {number} min - The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'.
|
|
|
|
* @param {number} max - The maximum value, also known as the 'right edge', assumed greater than the 'left edge'.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @return {number} The smoothly interpolated value.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2016-12-07 17:16:59 +00:00
|
|
|
var SmootherStep = function (x, min, max)
|
|
|
|
{
|
|
|
|
x = Math.max(0, Math.min(1, (x - min) / (max - min)));
|
|
|
|
|
|
|
|
return x * x * x * (x * (x * 6 - 15) + 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SmootherStep;
|