baublet/w8mngr

View on GitHub
shared/weightedClamp.ts

Summary

Maintainability
A
0 mins
Test Coverage
export function weightedClamp({
  setValue,
  max,
  min,
  setMax,
}: {
  setValue: number;
  max: number;
  min: number;
  setMax: number;
}): number {
  const oldRange = setMax - min;
  const newRange = max - min;
  const newValue = ((setValue - min) * newRange) / oldRange + min;

  return newValue;
}