map static method

double map(
  1. double srcValue,
  2. double srcMin,
  3. double srcMax,
  4. double dstMin,
  5. double dstMax,
)

Maps a value from one range to another.

Given a srcValue, srcMin, srcMax, dstMin, and dstMax, maps the srcValue from the srcMin-srcMax range to the dstMin-dstMax range.

Example:

final srcValue = 50;
final srcMin = 0;
final srcMax = 100;
final dstMin = 0;
final dstMax = 255;
final mappedValue = Math.map(srcValue, srcMin, srcMax, dstMin, dstMax);
print(mappedValue); // 127.5

Implementation

@pragma("vm:prefer-inline")
static double map(
  double srcValue,
  double srcMin,
  double srcMax,
  double dstMin,
  double dstMax,
) {
  final norm = Math.norm(srcValue, srcMin, srcMax);
  return Math.lerp(dstMin, dstMax, norm);
}