Skip to main content

EaseFunction

Enum EaseFunction 

Source
#[non_exhaustive]
pub enum EaseFunction {
Show 39 variants Linear, QuadraticIn, QuadraticOut, QuadraticInOut, CubicIn, CubicOut, CubicInOut, QuarticIn, QuarticOut, QuarticInOut, QuinticIn, QuinticOut, QuinticInOut, SmoothStepIn, SmoothStepOut, SmoothStep, SmootherStepIn, SmootherStepOut, SmootherStep, SineIn, SineOut, SineInOut, CircularIn, CircularOut, CircularInOut, ExponentialIn, ExponentialOut, ExponentialInOut, ElasticIn, ElasticOut, ElasticInOut, BackIn, BackOut, BackInOut, BounceIn, BounceOut, BounceInOut, Steps(usize, JumpAt), Elastic(f32),
}
Expand description

Curve functions over the unit interval, commonly used for easing transitions.

EaseFunction can be used on its own to interpolate between 0.0 and 1.0. It can also be combined with EasingCurve to interpolate between other intervals and types, including vectors and rotations.

§Example

sample the smoothstep function at various points. This will return None if the parameter is outside the unit interval.

let f = EaseFunction::SmoothStep;

assert_eq!(f.sample(-1.0), None);
assert_eq!(f.sample(0.0), Some(0.0));
assert_eq!(f.sample(0.5), Some(0.5));
assert_eq!(f.sample(1.0), Some(1.0));
assert_eq!(f.sample(2.0), None);

sample_clamped will clamp the parameter to the unit interval, so it always returns a value.

assert_eq!(f.sample_clamped(-1.0), 0.0);
assert_eq!(f.sample_clamped(0.0), 0.0);
assert_eq!(f.sample_clamped(0.5), 0.5);
assert_eq!(f.sample_clamped(1.0), 1.0);
assert_eq!(f.sample_clamped(2.0), 1.0);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Linear

f(t) = t

Linear
§

QuadraticIn

f(t) = t²

This is the Hermite interpolator for

  • f(0) = 0
  • f(1) = 1
  • f′(0) = 0
QuadraticIn
§

QuadraticOut

f(t) = -(t * (t - 2.0))

This is the Hermite interpolator for

  • f(0) = 0
  • f(1) = 1
  • f′(1) = 0
QuadraticOut
§

QuadraticInOut

Behaves as EaseFunction::QuadraticIn for t < 0.5 and as EaseFunction::QuadraticOut for t >= 0.5

A quadratic has too low of a degree to be both an InOut and C², so consider using at least a cubic (such as EaseFunction::SmoothStep) if you want the acceleration to be continuous.

QuadraticInOut
§

CubicIn

f(t) = t³

This is the Hermite interpolator for

  • f(0) = 0
  • f(1) = 1
  • f′(0) = 0
  • f″(0) = 0
CubicIn
§

CubicOut

f(t) = (t - 1.0)³ + 1.0

CubicOut
§

CubicInOut

Behaves as EaseFunction::CubicIn for t < 0.5 and as EaseFunction::CubicOut for t >= 0.5

Due to this piecewise definition, this is only C¹ despite being a cubic: the acceleration jumps from +12 to -12 at t = ½.

Consider using EaseFunction::SmoothStep instead, which is also cubic, or EaseFunction::SmootherStep if you picked this because you wanted the acceleration at the endpoints to also be zero.

CubicInOut
§

QuarticIn

f(t) = t⁴

QuarticIn
§

QuarticOut

f(t) = 1.0 - (1.0 - t)⁴

QuarticOut
§

QuarticInOut

Behaves as EaseFunction::QuarticIn for t < 0.5 and as EaseFunction::QuarticOut for t >= 0.5

QuarticInOut
§

QuinticIn

f(t) = t⁵

QuinticIn
§

QuinticOut

f(t) = (t - 1.0)⁵ + 1.0

QuinticOut
§

QuinticInOut

Behaves as EaseFunction::QuinticIn for t < 0.5 and as EaseFunction::QuinticOut for t >= 0.5

