phaser/src/math/Clamp.js

25 lines
645 B
JavaScript
Raw Normal View History

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 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;