BLADEBURNER: Typesafety / refactoring (#1154)

This commit is contained in:
Snarling
2024-03-28 21:52:37 -04:00
committed by GitHub
parent 5f1a94a9d3
commit 6669c4da6a
79 changed files with 3876 additions and 5462 deletions
+10 -2
View File
@@ -2,14 +2,22 @@ import { CONSTANTS } from "../../Constants";
/**
* Clamps the value on a lower and an upper bound
* @param {number} value Value to clamp
* @param {number} min Lower bound, defaults to Number.MIN_VALUE
* @param {number} min Lower bound, defaults to negative Number.MAX_VALUE
* @param {number} max Upper bound, defaults to Number.MAX_VALUE
* @returns {number} Clamped value
*/
export function clampNumber(value: number, min = Number.MIN_VALUE, max = Number.MAX_VALUE) {
export function clampNumber(value: number, min = -Number.MAX_VALUE, max = Number.MAX_VALUE) {
if (isNaN(value)) {
if (CONSTANTS.isDevBranch) throw new Error("NaN passed into clampNumber()");
return min;
}
return Math.max(Math.min(value, max), min);
}
export function clampInteger(value: number, min = -Number.MAX_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
if (isNaN(value)) {
if (CONSTANTS.isDevBranch) throw new Error("NaN passed into clampInteger()");
return min;
}
return Math.round(Math.max(Math.min(value, max), min));
}