mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Adding in the start of the Math functions.
This commit is contained in:
parent
2b3127c405
commit
ff5273d01c
2 changed files with 40 additions and 0 deletions
26
v3/src/math/Clamp.js
Normal file
26
v3/src/math/Clamp.js
Normal 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;
|
14
v3/src/math/IsPowerOfTwo.js
Normal file
14
v3/src/math/IsPowerOfTwo.js
Normal 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;
|
Loading…
Add table
Reference in a new issue