Skip to content

Commit

Permalink
Avoid redundant clamping of values
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Aug 14, 2023
1 parent 7ba1a11 commit c48371e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[package]
name = "djio"
description = "DJ Hardware Control(ler) Support"
version = "0.0.7"
version = "0.0.8"
license = "MPL-2.0"
readme = "README.md"
repository = "https://github.com/uklotzde/djio"
Expand Down
18 changes: 10 additions & 8 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ pub fn split_crossfader_input_linear(input: CenterSliderInput) -> (SliderInput,
}
let CenterSliderInput { position } = input;
let x = position * 0.5 + 0.5; // [0, 1]
let left_position = f_x(1.0 - x).max(0.0).min(1.0);
let right_position = f_x(x).max(0.0).min(1.0);
let left_position = f_x(1.0 - x);
let right_position = f_x(x);
debug_assert!(SliderInput::POSITION_RANGE.contains(&left_position));
debug_assert!(SliderInput::POSITION_RANGE.contains(&right_position));
(
SliderInput {
position: left_position,
Expand All @@ -440,8 +442,8 @@ pub fn split_crossfader_input_amplitude_preserving_approx(
}
let CenterSliderInput { position } = input;
let x: f64 = f64::from(position) * 0.5 + 0.5; // [0, 1]
let left_position = f_x(1.0 - x).max(0.0).min(1.0);
let right_position = f_x(x).max(0.0).min(1.0);
let left_position = f_x(1.0 - x);
let right_position = f_x(x);
(
SliderInput {
position: SliderInput::clamp_position(left_position),
Expand All @@ -464,8 +466,8 @@ pub fn split_crossfader_input_energy_preserving_approx(
}
let CenterSliderInput { position } = input;
let x = f64::from(position) * 0.5 + 0.5; // [0, 1]
let left_position = f_x(1.0 - x).max(0.0).min(1.0);
let right_position = f_x(x).max(0.0).min(1.0);
let left_position = f_x(1.0 - x);
let right_position = f_x(x);
(
SliderInput {
position: SliderInput::clamp_position(left_position),
Expand All @@ -491,10 +493,10 @@ pub fn split_crossfader_input_square(input: CenterSliderInput) -> (SliderInput,
};
(
SliderInput {
position: SliderInput::clamp_position(left_position),
position: left_position,
},
SliderInput {
position: SliderInput::clamp_position(right_position),
position: right_position,
},
)
}
Expand Down

0 comments on commit c48371e

Please sign in to comment.