Skip to main content

SpringDescription

Struct SpringDescription 

Source
pub struct SpringDescription {
    pub mass: f64,
    pub stiffness: f64,
    pub damping: f64,
}
Expand description

Structure that describes a spring’s constants.

Used to configure a SpringSimulation.

Fields§

§mass: f64

The mass of the spring (m).

The units are arbitrary, but all springs within a system should use the same mass units.

The greater the mass, the larger the amplitude of oscillation, and the longer the time to return to the equilibrium position.

§stiffness: f64

The spring constant (k).

The units of stiffness are M/T², where M is the mass unit used for the value of the mass property, and T is the time unit used for driving the SpringSimulation.

Stiffness defines the spring constant, which measures the strength of the spring. A stiff spring applies more force to the object that is attached for some deviation from the rest position.

§damping: f64

The damping coefficient (c).

It is a pure number without physical meaning and describes the oscillation and decay of a system after being disturbed. The larger the damping, the fewer oscillations and smaller the amplitude of the elastic motion.

Do not confuse the damping coefficient (c) with the damping ratio (ζ). To create a SpringDescription with a damping ratio, use with_damping_ratio.

The units of the damping coefficient are M/T, where M is the mass unit used for the value of the mass property, and T is the time unit used for driving the SpringSimulation.

Implementations§

Source§

impl SpringDescription

Source

pub const fn new(mass: f64, stiffness: f64, damping: f64) -> SpringDescription

Creates a spring given the mass, stiffness, and the damping coefficient.

See mass, stiffness, and damping for the units of the arguments.

Source

pub fn with_damping_ratio(mass: f64, stiffness: f64) -> SpringDescription

Creates a spring given the mass (m), stiffness (k), and damping ratio (ζ). The damping ratio describes a gradual reduction in a spring oscillation. By using the damping ratio, you can define how rapidly the oscillations decay from one bounce to the next.

The damping ratio is especially useful when trying to determining the type of spring to create. A ratio of 1.0 creates a critically damped spring, > 1.0 creates an overdamped spring and < 1.0 an underdamped one.

See mass and stiffness for the units for those arguments. The damping ratio is unitless.

Source

pub fn with_damping_ratio_value( mass: f64, stiffness: f64, ratio: f64, ) -> SpringDescription

Dart’s withDampingRatio ratio argument (default 1.0).

Source

pub fn with_duration_and_bounce( duration: Duration, bounce: f64, ) -> SpringDescription

Creates a SpringDescription based on a desired animation duration and bounce.

This provides an intuitive way to define a spring based on its visual properties, duration and bounce.

This constructor produces the same result as SwiftUI’s spring(duration:bounce:blendDuration:) animation.

Source

pub fn duration(&self) -> Duration

The duration parameter used in with_duration_and_bounce.

This value defines the perceptual duration of the spring, controlling its overall pace. It is approximately equal to the time it takes for the spring to settle, but for highly bouncy springs, it instead corresponds to the oscillation period.

This duration does not represent the exact time for the spring to stop moving. For example, when bounce is 1, the spring oscillates indefinitely, even though duration has a finite value. To determine when the motion has effectively stopped within a certain tolerance, use SpringSimulation::is_done.

Defaults to 0.5 seconds.

Source

pub fn bounce(&self) -> f64

The bounce parameter used in with_duration_and_bounce.

This value controls how bouncy the spring is:

  • A value of 0 results in a critically damped spring with no oscillation.
  • Values between 0 and 1 produce underdamping, where the spring oscillates a few times before settling. A value of 1 represents an undamped spring that oscillates indefinitely.
  • Negative values indicate overdamping, where the motion is slow and resistive, like moving through a thick fluid.

Defaults to 0.

Trait Implementations§

Source§

impl Clone for SpringDescription

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SpringDescription

Source§

impl Debug for SpringDescription

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,