Skip to content

Commit 1f948d8

Browse files
author
Gaëtan Renaudeau
committed
Fix phaserjs#771: make smoothstep(x,a,b) work if a > b
1 parent f12168a commit 1f948d8

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

src/math/Math.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,18 +1265,7 @@ Phaser.Math = {
12651265
*/
12661266
smoothstep: function ( x, min, max ) {
12671267

1268-
if (x <= min)
1269-
{
1270-
return 0;
1271-
}
1272-
1273-
if (x >= max)
1274-
{
1275-
return 1;
1276-
}
1277-
1278-
x = (x - min) / (max - min);
1279-
1268+
x = Math.max(0, Math.min(1, (x - min) / (max - min)));
12801269
return x * x * (3 - 2 * x);
12811270

12821271
},
@@ -1292,18 +1281,7 @@ Phaser.Math = {
12921281
*/
12931282
smootherstep: function ( x, min, max ) {
12941283

1295-
if (x <= min)
1296-
{
1297-
return 0;
1298-
}
1299-
1300-
if (x >= max)
1301-
{
1302-
return 1;
1303-
}
1304-
1305-
x = (x - min) / (max - min);
1306-
1284+
x = Math.max(0, Math.min(1, (x - min) / (max - min)));
13071285
return x * x * x * (x * (x * 6 - 15) + 10);
13081286

13091287
},

0 commit comments

Comments
 (0)