Due to this piecewise definition, this is only C¹ despite being a quintic: the acceleration jumps from +40 to -40 at t = ½.

Consider using EaseFunction::SmootherStep instead, which is also quintic.

QuinticInOut
§

SmoothStepIn

Behaves as the first half of EaseFunction::SmoothStep.

This has f″(1) = 0, unlike EaseFunction::QuadraticIn which starts similarly.

SmoothStepIn
§

SmoothStepOut

Behaves as the second half of EaseFunction::SmoothStep.

This has f″(0) = 0, unlike EaseFunction::QuadraticOut which ends similarly.

SmoothStepOut
§

SmoothStep

f(t) = 3t² - 2t³

This is the Hermite interpolator for

  • f(0) = 0
  • f(1) = 1
  • f′(0) = 0
  • f′(1) = 0

See also smoothstep in GLSL.

SmoothStep
§

SmootherStepIn

Behaves as the first half of EaseFunction::SmootherStep.

This has f″(1) = 0, unlike EaseFunction::CubicIn which starts similarly.

SmootherStepIn
§

SmootherStepOut

Behaves as the second half of EaseFunction::SmootherStep.

This has f″(0) = 0, unlike EaseFunction::CubicOut which ends similarly.

SmootherStepOut
§

SmootherStep

f(t) = 6t⁵ - 15t⁴ + 10t³

This is the Hermite interpolator for

  • f(0) = 0
  • f(1) = 1
  • f′(0) = 0
  • f′(1) = 0
  • f″(0) = 0
  • f″(1) = 0
SmootherStep
§

SineIn

f(t) = 1.0 - cos(t * π / 2.0)

SineIn
§

SineOut

f(t) = sin(t * π / 2.0)

SineOut
§

SineInOut

Behaves as EaseFunction::SineIn for t < 0.5 and as EaseFunction::SineOut for t >= 0.5

SineInOut
§

CircularIn

f(t) = 1.0 - sqrt(1.0 - t²)

CircularIn
§

CircularOut

f(t) = sqrt((2.0 - t) * t)

CircularOut
§

CircularInOut

Behaves as EaseFunction::CircularIn for t < 0.5 and as EaseFunction::CircularOut for t >= 0.5

CircularInOut
§

ExponentialIn

f(t) ≈ 2.0^(10.0 * (t - 1.0))

The precise definition adjusts it slightly so it hits both (0, 0) and (1, 1): f(t) = 2.0^(10.0 * t - A) - B, where A = log₂(2¹⁰-1) and B = 1/(2¹⁰-1).

ExponentialIn
§

ExponentialOut

f(t) ≈ 1.0 - 2.0^(-10.0 * t)

As with EaseFunction::ExponentialIn, the precise definition adjusts it slightly so it hits both (0, 0) and (1, 1).

ExponentialOut
§

ExponentialInOut

Behaves as EaseFunction::ExponentialIn for t < 0.5 and as EaseFunction::ExponentialOut for t >= 0.5

ExponentialInOut
§

ElasticIn

f(t) = -2.0^(10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * 2.0 * π / 3.0)

ElasticIn
§

ElasticOut

f(t) = 2.0^(-10.0 * t) * sin((t * 10.0 - 0.75) * 2.0 * π / 3.0) + 1.0

ElasticOut
§

ElasticInOut

Behaves as EaseFunction::ElasticIn for t < 0.5 and as EaseFunction::ElasticOut for t >= 0.5

ElasticInOut
§

BackIn

f(t) = 2.70158 * t³ - 1.70158 * t²

BackIn
§

BackOut

f(t) = 1.0 + 2.70158 * (t - 1.0)³ + 1.70158 * (t - 1.0)²

BackOut
§

BackInOut

Behaves as EaseFunction::BackIn for t < 0.5 and as EaseFunction::BackOut for t >= 0.5

BackInOut
§

BounceIn

bouncy at the start!

BounceIn
§

BounceOut

bouncy at the end!

BounceOut
§

BounceInOut

Behaves as EaseFunction::BounceIn for t < 0.5 and as EaseFunction::BounceOut for t >= 0.5

