1
0
Fork 0

Add rounding to integer ranges

This commit is contained in:
Robbert van der Helm 2022-01-25 22:26:38 +01:00
parent 3c950d98d4
commit d7929920c9

View file

@ -140,7 +140,7 @@ impl NormalizebleRange<i32> for Range<i32> {
fn unnormalize(&self, normalized: f32) -> i32 {
match &self {
Range::Linear { min, max } => (normalized * (max - min) as f32) as i32 + min,
Range::Linear { min, max } => (normalized * (max - min) as f32).round() as i32 + min,
}
}
}
@ -263,4 +263,10 @@ mod tests {
let range = make_linear_int_range();
assert_eq!(range.unnormalize(0.75), 5);
}
#[test]
fn range_unnormalize_linear_int_rounding() {
let range = make_linear_int_range();
assert_eq!(range.unnormalize(0.73), 5);
}
}