Skip to content

Commit 424b5d7

Browse files
committed
Added SmootherStep interpolation function.
1 parent 603483e commit 424b5d7

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/math/interpolation/LinearInterpolation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var Linear = require('../Linear');
1111
*
1212
* @function Phaser.Math.Interpolation.Linear
1313
* @since 3.0.0
14-
* @see https://en.wikipedia.org/wiki/Linear_interpolation
14+
* @see {@link https://en.wikipedia.org/wiki/Linear_interpolation}
1515
*
1616
* @param {number[]} v - The input array of values to interpolate between.
1717
* @param {!number} k - The percentage of interpolation, between 0 and 1.

src/math/interpolation/SmoothStepInterpolation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var SmoothStep = require('../SmoothStep');
1111
*
1212
* @function Phaser.Math.Interpolation.SmoothStep
1313
* @since 3.9.0
14-
* @see https://en.wikipedia.org/wiki/Smoothstep
14+
* @see {@link https://en.wikipedia.org/wiki/Smoothstep}
1515
*
1616
* @param {number} x - The input value.
1717
* @param {number} min - The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var SmootherStep = require('../SmootherStep');
8+
9+
/**
10+
* A Smoother Step interpolation method.
11+
*
12+
* @function Phaser.Math.Interpolation.SmootherStep
13+
* @since 3.9.0
14+
* @see {@link https://en.wikipedia.org/wiki/Smoothstep#Variations}
15+
*
16+
* @param {number} x - The input value.
17+
* @param {number} min - The minimum value, also known as the 'left edge', assumed smaller than the 'right edge'.
18+
* @param {number} max - The maximum value, also known as the 'right edge', assumed greater than the 'left edge'.
19+
*
20+
* @return {number} The interpolated value.
21+
*/
22+
var SmootherStepInterpolation = function (x, min, max)
23+
{
24+
var t = SmootherStep(x, min, max);
25+
26+
return (max - min) * t + min;
27+
};
28+
29+
module.exports = SmootherStepInterpolation;

src/math/interpolation/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
CubicBezier: require('./CubicBezierInterpolation'),
1616
Linear: require('./LinearInterpolation'),
1717
QuadraticBezier: require('./QuadraticBezierInterpolation'),
18-
SmoothStep: require('./SmoothStepInterpolation')
18+
SmoothStep: require('./SmoothStepInterpolation'),
19+
SmootherStep: require('./SmootherStepInterpolation')
1920

2021
};

0 commit comments

Comments
 (0)