Add dedicated single step next() to SmoothingStyle
This avoids some computations for single stepping. And we can use this for block smoothing later.
This commit is contained in:
parent
e47899d421
commit
dd320c4c1f
1 changed files with 19 additions and 1 deletions
|
@ -64,7 +64,9 @@ pub struct SmootherIter<'a, T> {
|
|||
}
|
||||
|
||||
impl SmoothingStyle {
|
||||
/// Compute the step size for this smoother.
|
||||
/// Compute the step size for this smoother. Check the source code of the
|
||||
/// [`SmoothingStyle::next()`] and [`SmoothingStyle::next_step()`] functions for details on how
|
||||
/// these values should be used.
|
||||
#[inline]
|
||||
pub fn step_size(&self, current: f32, target: f32, steps_left: u32) -> f32 {
|
||||
nih_debug_assert!(steps_left >= 1);
|
||||
|
@ -86,6 +88,22 @@ impl SmoothingStyle {
|
|||
}
|
||||
}
|
||||
|
||||
/// Compute the next value from `current` leading up to `target` using the `step_size` computed
|
||||
/// using [`SmoothingStyle::step_size()`]. Depending on the smoothing style this function may
|
||||
/// never completely reach `target`, so you will need to snap to `target` yourself after
|
||||
/// cmoputing the target number of steps.
|
||||
///
|
||||
/// See the docstring on the [`SmoothingStyle::next_step()`] function for the formulas used.
|
||||
#[inline]
|
||||
pub fn next(&self, current: f32, target: f32, step_size: f32) -> f32 {
|
||||
match self {
|
||||
SmoothingStyle::None => target,
|
||||
SmoothingStyle::Linear(_) => current + step_size,
|
||||
SmoothingStyle::Logarithmic(_) => current * step_size,
|
||||
SmoothingStyle::Exponential(_) => (current * step_size) + (target * (1.0 - step_size)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The same as [`next()`][Self::next()], but with the option to take more than one step at a
|
||||
/// time. Calling `next_step()` with step count `n` gives the same result as applying `next()`
|
||||
/// `n` times to a value, but is more efficient to compute. `next_step()` with 1 step is
|
||||
|
|
Loading…
Add table
Reference in a new issue