Adding in the start of the Math functions.

This commit is contained in:
photonstorm 2016-12-06 16:18:12 +00:00
parent 2b3127c405
commit ff5273d01c
2 changed files with 40 additions and 0 deletions

26
v3/src/math/Clamp.js Normal file
View file

@ -0,0 +1,26 @@
/**
* 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;

View file

@ -0,0 +1,14 @@
/**
* Checks if the given dimensions make a power of two texture.
*
* @method Phaser.Math#isPowerOfTwo
* @param {number} width - The width to check.
* @param {number} height - The height to check.
* @return {boolean} True if the width and height are a power of two.
*/
var IsPowerOfTwo = function (width, height)
{
return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
};
module.exports = isPowerOfTwo;