BounceInOut
§

Steps(usize, JumpAt)

n steps connecting the start and the end. Jumping behavior is customizable via JumpAt. See JumpAt for all the options and visual examples.

§

Elastic(f32)

f(omega,t) = 1 - (1 - t)²(2sin(omega * t) / omega + cos(omega * t)), parametrized by omega

Elastic(50.0)

Trait Implementations§

Source§

impl Clone for EaseFunction

Source§

fn clone(&self) -> EaseFunction

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 EaseFunction

Source§

impl Curve<f32> for EaseFunction

Source§

fn domain(&self) -> Interval

The interval over which this curve is parametrized. Read more
Source§

fn sample_unchecked(&self, t: f32) -> f32

Sample a point on this curve at the parameter value t, extracting the associated value. This is the unchecked version of sampling, which should only be used if the sample time t is already known to lie within the curve’s domain. Read more
Source§

fn sample(&self, t: f32) -> Option<T>

Sample a point on this curve at the parameter value t, returning None if the point is outside of the curve’s domain.
Source§

fn sample_clamped(&self, t: f32) -> T

Sample a point on this curve at the parameter value t, clamping t to lie inside the domain of the curve.
Source§

impl Debug for EaseFunction

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for EaseFunction

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for EaseFunction

Source§

fn eq(&self, other: &EaseFunction) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for EaseFunction

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for EaseFunction

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> 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<C, T> CurveExt<T> for C
where C: Curve<T>,

Source§

fn sample_iter( &self, iter: impl IntoIterator<Item = f32>, ) -> impl Iterator<Item = Option<T>>

Sample a collection of n >= 0 points on this curve at the parameter values t_n, returning None if the point is outside of the curve’s domain. Read more
Source§

fn sample_iter_unchecked( &self, iter: impl IntoIterator<Item = f32>, ) -> impl Iterator<Item = T>

Sample a collection of n >= 0 points on this curve at the parameter values t_n, extracting the associated values. This is the unchecked version of sampling, which should only be used if the sample times t_n are already known to lie within the curve’s domain. Read more
Source§

fn sample_iter_clamped( &self, iter: impl IntoIterator<Item = f32>, ) -> impl Iterator<Item = T>

Sample a collection of n >= 0 points on this curve at the parameter values t_n, clamping t_n to lie inside the domain of the curve. Read more
Source§

fn map<S, F>(self, f: F) -> MapCurve<T, S, Self, F>
where F: Fn(T) -> S,

Create a new curve by mapping the values of this curve via a function f; i.e., if the sample at time t for this curve is x, the value at time t on the new curve will be f(x).
Source§

fn reparametrize<F>(self, domain: Interval, f: F) -> ReparamCurve<T, Self, F>
where F: Fn(f32) -> f32,

Create a new Curve whose parameter space is related to the parameter space of this curve by f. For each time t, the sample from the new curve at time t is the sample from this curve at time f(t). The given domain will be the domain of the new curve. The function f is expected to take domain into self.domain(). Read more
Source§

fn reparametrize_linear( self, domain: Interval, ) -> Result<LinearReparamCurve<T, Self>, LinearReparamError>

Linearly reparametrize this Curve, producing a new curve whose domain is the given domain instead of the current one. This operation is only valid for curves with bounded domains. Read more
Source§

fn reparametrize_by_curve<C>(self, other: C) -> CurveReparamCurve<T, Self, C>
where C: Curve<f32>,

Reparametrize this Curve by sampling from another curve. Read more
Source§

fn graph(self) -> GraphCurve<T, Self>

Create a new Curve which is the graph of this one; that is, its output echoes the sample time as part of a tuple. Read more
Source§

fn zip<S, C>( self, other: C, ) -> Result<ZipCurve<T, S, Self, C>, InvalidIntervalError>
where C: Curve<S> + Sized,

Create a new Curve by zipping this curve together with another. Read more
Source§

fn chain<C>(self, other: C) -> Result<ChainCurve<T, Self, C>, ChainError>
where C: Curve<T>,

