mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Add Math.clamp utility function
This commit is contained in:
parent
5268cb62a6
commit
adab416847
1 changed files with 17 additions and 0 deletions
|
|
@ -330,3 +330,20 @@ Math.euclidDistance3D = function(x1, y1, z1, x2, y2, z2)
|
|||
{
|
||||
return Math.sqrt(Math.euclidDistance3DSquared(x1, y1, z1, x2, y2, z2));
|
||||
};
|
||||
|
||||
/**
|
||||
* Clamps a value between a minimum and maximum range.
|
||||
*
|
||||
* @param {number} value - The value to clamp
|
||||
* @param {number} min - Minimum allowed value
|
||||
* @param {number} max - Maximum allowed value
|
||||
* @returns {number} The clamped value (min <= result <= max)
|
||||
*/
|
||||
Math.clamp = function(value, min, max)
|
||||
{
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue