scaleBetween method

num scaleBetween(
  1. num min,
  2. num max
)

Normalizes this number to a range between min and max.

Returns a value between 0 and 1 representing where this value falls in the range from min to max.

Throws ArgumentError if min equals max or if min > max.

Implementation

num scaleBetween(num min, num max) {
  if (min == max) {
    throw ArgumentError('Min and max cannot be the same.');
  }
  if (min > max) {
    throw ArgumentError('Min cannot be greater than max.');
  }
  return (this - min) / (max - min);
}