mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
19 lines
557 B
TypeScript
19 lines
557 B
TypeScript
// round value to n decimals
|
|
export function rn(value: number, decimals: number = 0) {
|
|
const multiplier = Math.pow(10, decimals);
|
|
return Math.round(value * multiplier) / multiplier;
|
|
}
|
|
|
|
export function minmax(value: number, min: number, max: number) {
|
|
return Math.min(Math.max(value, min), max);
|
|
}
|
|
|
|
// return value clamped to [0, 100]
|
|
export function lim(value: number) {
|
|
return minmax(value, 0, 100);
|
|
}
|
|
|
|
// normalization function
|
|
export function normalize(val: number, min: number, max: number) {
|
|
return minmax((val - min) / (max - min), 0, 1);
|
|
}
|