Create a new Curve by composing this curve end-to-start with another, producing another curve with outputs of the same type. The domain of the other curve is translated so that its start coincides with where this curve ends. Read more
Source§

fn reverse(self) -> Result<ReverseCurve<T, Self>, ReverseError>

Create a new Curve inverting this curve on the x-axis, producing another curve with outputs of the same type, effectively playing backwards starting at self.domain().end() and transitioning over to self.domain().start(). The domain of the new curve is still the same. Read more
Source§

fn repeat(self, count: usize) -> Result<RepeatCurve<T, Self>, RepeatError>

Create a new Curve repeating this curve N times, producing another curve with outputs of the same type. The domain of the new curve will be bigger by a factor of n + 1. Read more
Source§

fn forever(self) -> Result<ForeverCurve<T, Self>, RepeatError>

Create a new Curve repeating this curve forever, producing another curve with outputs of the same type. The domain of the new curve will be unbounded. Read more
Source§

fn ping_pong(self) -> Result<PingPongCurve<T, Self>, PingPongError>

Create a new Curve chaining the original curve with its inverse, producing another curve with outputs of the same type. The domain of the new curve will be twice as long. The transition point is guaranteed to not make any jumps. Read more
Source§

fn chain_continue<C>( self, other: C, ) -> Result<ContinuationCurve<T, Self, C>, ChainError>
where T: VectorSpace, C: Curve<T>,

Create a new Curve by composing this curve end-to-start with another, producing another curve with outputs of the same type. The domain of the other curve is translated so that its start coincides with where this curve ends. Read more
Source§

fn samples( &self, samples: usize, ) -> Result<impl Iterator<Item = T>, ResamplingError>

Extract an iterator over evenly-spaced samples from this curve. Read more
Source§

fn by_ref(&self) -> &Self

Borrow this curve rather than taking ownership of it. This is essentially an alias for a prefix &; the point is that intermediate operations can be performed while retaining access to the original curve. Read more
Source§

fn flip<U, V>(self) -> impl Curve<(V, U)>
where Self: CurveExt<(U, V)>,

Flip this curve so that its tuple output is arranged the other way.
Source§

impl<C, T> CurveResampleExt<T> for C
where C: Curve<T> + ?Sized,

Source§

fn resample<I>( &self, segments: usize, interpolation: I, ) -> Result<SampleCurve<T, I>, ResamplingError>
where I: Fn(&T, &T, f32) -> T,

Resample this Curve to produce a new one that is defined by interpolation over equally spaced sample values, using the provided interpolation to interpolate between adjacent samples. The curve is interpolated on segments segments between samples. For example, if segments is 1, only the start and end points of the curve are used as samples; if segments is 2, a sample at the midpoint is taken as well, and so on. Read more
Source§

fn resample_auto( &self, segments: usize, ) -> Result<SampleAutoCurve<T>, ResamplingError>

Resample this Curve to produce a new one that is defined by interpolation over equally spaced sample values, using automatic interpolation to interpolate between adjacent samples. The curve is interpolated on segments segments between samples. For example, if segments is 1, only the start and end points of the curve are used as samples; if segments is 2, a sample at the midpoint is taken as well, and so on. Read more
Source§

fn resample_uneven<I>( &self, sample_times: impl IntoIterator<Item = f32>, interpolation: I, ) -> Result<UnevenSampleCurve<T, I>, ResamplingError>
where I: Fn(&T, &T, f32) -> T,

Resample this Curve to produce a new one that is defined by interpolation over samples taken at a given set of times. The given interpolation is used to interpolate adjacent samples, and the sample_times are expected to contain at least two valid times within the curve’s domain interval. Read more
Source§

fn resample_uneven_auto( &self, sample_times: impl IntoIterator<Item = f32>, ) -> Result<UnevenSampleAutoCurve<T>, ResamplingError>

Resample this Curve to produce a new one that is defined by automatic interpolation over samples taken at the given set of times. The given sample_times are expected to contain at least two valid times within the curve’s domain interval. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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 = 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<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of self.
Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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