diff --git a/src/user_inputs/axislike_settings.rs b/src/user_inputs/axislike_settings.rs index a5a0f5a2..ec786727 100644 --- a/src/user_inputs/axislike_settings.rs +++ b/src/user_inputs/axislike_settings.rs @@ -103,7 +103,7 @@ impl SingleAxisSettings { Self::new(sensitivity, SingleAxisDeadzone::DEFAULT) } - /// Creates a new [`SingleAxisSettings`] with the given settings. + /// Creates a new [`SingleAxisSettings`] with the given deadzone. pub const fn with_deadzone(deadzone: SingleAxisDeadzone) -> Self { Self::new(1.0, deadzone) } @@ -112,9 +112,9 @@ impl SingleAxisSettings { /// /// # Arguments /// - /// - `negative_low` - The lower limit for negative values. - pub fn with_negative_only(negative_low: f32) -> Self { - let deadzone = SingleAxisDeadzone::negative_only(negative_low); + /// - `negative_max` - The maximum limit for negative values. + pub fn with_negative_only(negative_max: f32) -> Self { + let deadzone = SingleAxisDeadzone::negative_only(negative_max); Self::new(1.0, deadzone) } @@ -122,9 +122,9 @@ impl SingleAxisSettings { /// /// # Arguments /// - /// - `positive_low` - The lower limit for positive values. - pub fn with_positive_only(positive_low: f32) -> Self { - let deadzone = SingleAxisDeadzone::positive_only(positive_low); + /// - `positive_min` - The minimum limit for positive values. + pub fn with_positive_only(positive_min: f32) -> Self { + let deadzone = SingleAxisDeadzone::positive_only(positive_min); Self::new(1.0, deadzone) } @@ -153,49 +153,49 @@ impl SingleAxisSettings { /// Deadzone settings for single-axis inputs. #[derive(Debug, Clone, PartialEq, Reflect, Serialize, Deserialize)] pub struct SingleAxisDeadzone { - /// The lower limit for negative values. - negative_low: f32, + /// The maximum limit for negative values. + negative_max: f32, - /// The lower limit for positive values. - positive_low: f32, + /// The minimum limit for positive values. + positive_min: f32, /// The width of the deadzone around the negative axis. /// - /// This value represents the absolute value of `negative_low`, + /// This value represents the absolute value of `negative_max`, /// reducing the performance cost of using `abs` during value computation. - negative_low_width: f32, + negative_deadzone_width: f32, } impl SingleAxisDeadzone { /// The default deadzone with a small offset to filter out near-zero input values. /// - /// This deadzone excludes input values within the range [-0.1, 0.1]. + /// This deadzone excludes input values within the range `[-0.1, 0.1]`. pub const DEFAULT: Self = Self { - negative_low: -0.1, - positive_low: 0.1, - negative_low_width: 0.1, + negative_max: -0.1, + positive_min: 0.1, + negative_deadzone_width: 0.1, }; /// The deadzone that only filters out the zeroes. /// - /// This deadzone does not filter out near-zero negative or positive values. + /// This deadzone doesn't filter out near-zero negative or positive values. pub const ZERO: Self = Self { - negative_low: 0.0, - positive_low: 0.0, - negative_low_width: 0.0, + negative_max: 0.0, + positive_min: 0.0, + negative_deadzone_width: 0.0, }; - /// Creates a new [`SingleAxisDeadzone`] with the given settings. + /// Creates a new [`SingleAxisDeadzone`] to filter out input values within the range `[negative_max, positive_min]`. /// /// # Arguments /// - /// - `negative_low` - The lower limit for negative values, clamped to `0.0` if greater than `0.0`. - /// - `positive_low` - The lower limit for positive values, clamped to `0.0` if less than `0.0`. - pub fn new(negative_low: f32, positive_low: f32) -> Self { + /// - `negative_max` - The maximum limit for negative values, clamped to `0.0` if greater than `0.0`. + /// - `positive_min` - The minimum limit for positive values, clamped to `0.0` if less than `0.0`. + pub fn new(negative_max: f32, positive_min: f32) -> Self { Self { - negative_low: negative_low.min(0.0), - positive_low: positive_low.max(0.0), - negative_low_width: negative_low.abs(), + negative_max: negative_max.min(0.0), + positive_min: positive_min.max(0.0), + negative_deadzone_width: negative_max.abs(), } } @@ -203,12 +203,12 @@ impl SingleAxisDeadzone { /// /// # Arguments /// - /// - `negative_low` - The lower limit for negative values, clamped to `0.0` if greater than `0.0`. - pub fn negative_only(negative_low: f32) -> Self { + /// - `negative_max` - The maximum limit for negative values, clamped to `0.0` if greater than `0.0`. + pub fn negative_only(negative_max: f32) -> Self { Self { - negative_low: negative_low.min(0.0), - positive_low: f32::MAX, - negative_low_width: negative_low.abs(), + negative_max: negative_max.min(0.0), + positive_min: f32::MAX, + negative_deadzone_width: negative_max.abs(), } } @@ -216,12 +216,12 @@ impl SingleAxisDeadzone { /// /// # Arguments /// - /// - `positive_low` - The lower limit for negative values, clamped to `0.0` if less than `0.0`. - pub fn positive_only(positive_low: f32) -> Self { + /// - `positive_min` - The minimum limit for negative values, clamped to `0.0` if less than `0.0`. + pub fn positive_only(positive_min: f32) -> Self { Self { - negative_low: f32::MIN, - positive_low: positive_low.max(0.0), - negative_low_width: f32::MAX, + negative_max: f32::MIN, + positive_min: positive_min.max(0.0), + negative_deadzone_width: f32::MAX, } } @@ -229,7 +229,7 @@ impl SingleAxisDeadzone { /// /// This function calculates the deadzone width based on the input value and the deadzone settings. /// If the input value falls within the deadzone range, it returns `0.0`. - /// Otherwise, it normalizes the input value into the range [-1.0, 1.0] by subtracting the deadzone width. + /// Otherwise, it normalizes the input value into the range `[-1.0, 1.0]` by subtracting the deadzone width. /// /// # Panics /// @@ -238,16 +238,16 @@ impl SingleAxisDeadzone { /// If this happens, you might be exploring the quantum realm! /// Consider offering your computer a cup of coffee and politely asking for a less mysterious explanation. pub fn apply_deadzone(&self, input_value: f32) -> f32 { - let is_negative_active = self.negative_low > input_value; - let is_positive_active = self.positive_low < input_value; + let is_negative_active = self.negative_max > input_value; + let is_positive_active = self.positive_min < input_value; let deadzone_width = match (is_negative_active, is_positive_active) { // The input value is within the deadzone and falls back to `0.0` (false, false) => return 0.0, // The input value is outside the negative deadzone range - (true, false) => self.negative_low_width, + (true, false) => self.negative_deadzone_width, // The input value is outside the positive deadzone range - (false, true) => self.positive_low, + (false, true) => self.positive_min, // This case must never be reached. // Unless you've discovered the elusive quantum deadzone! // Please check your quantum computer and contact the Rust Team. @@ -278,8 +278,8 @@ impl Eq for SingleAxisDeadzone {} impl std::hash::Hash for SingleAxisDeadzone { fn hash(&self, state: &mut H) { - FloatOrd(self.negative_low).hash(state); - FloatOrd(self.positive_low).hash(state); - FloatOrd(self.negative_low_width).hash(state); + FloatOrd(self.negative_max).hash(state); + FloatOrd(self.positive_min).hash(state); + FloatOrd(self.negative_deadzone_width).hash(state); } }