11 lines
No EOL
338 B
TypeScript
11 lines
No EOL
338 B
TypeScript
|
|
export function mapNumber(value: number, fromMin: number, fromMax: number, toMin: number, toMax: number): number {
|
|
if (value <= fromMin) return toMin;
|
|
if (value >= fromMax) return toMax;
|
|
|
|
const absFromMax = fromMax - fromMin;
|
|
const absToMax = toMax - toMin;
|
|
|
|
const mapped = (value / absFromMax) * absToMax;
|
|
return mapped + toMin;
|
|
} |