mapRange method
Maps this value from one range fromMin, fromMax to another toMin, toMax.
Example:
int value = 50;
double mapped = value.mapRange(fromMin: 0, fromMax: 100, toMin: 0.0, toMax: 1.0); // 0.5
Implementation
double mapRange({
required int fromMin,
required int fromMax,
required double toMin,
required double toMax,
}) {
if (fromMax == fromMin) return toMin;
final normalized = (this - fromMin) / (fromMax - fromMin);
return toMin + normalized * (toMax - toMin);
}