From d7929920c9326ef27ffba6510036e14a5f533978 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 25 Jan 2022 22:26:38 +0100 Subject: [PATCH] Add rounding to integer ranges --- nih_plug/src/params.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nih_plug/src/params.rs b/nih_plug/src/params.rs index 11e29618..3558c94a 100644 --- a/nih_plug/src/params.rs +++ b/nih_plug/src/params.rs @@ -140,7 +140,7 @@ impl NormalizebleRange for Range { 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); + } }