Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created October 21, 2022 21:47
Show Gist options
  • Save ruan65/d4478d2bc06bfce0661042688e97a359 to your computer and use it in GitHub Desktop.
Save ruan65/d4478d2bc06bfce0661042688e97a359 to your computer and use it in GitHub Desktop.
extension Normalize on num {
num normalized(
num selfRangeMin,
num selfRangeMax, [
num normalizedRangeMin = 0.0,
num normalizedRangeMax = 1.0,
]) =>
(normalizedRangeMax - normalizedRangeMin) *
((this - selfRangeMin) / (selfRangeMax - selfRangeMin)) +
normalizedRangeMin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment