Files
Edouard Marquez dbd23f50f8 feat: Guide for Nutri-Score V2 (#5273)
* Guide for Nutriscore V2

* Revert some code
2024-05-21 13:04:45 +02:00

22 lines
754 B
Dart

extension DoubleExtension on double {
/// Returns the progress of the current value between [min] and [max].
/// /!\ May return < 0 or > 1 values, use [progressAndClamp] if you want to limit the output.
/// Eg: 5.progress(0, 10) => 0.5
/// Eg: -1.progress(0, 5) => -0.2
double progress(num min, num max) {
return (this - min) / (max - min);
}
/// Returns the progress of the current value between [min] and [max].
/// The minimum value will always be 0 and the maximum value will always be [clamp].
double progressAndClamp(num min, double max, double clamp) {
return progress(min, max).clamp(0.0, clamp);
}
}
extension IntExtension on int {
double progress(int min, int max) {
return (this - min) / (max - min);
}
}