Add ways to configure EasingFunction::Steps via new StepConfig (#17752)

# Objective

- In #17743, attention was raised to the fact that we supported an
unusual kind of step easing function. The author of the fix kindly
provided some links to standards used in CSS. It would be desirable to
support generally agreed upon standards so this PR here tries to
implement an extra configuration option of the step easing function
- Resolve #17744

## Solution

- Introduce `StepConfig`
- `StepConfig` can configure both the number of steps and the jumping
behavior of the function
- `StepConfig` replaces the raw `usize` parameter of the
`EasingFunction::Steps(usize)` construct.
- `StepConfig`s default jumping behavior is `end`, so in that way it
follows #17743

## Testing

- I added a new test per `JumpAt` jumping behavior. These tests
replicate the visuals that can be found at
https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function/steps#description

## Migration Guide

- `EasingFunction::Steps` now uses a `StepConfig` instead of a raw
`usize`. You can replicate the previous behavior by replaceing
`EasingFunction::Steps(10)` with
`EasingFunction::Steps(StepConfig::new(10))`.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
RobWalt 2025-02-11 22:19:01 +00:00 committed by GitHub
parent 98dcee2853
commit aa8793f6b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 181 additions and 18 deletions

View File

@ -0,0 +1,5 @@
<svg viewBox="-0.04 -0.04 1.08 1.08" width="6em" xmlns="http://www.w3.org/2000/svg">
<title>BothSteps(4, Both)</title>
<path d="M0,0 L0,1 M1,0 L1,1 M0,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 M0,1 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0" fill="none" stroke="var(--main-color)" stroke-width="0.02"/>
<polyline fill="none" points="0 0.8 0.01010101 0.8 0.02020202 0.8 0.030303031 0.8 0.04040404 0.8 0.05050505 0.8 0.060606062 0.8 0.07070707 0.8 0.08080808 0.8 0.09090909 0.8 0.1010101 0.8 0.11111111 0.8 0.121212125 0.8 0.13131313 0.8 0.14141414 0.8 0.15151516 0.8 0.16161616 0.8 0.17171717 0.8 0.18181819 0.8 0.1919192 0.8 0.2020202 0.8 0.21212122 0.8 0.22222222 0.8 0.23232323 0.8 0.24242425 0.8 0.25252524 0.6 0.26262626 0.6 0.27272728 0.6 0.28282827 0.6 0.2929293 0.6 0.3030303 0.6 0.3131313 0.6 0.32323232 0.6 0.33333334 0.6 0.34343433 0.6 0.35353535 0.6 0.36363637 0.6 0.37373737 0.6 0.3838384 0.6 0.3939394 0.6 0.4040404 0.6 0.41414142 0.6 0.42424244 0.6 0.43434343 0.6 0.44444445 0.6 0.45454547 0.6 0.46464646 0.6 0.47474748 0.6 0.4848485 0.6 0.4949495 0.6 0.5050505 0.39999998 0.5151515 0.39999998 0.5252525 0.39999998 0.53535354 0.39999998 0.54545456 0.39999998 0.5555556 0.39999998 0.56565654 0.39999998 0.57575756 0.39999998 0.5858586 0.39999998 0.5959596 0.39999998 0.6060606 0.39999998 0.61616164 0.39999998 0.6262626 0.39999998 0.6363636 0.39999998 0.64646465 0.39999998 0.65656567 0.39999998 0.6666667 0.39999998 0.67676765 0.39999998 0.68686867 0.39999998 0.6969697 0.39999998 0.7070707 0.39999998 0.7171717 0.39999998 0.72727275 0.39999998 0.7373737 0.39999998 0.74747473 0.39999998 0.75757575 0.19999999 0.7676768 0.19999999 0.7777778 0.19999999 0.7878788 0.19999999 0.7979798 0.19999999 0.8080808 0.19999999 0.8181818 0.19999999 0.82828283 0.19999999 0.83838385 0.19999999 0.8484849 0.19999999 0.85858583 0.19999999 0.86868685 0.19999999 0.8787879 0.19999999 0.8888889 0.19999999 0.8989899 0.19999999 0.90909094 0.19999999 0.9191919 0.19999999 0.9292929 0.19999999 0.93939394 0.19999999 0.94949496 0.19999999 0.959596 0.19999999 0.969697 0.19999999 0.97979796 0.19999999 0.989899 0.19999999 1 0" stroke="red" stroke-width="0.04"/>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,5 @@
<svg viewBox="-0.04 -0.04 1.08 1.08" width="6em" xmlns="http://www.w3.org/2000/svg">
<title>EndSteps(4, End)</title>
<path d="M0,0 L0,1 M1,0 L1,1 M0,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 M0,1 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0" fill="none" stroke="var(--main-color)" stroke-width="0.02"/>
<polyline fill="none" points="0 1 0.01010101 1 0.02020202 1 0.030303031 1 0.04040404 1 0.05050505 1 0.060606062 1 0.07070707 1 0.08080808 1 0.09090909 1 0.1010101 1 0.11111111 1 0.121212125 1 0.13131313 1 0.14141414 1 0.15151516 1 0.16161616 1 0.17171717 1 0.18181819 1 0.1919192 1 0.2020202 1 0.21212122 1 0.22222222 1 0.23232323 1 0.24242425 1 0.25252524 0.75 0.26262626 0.75 0.27272728 0.75 0.28282827 0.75 0.2929293 0.75 0.3030303 0.75 0.3131313 0.75 0.32323232 0.75 0.33333334 0.75 0.34343433 0.75 0.35353535 0.75 0.36363637 0.75 0.37373737 0.75 0.3838384 0.75 0.3939394 0.75 0.4040404 0.75 0.41414142 0.75 0.42424244 0.75 0.43434343 0.75 0.44444445 0.75 0.45454547 0.75 0.46464646 0.75 0.47474748 0.75 0.4848485 0.75 0.4949495 0.75 0.5050505 0.5 0.5151515 0.5 0.5252525 0.5 0.53535354 0.5 0.54545456 0.5 0.5555556 0.5 0.56565654 0.5 0.57575756 0.5 0.5858586 0.5 0.5959596 0.5 0.6060606 0.5 0.61616164 0.5 0.6262626 0.5 0.6363636 0.5 0.64646465 0.5 0.65656567 0.5 0.6666667 0.5 0.67676765 0.5 0.68686867 0.5 0.6969697 0.5 0.7070707 0.5 0.7171717 0.5 0.72727275 0.5 0.7373737 0.5 0.74747473 0.5 0.75757575 0.25 0.7676768 0.25 0.7777778 0.25 0.7878788 0.25 0.7979798 0.25 0.8080808 0.25 0.8181818 0.25 0.82828283 0.25 0.83838385 0.25 0.8484849 0.25 0.85858583 0.25 0.86868685 0.25 0.8787879 0.25 0.8888889 0.25 0.8989899 0.25 0.90909094 0.25 0.9191919 0.25 0.9292929 0.25 0.93939394 0.25 0.94949496 0.25 0.959596 0.25 0.969697 0.25 0.97979796 0.25 0.989899 0.25 1 0" stroke="red" stroke-width="0.04"/>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,5 @@
<svg viewBox="-0.04 -0.04 1.08 1.08" width="6em" xmlns="http://www.w3.org/2000/svg">
<title>NoneSteps(4, None)</title>
<path d="M0,0 L0,1 M1,0 L1,1 M0,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 M0,1 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0" fill="none" stroke="var(--main-color)" stroke-width="0.02"/>
<polyline fill="none" points="0 1 0.01010101 1 0.02020202 1 0.030303031 1 0.04040404 1 0.05050505 1 0.060606062 1 0.07070707 1 0.08080808 1 0.09090909 1 0.1010101 1 0.11111111 1 0.121212125 1 0.13131313 1 0.14141414 1 0.15151516 1 0.16161616 1 0.17171717 1 0.18181819 1 0.1919192 1 0.2020202 1 0.21212122 1 0.22222222 1 0.23232323 1 0.24242425 1 0.25252524 0.6666666 0.26262626 0.6666666 0.27272728 0.6666666 0.28282827 0.6666666 0.2929293 0.6666666 0.3030303 0.6666666 0.3131313 0.6666666 0.32323232 0.6666666 0.33333334 0.6666666 0.34343433 0.6666666 0.35353535 0.6666666 0.36363637 0.6666666 0.37373737 0.6666666 0.3838384 0.6666666 0.3939394 0.6666666 0.4040404 0.6666666 0.41414142 0.6666666 0.42424244 0.6666666 0.43434343 0.6666666 0.44444445 0.6666666 0.45454547 0.6666666 0.46464646 0.6666666 0.47474748 0.6666666 0.4848485 0.6666666 0.4949495 0.6666666 0.5050505 0.3333333 0.5151515 0.3333333 0.5252525 0.3333333 0.53535354 0.3333333 0.54545456 0.3333333 0.5555556 0.3333333 0.56565654 0.3333333 0.57575756 0.3333333 0.5858586 0.3333333 0.5959596 0.3333333 0.6060606 0.3333333 0.61616164 0.3333333 0.6262626 0.3333333 0.6363636 0.3333333 0.64646465 0.3333333 0.65656567 0.3333333 0.6666667 0.3333333 0.67676765 0.3333333 0.68686867 0.3333333 0.6969697 0.3333333 0.7070707 0.3333333 0.7171717 0.3333333 0.72727275 0.3333333 0.7373737 0.3333333 0.74747473 0.3333333 0.75757575 0 0.7676768 0 0.7777778 0 0.7878788 0 0.7979798 0 0.8080808 0 0.8181818 0 0.82828283 0 0.83838385 0 0.8484849 0 0.85858583 0 0.86868685 0 0.8787879 0 0.8888889 0 0.8989899 0 0.90909094 0 0.9191919 0 0.9292929 0 0.93939394 0 0.94949496 0 0.959596 0 0.969697 0 0.97979796 0 0.989899 0 1 0" stroke="red" stroke-width="0.04"/>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1,5 @@
<svg viewBox="-0.04 -0.04 1.08 1.08" width="6em" xmlns="http://www.w3.org/2000/svg">
<title>StartSteps(4, Start)</title>
<path d="M0,0 L0,1 M1,0 L1,1 M0,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 M0,1 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0" fill="none" stroke="var(--main-color)" stroke-width="0.02"/>
<polyline fill="none" points="0 0.75 0.01010101 0.75 0.02020202 0.75 0.030303031 0.75 0.04040404 0.75 0.05050505 0.75 0.060606062 0.75 0.07070707 0.75 0.08080808 0.75 0.09090909 0.75 0.1010101 0.75 0.11111111 0.75 0.121212125 0.75 0.13131313 0.75 0.14141414 0.75 0.15151516 0.75 0.16161616 0.75 0.17171717 0.75 0.18181819 0.75 0.1919192 0.75 0.2020202 0.75 0.21212122 0.75 0.22222222 0.75 0.23232323 0.75 0.24242425 0.75 0.25252524 0.5 0.26262626 0.5 0.27272728 0.5 0.28282827 0.5 0.2929293 0.5 0.3030303 0.5 0.3131313 0.5 0.32323232 0.5 0.33333334 0.5 0.34343433 0.5 0.35353535 0.5 0.36363637 0.5 0.37373737 0.5 0.3838384 0.5 0.3939394 0.5 0.4040404 0.5 0.41414142 0.5 0.42424244 0.5 0.43434343 0.5 0.44444445 0.5 0.45454547 0.5 0.46464646 0.5 0.47474748 0.5 0.4848485 0.5 0.4949495 0.5 0.5050505 0.25 0.5151515 0.25 0.5252525 0.25 0.53535354 0.25 0.54545456 0.25 0.5555556 0.25 0.56565654 0.25 0.57575756 0.25 0.5858586 0.25 0.5959596 0.25 0.6060606 0.25 0.61616164 0.25 0.6262626 0.25 0.6363636 0.25 0.64646465 0.25 0.65656567 0.25 0.6666667 0.25 0.67676765 0.25 0.68686867 0.25 0.6969697 0.25 0.7070707 0.25 0.7171717 0.25 0.72727275 0.25 0.7373737 0.25 0.74747473 0.25 0.75757575 0 0.7676768 0 0.7777778 0 0.7878788 0 0.7979798 0 0.8080808 0 0.8181818 0 0.82828283 0 0.83838385 0 0.8484849 0 0.85858583 0 0.86868685 0 0.8787879 0 0.8888889 0 0.8989899 0 0.90909094 0 0.9191919 0 0.9292929 0 0.93939394 0 0.94949496 0 0.959596 0 0.969697 0 0.97979796 0 0.989899 0 1 0" stroke="red" stroke-width="0.04"/>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,5 +0,0 @@
<svg viewBox="-0.04 -0.04 1.08 1.08" width="6em" xmlns="http://www.w3.org/2000/svg">
<title>Steps(4)</title>
<path d="M0,0 L0,1 M1,0 L1,1 M0,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 M0,1 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0 m0.1,0 l0.1,0" fill="none" stroke="var(--main-color)" stroke-width="0.02"/>
<polyline fill="none" points="0 1 0.01010101 1 0.02020202 1 0.030303031 1 0.04040404 1 0.05050505 1 0.060606062 1 0.07070707 1 0.08080808 1 0.09090909 1 0.1010101 1 0.11111111 1 0.121212125 1 0.13131313 0.75 0.14141414 0.75 0.15151516 0.75 0.16161616 0.75 0.17171717 0.75 0.18181819 0.75 0.1919192 0.75 0.2020202 0.75 0.21212122 0.75 0.22222222 0.75 0.23232323 0.75 0.24242425 0.75 0.25252524 0.75 0.26262626 0.75 0.27272728 0.75 0.28282827 0.75 0.2929293 0.75 0.3030303 0.75 0.3131313 0.75 0.32323232 0.75 0.33333334 0.75 0.34343433 0.75 0.35353535 0.75 0.36363637 0.75 0.37373737 0.75 0.3838384 0.5 0.3939394 0.5 0.4040404 0.5 0.41414142 0.5 0.42424244 0.5 0.43434343 0.5 0.44444445 0.5 0.45454547 0.5 0.46464646 0.5 0.47474748 0.5 0.4848485 0.5 0.4949495 0.5 0.5050505 0.5 0.5151515 0.5 0.5252525 0.5 0.53535354 0.5 0.54545456 0.5 0.5555556 0.5 0.56565654 0.5 0.57575756 0.5 0.5858586 0.5 0.5959596 0.5 0.6060606 0.5 0.61616164 0.5 0.6262626 0.25 0.6363636 0.25 0.64646465 0.25 0.65656567 0.25 0.6666667 0.25 0.67676765 0.25 0.68686867 0.25 0.6969697 0.25 0.7070707 0.25 0.7171717 0.25 0.72727275 0.25 0.7373737 0.25 0.74747473 0.25 0.75757575 0.25 0.7676768 0.25 0.7777778 0.25 0.7878788 0.25 0.7979798 0.25 0.8080808 0.25 0.8181818 0.25 0.82828283 0.25 0.83838385 0.25 0.8484849 0.25 0.85858583 0.25 0.86868685 0.25 0.8787879 0 0.8888889 0 0.8989899 0 0.90909094 0 0.9191919 0 0.9292929 0 0.93939394 0 0.94949496 0 0.959596 0 0.969697 0 0.97979796 0 0.989899 0 1 0" stroke="red" stroke-width="0.04"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -269,6 +269,52 @@ where
}
}
/// Configuration options for the [`EaseFunction::Steps`] curves. This closely replicates the
/// [CSS step function specification].
///
/// [CSS step function specification]: https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function/steps#description
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
pub enum JumpAt {
/// Indicates that the first step happens when the animation begins.
///
#[doc = include_str!("../../images/easefunction/StartSteps.svg")]
Start,
/// Indicates that the last step happens when the animation ends.
///
#[doc = include_str!("../../images/easefunction/EndSteps.svg")]
#[default]
End,
/// Indicates neither early nor late jumps happen.
///
#[doc = include_str!("../../images/easefunction/NoneSteps.svg")]
None,
/// Indicates both early and late jumps happen.
///
#[doc = include_str!("../../images/easefunction/BothSteps.svg")]
Both,
}
impl JumpAt {
#[inline]
pub(crate) fn eval(self, num_steps: usize, t: f32) -> f32 {
use crate::ops;
let (a, b) = match self {
JumpAt::Start => (1.0, 0),
JumpAt::End => (0.0, 0),
JumpAt::None => (0.0, -1),
JumpAt::Both => (1.0, 1),
};
let current_step = ops::floor(t * num_steps as f32) + a;
let step_size = (num_steps as isize + b).max(1) as f32;
(current_step / step_size).clamp(0.0, 1.0)
}
}
/// 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`.
@ -538,10 +584,9 @@ pub enum EaseFunction {
#[doc = include_str!("../../images/easefunction/BounceInOut.svg")]
BounceInOut,
/// `n` steps connecting the start and the end
///
#[doc = include_str!("../../images/easefunction/Steps.svg")]
Steps(usize),
/// `n` steps connecting the start and the end. Jumping behavior is customizable via
/// [`JumpAt`]. See [`JumpAt`] for all the options and visual examples.
Steps(usize, JumpAt),
/// `f(omega,t) = 1 - (1 - t)²(2sin(omega * t) / omega + cos(omega * t))`, parametrized by `omega`
///
@ -794,8 +839,8 @@ mod easing_functions {
}
#[inline]
pub(crate) fn steps(num_steps: usize, t: f32) -> f32 {
ops::floor(t * num_steps as f32) / num_steps.max(1) as f32
pub(crate) fn steps(num_steps: usize, jump_at: super::JumpAt, t: f32) -> f32 {
jump_at.eval(num_steps, t)
}
#[inline]
@ -844,7 +889,9 @@ impl EaseFunction {
EaseFunction::BounceIn => easing_functions::bounce_in(t),
EaseFunction::BounceOut => easing_functions::bounce_out(t),
EaseFunction::BounceInOut => easing_functions::bounce_in_out(t),
EaseFunction::Steps(num_steps) => easing_functions::steps(*num_steps, t),
EaseFunction::Steps(num_steps, jump_at) => {
easing_functions::steps(*num_steps, *jump_at, t)
}
EaseFunction::Elastic(omega) => easing_functions::elastic(*omega, t),
}
}
@ -865,6 +912,7 @@ impl Curve<f32> for EaseFunction {
#[cfg(test)]
#[cfg(feature = "approx")]
mod tests {
use crate::{Vec2, Vec3, Vec3A};
use approx::assert_abs_diff_eq;
@ -1027,6 +1075,95 @@ mod tests {
});
}
#[test]
fn jump_at_start() {
let jump_at = JumpAt::Start;
let num_steps = 4;
[
(0.0, 0.25),
(0.249, 0.25),
(0.25, 0.5),
(0.499, 0.5),
(0.5, 0.75),
(0.749, 0.75),
(0.75, 1.0),
(1.0, 1.0),
]
.into_iter()
.for_each(|(t, expected)| {
assert_abs_diff_eq!(jump_at.eval(num_steps, t), expected);
});
}
#[test]
fn jump_at_end() {
let jump_at = JumpAt::End;
let num_steps = 4;
[
(0.0, 0.0),
(0.249, 0.0),
(0.25, 0.25),
(0.499, 0.25),
(0.5, 0.5),
(0.749, 0.5),
(0.75, 0.75),
(0.999, 0.75),
(1.0, 1.0),
]
.into_iter()
.for_each(|(t, expected)| {
assert_abs_diff_eq!(jump_at.eval(num_steps, t), expected);
});
}
#[test]
fn jump_at_none() {
let jump_at = JumpAt::None;
let num_steps = 5;
[
(0.0, 0.0),
(0.199, 0.0),
(0.2, 0.25),
(0.399, 0.25),
(0.4, 0.5),
(0.599, 0.5),
(0.6, 0.75),
(0.799, 0.75),
(0.8, 1.0),
(0.999, 1.0),
(1.0, 1.0),
]
.into_iter()
.for_each(|(t, expected)| {
assert_abs_diff_eq!(jump_at.eval(num_steps, t), expected);
});
}
#[test]
fn jump_at_both() {
let jump_at = JumpAt::Both;
let num_steps = 4;
[
(0.0, 0.2),
(0.249, 0.2),
(0.25, 0.4),
(0.499, 0.4),
(0.5, 0.6),
(0.749, 0.6),
(0.75, 0.8),
(0.999, 0.8),
(1.0, 1.0),
]
.into_iter()
.for_each(|(t, expected)| {
assert_abs_diff_eq!(jump_at.eval(num_steps, t), expected);
});
}
#[test]
fn ease_function_curve() {
// Test that using `EaseFunction` directly is equivalent to `EasingCurve::new(0.0, 1.0, ...)`.

View File

@ -1061,7 +1061,7 @@ mod tests {
let start = Vec2::ZERO;
let end = Vec2::new(1.0, 2.0);
let curve = EasingCurve::new(start, end, EaseFunction::Steps(4));
let curve = EasingCurve::new(start, end, EaseFunction::Steps(4, JumpAt::End));
[
(0.0, start),
(0.249, start),

View File

@ -68,7 +68,10 @@ fn setup(mut commands: Commands) {
EaseFunction::BounceInOut,
// "Other" row
EaseFunction::Linear,
EaseFunction::Steps(4),
EaseFunction::Steps(4, JumpAt::End),
EaseFunction::Steps(4, JumpAt::Start),
EaseFunction::Steps(4, JumpAt::Both),
EaseFunction::Steps(4, JumpAt::None),
EaseFunction::Elastic(50.0),
]
.chunks(COLS);

View File

@ -1,7 +1,7 @@
//! Generates graphs for the `EaseFunction` docs.
use std::path::PathBuf;
use bevy_math::curve::{CurveExt, EaseFunction, EasingCurve};
use bevy_math::curve::{CurveExt, EaseFunction, EasingCurve, JumpAt};
use svg::{
node::element::{self, path::Data},
Document,
@ -55,7 +55,10 @@ fn main() {
EaseFunction::BounceOut,
EaseFunction::BounceInOut,
EaseFunction::Linear,
EaseFunction::Steps(4),
EaseFunction::Steps(4, JumpAt::Start),
EaseFunction::Steps(4, JumpAt::End),
EaseFunction::Steps(4, JumpAt::None),
EaseFunction::Steps(4, JumpAt::Both),
EaseFunction::Elastic(50.0),
] {
let curve = EasingCurve::new(0.0, 1.0, function);
@ -71,7 +74,7 @@ fn main() {
// Curve can go out past endpoints
let mut min = 0.0f32;
let mut max = 0.0f32;
let mut max = 1.0f32;
for &(_, y) in &samples {
min = min.min(y);
max = max.max(y);
@ -104,7 +107,12 @@ fn main() {
data
});
let name = format!("{function:?}");
let opt_tag = match function {
EaseFunction::Steps(_n, jump_at) => format!("{jump_at:?}"),
_ => String::new(),
};
let name = format!("{opt_tag}{function:?}");
let tooltip = element::Title::new(&name);
const MARGIN: f32 = 0.04;