Newtonian

Struct Newtonian 

Source
pub struct Newtonian {
    pub speed_limit: [f32; 2],
    pub acceleration: [f32; 2],
    pub deceleration: [f32; 2],
    pub goal: f32,
    pub value: f32,
    pub time: u64,
    pub enabled: bool,
    /* private fields */
}
Expand description

A modulator that uses classical mechanics to move to its goal - it guarantees smooth acceleration, deceleration and speed limiting regardless of settings.

The goal calculation computes an analytical solution to the motion equation. When a new goal is set, speed_limit, acceleration and deceleration values are picked from their respective ranges, then movement begins with the value starting from current value with 0 velocity, accelerating at the selected rate up to the speed limit, then decelerating at the selected rate of deceleration so that it is guaranteed to come to a stop at the goal.

The analytical solution to the motion equation ensures that, regardless of input, the value always accelerates and decelerates at the picked rates, and never exceeds the speed max. If there is not enough time to reach peak speed, the value accelerates as much as it it can while ensuring that it will decelerate and come to a stop (0 speed) exactly at goal.

Fields§

§speed_limit: [f32; 2]

Max speed range, selected on new goal

§acceleration: [f32; 2]

range of acceleration values selected on new goal

§deceleration: [f32; 2]

range of deceleration values selected on new goal

§goal: f32§value: f32§time: u64

Accumulated microseconds since the most recent goal was set

§enabled: bool

Enabling toggle

Implementations§

Source§

impl Newtonian

Source

pub fn new( speed_limit: [f32; 2], acceleration: [f32; 2], deceleration: [f32; 2], initial: f32, ) -> Self

Make a Newtonian mechanics value moving modulator

Source

pub fn reset(&mut self, value: f32)

Manual reset of the current value - also ends all motion

Source

pub fn move_to(&mut self, goal: f32)

Start moving from the current value to the given goal

Trait Implementations§

Source§

impl Modulator<f32> for Newtonian

Source§

fn value(&self) -> f32

Value of the modulator at the current time.
Source§

fn goal(&self) -> Option<f32>

Current goal of the modulator, or None if not applicable.
Source§

fn set_goal(&mut self, goal: f32)

Set a goal for the modulator to move towards, if possible.
Source§

fn elapsed_us(&self) -> u64

Total accumulated microseconds for the modulator.
Source§

fn enabled(&self) -> bool

Check if the modulator is disabled
Source§

fn set_enabled(&mut self, enabled: bool)

Toggle enabling/disabling the modulator
Source§

fn advance(&mut self, dt: u64)

Move the modulator ahead by dt microseconds.
Source§

fn as_any(&mut self) -> &mut dyn Any

Allow donwcasting.
Source§

fn range(&self) -> Option<[T; 2]>

Range of the modulator as min..=max, or None if the range is indeterminate.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V