mirror of
https://github.com/photonstorm/phaser
synced 2024-12-24 20:13:35 +00:00
27 lines
494 B
JavaScript
27 lines
494 B
JavaScript
|
/**
|
||
|
* Force a value within the boundaries by clamping it to the range `min`, `max`.
|
||
|
*
|
||
|
* @method Phaser.Math#clamp
|
||
|
* @param {float} v - The value to be clamped.
|
||
|
* @param {float} min - The minimum bounds.
|
||
|
* @param {float} max - The maximum bounds.
|
||
|
* @return {number} The clamped value.
|
||
|
*/
|
||
|
var Clamp = function (v, min, max)
|
||
|
{
|
||
|
if (v < min)
|
||
|
{
|
||
|
return min;
|
||
|
}
|
||
|
else if (max < v)
|
||
|
{
|
||
|
return max;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return v;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
module.exports = Clamp;
|