mirror of
https://github.com/photonstorm/phaser
synced 2024-12-24 12:03:36 +00:00
cbf3957a33
`FromPercent` silently assumed `min` to be 0. Shifting the result by `min` makes it work as documented and gives a value between `min` and `max`. Our uses of `FromPercent` only have `min` at 0, so there is no regression in our code. This is merely a fix for 3rd party users.
28 lines
779 B
JavaScript
28 lines
779 B
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2020 Photon Storm Ltd.
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
*/
|
|
|
|
var Clamp = require('./Clamp');
|
|
|
|
/**
|
|
* Return a value based on the range between `min` and `max` and the percentage given.
|
|
*
|
|
* @function Phaser.Math.FromPercent
|
|
* @since 3.0.0
|
|
*
|
|
* @param {number} percent - A value between 0 and 1 representing the percentage.
|
|
* @param {number} min - The minimum value.
|
|
* @param {number} [max] - The maximum value.
|
|
*
|
|
* @return {number} The value that is `percent` percent between `min` and `max`.
|
|
*/
|
|
var FromPercent = function (percent, min, max)
|
|
{
|
|
percent = Clamp(percent, 0, 1);
|
|
|
|
return (max - min) * percent + min;
|
|
};
|
|
|
|
module.exports = FromPercent;
|