phaser/src/math/Clamp.js

25 lines
619 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
/**
2017-10-06 02:05:01 +00:00
* Force a value within the boundaries by clamping it to the range `min`, `max`.
*
* @function Phaser.Math.Clamp
* @since 3.0.0
*
* @param {number} value - The value to be clamped.
* @param {number} min - The minimum bounds.
* @param {number} max - The maximum bounds.
*
* @return {number} The clamped value.
*/
2017-09-21 13:26:18 +00:00
var Clamp = function (value, min, max)
{
2017-09-20 15:51:15 +00:00
return Math.max(min, Math.min(max, value));
};
module.exports = Clamp;