Begin more math boltons

This commit is contained in:
jordan4ibanez 2024-04-19 03:52:16 -04:00
parent c9d3fea3ce
commit 147e8345c3

View File

@ -1,6 +1,13 @@
namespace utility {
const floor = math.floor;
const PI = math.pi;
const PI_HALF = math.pi / 2;
const PI2 = math.pi * 2;
const random = math.random;
export function randomRange(min: number, max: number): number {
return (math.random() * (max - min) + min);
return (random() * (max - min) + min);
}
/**
@ -19,4 +26,32 @@ namespace utility {
return input;
};
/**
* Truncate (cast float to int) a floating point value.
* @param floating A floating point value.
* @returns A truncated (casted to int) value. As close as you can get in lua.
*/
math.truncate = function (floating: number): number {
return math.floor(floating * 10) / 10;
};
math.cosFromSin = function (sin: number, angle: number): number {
//if (Options.FASTMATH){
// return math_sin(angle + PIHalf);
// }
// sin(x)^2 + cos(x)^2 = 1
let cos: number = math.sqrt(1.0 - sin * sin);
let a: number = angle + PI_HALF;
let b: number = a - floor(a / PI2) * PI2;
if (b < 0.0)
b = PI2 + b;
if (b >= PI)
return -cos;
return cos;
};
}