use std::{
cell::Cell,
fmt,
rc::{Rc, Weak},
};
use nsh_animation::{
AnimationId, AnimationOp, Composite, Driver, Easing, Extrapolate, MathOp, Operand, Output,
};
use super::{
AdaptiveColor,
task::{Action, Answer, Executor},
};
pub(crate) struct Node {
id: nsh_animation::NodeId,
executor: Weak<Executor>,
_inputs: Vec<Rc<Node>>,
}
impl Node {
fn new(
executor: &Rc<Executor>,
op: impl FnOnce(nsh_animation::NodeId) -> AnimationOp,
inputs: Vec<Rc<Node>>,
) -> Rc<Self> {
let id = executor.next_animation_id();
executor.act(Action::Animation(op(id)));
Rc::new(Self {
id,
executor: Rc::downgrade(executor),
_inputs: inputs,
})
}
fn act(&self, op: AnimationOp) {
if let Some(executor) = self.executor.upgrade() {
executor.act(Action::Animation(op));
}
}
}
impl Drop for Node {
fn drop(&mut self) {
self.act(AnimationOp::Release { node: self.id });
}
}
fn with_node(mut op: AnimationOp, id: nsh_animation::NodeId) -> AnimationOp {
match &mut op {
AnimationOp::CreateValue { node, .. }
| AnimationOp::CreateInterpolate { node, .. }
| AnimationOp::CreateDiffClamp { node, .. }
| AnimationOp::CreateMath { node, .. } => *node = id,
_ => {}
}
op
}
#[derive(Default)]
pub(crate) struct Derived(pub(crate) Vec<(AnimationOp, Weak<Node>)>);
impl Derived {
pub(crate) fn get(&mut self, key: &AnimationOp) -> Option<Rc<Node>> {
self.0.retain(|(_, n)| n.strong_count() > 0);
self.0
.iter()
.find(|(k, _)| k == key)
.and_then(|(_, n)| n.upgrade())
}
}
pub trait Animated {
fn native_node(&self) -> NativeNode;
}
#[derive(Clone)]
pub struct NativeNode(Rc<Node>);
impl NativeNode {
pub(crate) fn id(&self) -> nsh_animation::NodeId {
self.0.id
}
fn executor(&self) -> Option<Rc<Executor>> {
self.0.executor.upgrade()
}
fn derive(
&self,
op: impl FnOnce(nsh_animation::NodeId) -> AnimationOp,
other: Option<&NativeNode>,
) -> NativeNode {
let Some(executor) = self.executor() else {
return self.clone();
};
let key = op(0);
if let Some(node) = executor.derived(&key) {
return NativeNode(node);
}
let mut inputs = vec![self.0.clone()];
inputs.extend(other.map(|o| o.0.clone()));
let node = Node::new(&executor, |id| with_node(key.clone(), id), inputs);
executor.remember_derived(key, &node);
NativeNode(node)
}
pub fn interpolate(&self, input: &[f32], output: &[f32]) -> NativeNode {
self.interpolate_with(
input,
Output::Numbers(output.to_vec()),
Interpolation::default(),
)
}
pub fn interpolate_colors<C: Into<AdaptiveColor> + Copy>(
&self,
input: &[f32],
colors: &[C],
) -> NativeNode {
let colors: Rc<[AdaptiveColor]> = colors.iter().map(|&c| c.into()).collect();
let pick = {
let colors = colors.clone();
move |dark: bool| {
Output::Colors(
colors
.iter()
.map(|c| if dark { c.dark.0 } else { c.light.0 })
.collect(),
)
}
};
if colors.iter().all(|c| c.light == c.dark) {
return self.interpolate_with(input, pick(false), Interpolation::default());
}
let node = self.interpolate_with(
input,
pick(super::untracked(super::ambient::dark)),
Interpolation::default(),
);
let held = node.clone();
let first = Cell::new(true);
super::reactive::render_effect(move || {
let output = pick(super::ambient::dark());
if !first.replace(false) {
held.0.act(AnimationOp::SetOutput {
node: held.id(),
output,
});
}
});
node
}
pub fn interpolate_with(
&self,
input: &[f32],
output: Output,
interpolation: Interpolation,
) -> NativeNode {
let source = self.id();
let input_range = input.to_vec();
self.derive(
move |node| AnimationOp::CreateInterpolate {
node,
input: source,
input_range,
output,
extrapolate_left: interpolation.extrapolate_left,
extrapolate_right: interpolation.extrapolate_right,
easing: interpolation.easing,
},
None,
)
}
fn math(&self, op: MathOp, other: AnimationOperand) -> NativeNode {
let a = Operand::Node(self.id());
let b = other.operand;
self.derive(
move |node| AnimationOp::CreateMath { node, op, a, b },
other.node.as_ref(),
)
}
pub fn add(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.math(MathOp::Add, other.into())
}
pub fn sub(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.math(MathOp::Sub, other.into())
}
pub fn mul(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.math(MathOp::Mul, other.into())
}
pub fn div(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.math(MathOp::Div, other.into())
}
pub fn modulo(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.math(MathOp::Mod, other.into())
}
pub fn diff_clamp(&self, min: f32, max: f32) -> NativeNode {
let input = self.id();
self.derive(
move |node| AnimationOp::CreateDiffClamp {
node,
input,
min,
max,
},
None,
)
}
}
impl Animated for NativeNode {
fn native_node(&self) -> NativeNode {
self.clone()
}
}
impl PartialEq for NativeNode {
fn eq(&self, other: &Self) -> bool {
self.id() == other.id()
}
}
impl fmt::Debug for NativeNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("NativeNode").field(&self.id()).finish()
}
}
#[derive(Debug, Clone)]
pub struct AnimationOperand {
operand: Operand,
node: Option<NativeNode>,
}
impl From<f32> for AnimationOperand {
fn from(n: f32) -> Self {
Self {
operand: Operand::Const(n),
node: None,
}
}
}
impl<A: Animated> From<&A> for AnimationOperand {
fn from(a: &A) -> Self {
let node = a.native_node();
Self {
operand: Operand::Node(node.id()),
node: Some(node),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Interpolation {
pub extrapolate_left: Extrapolate,
pub extrapolate_right: Extrapolate,
pub easing: Easing,
}
impl Interpolation {
pub const fn extrapolate(extrapolate: Extrapolate) -> Self {
Self {
extrapolate_left: extrapolate,
extrapolate_right: extrapolate,
easing: Easing::Linear,
}
}
}
impl Default for Interpolation {
fn default() -> Self {
Self::extrapolate(Extrapolate::Clamp)
}
}
#[derive(Clone, PartialEq, Debug)]
pub struct NativeValue(NativeNode);
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Spring {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
pub velocity: Option<f32>,
}
impl Default for Spring {
fn default() -> Self {
Self {
stiffness: 170.0,
damping: 26.0,
mass: 1.0,
velocity: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Timing {
pub duration_ms: f32,
pub easing: Easing,
pub delay_ms: f32,
}
impl Timing {
pub const fn new(duration_ms: f32, easing: Easing) -> Self {
Self {
duration_ms,
easing,
delay_ms: 0.0,
}
}
fn driver(self, to: f32) -> Driver {
Driver::Timing {
to,
duration_ms: self.duration_ms,
easing: self.easing,
delay_ms: self.delay_ms,
}
}
}
impl Default for Timing {
fn default() -> Self {
Self::new(300.0, Easing::EaseInOut)
}
}
impl Spring {
fn driver(self, to: f32) -> Driver {
Driver::Spring {
to,
stiffness: self.stiffness,
damping: self.damping,
mass: self.mass,
velocity: self.velocity,
}
}
}
fn sample(driver: Driver, from: f32, fps: f32) -> Vec<f32> {
let step = 1.0 / f64::from(fps.clamp(1.0, 1000.0));
nsh_animation::sample_driver(driver, from, step, nsh_animation::MAX_SAMPLES)
}
pub fn sample_spring(from: f32, to: f32, spring: Spring, fps: f32) -> Vec<f32> {
sample(spring.driver(to), from, fps)
}
pub fn sample_decay(from: f32, velocity: f32, deceleration: f32, fps: f32) -> Vec<f32> {
sample(
Driver::Decay {
velocity: Some(velocity),
deceleration,
clamp: None,
bounce: 0.0,
},
from,
fps,
)
}
pub fn sample_decay_within(
from: f32,
velocity: f32,
deceleration: f32,
(min, max): (f32, f32),
bounce: f32,
fps: f32,
) -> Vec<f32> {
sample(
Driver::Decay {
velocity: Some(velocity),
deceleration,
clamp: Some((min, max)),
bounce,
},
from,
fps,
)
}
#[derive(Debug)]
pub struct AnimationEnd(Answer<bool>);
impl std::future::IntoFuture for AnimationEnd {
type Output = bool;
type IntoFuture = Answer<bool>;
fn into_future(self) -> Answer<bool> {
self.0
}
}
impl NativeValue {
pub(crate) fn new(executor: &Rc<Executor>, value: f32) -> Self {
Self(NativeNode(Node::new(
executor,
|node| AnimationOp::CreateValue { node, value },
Vec::new(),
)))
}
pub fn node(&self) -> &NativeNode {
&self.0
}
pub fn set(&self, value: f32) {
self.0.0.act(AnimationOp::Set {
node: self.0.id(),
value,
});
}
pub fn stop(&self) {
self.0.0.act(AnimationOp::Stop { node: self.0.id() });
}
pub fn value(&self) -> Answer<f32> {
let (answer, slot) = Answer::new();
if let Some(executor) = self.0.executor() {
executor.act(Action::ReadValue {
node: self.0.id(),
value: slot,
});
}
answer
}
fn executor(&self) -> Weak<Executor> {
self.0.0.executor.clone()
}
fn start(&self, driver: Driver) -> AnimationEnd {
let (end, slot) = Answer::new();
let end = AnimationEnd(end);
if let Some(executor) = self.0.executor() {
let animation = executor.next_animation_id();
executor.act(Action::Animate {
op: AnimationOp::Start {
node: self.0.id(),
animation,
driver,
},
animation,
end: slot,
});
}
end
}
pub fn spring(&self, to: f32, spring: Spring) -> AnimationEnd {
self.start(spring.driver(to))
}
pub fn timing(&self, to: f32, ms: f32, easing: Easing) -> AnimationEnd {
self.timing_with(to, Timing::new(ms, easing))
}
pub fn timing_with(&self, to: f32, timing: Timing) -> AnimationEnd {
self.start(timing.driver(to))
}
pub fn decay(&self, velocity: Option<f32>, deceleration: f32) -> AnimationEnd {
self.start(Driver::Decay {
velocity,
deceleration,
clamp: None,
bounce: 0.0,
})
}
pub fn decay_within(
&self,
velocity: Option<f32>,
deceleration: f32,
(min, max): (f32, f32),
bounce: f32,
) -> AnimationEnd {
self.start(Driver::Decay {
velocity,
deceleration,
clamp: Some((min, max)),
bounce,
})
}
pub fn set_offset(&self, offset: f32) {
self.0.0.act(AnimationOp::SetOffset {
node: self.0.id(),
offset,
});
}
pub fn flatten_offset(&self) {
self.0
.0
.act(AnimationOp::FlattenOffset { node: self.0.id() });
}
pub fn extract_offset(&self) {
self.0
.0
.act(AnimationOp::ExtractOffset { node: self.0.id() });
}
pub fn interpolate(&self, input: &[f32], output: &[f32]) -> NativeNode {
self.0.interpolate(input, output)
}
pub fn interpolate_colors<C: Into<AdaptiveColor> + Copy>(
&self,
input: &[f32],
colors: &[C],
) -> NativeNode {
self.0.interpolate_colors(input, colors)
}
pub fn interpolate_with(
&self,
input: &[f32],
output: Output,
interpolation: Interpolation,
) -> NativeNode {
self.0.interpolate_with(input, output, interpolation)
}
pub fn diff_clamp(&self, min: f32, max: f32) -> NativeNode {
self.0.diff_clamp(min, max)
}
pub fn add(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.0.add(other)
}
pub fn sub(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.0.sub(other)
}
pub fn mul(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.0.mul(other)
}
pub fn div(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.0.div(other)
}
pub fn modulo(&self, other: impl Into<AnimationOperand>) -> NativeNode {
self.0.modulo(other)
}
}
impl Animated for NativeValue {
fn native_node(&self) -> NativeNode {
self.0.clone()
}
}
#[derive(Clone)]
pub struct Animation(Rc<Composed>);
struct Composed {
spec: Composite,
values: Vec<NativeValue>,
run: Run,
}
struct Run {
executor: Weak<Executor>,
key: Cell<u32>,
animation: Cell<AnimationId>,
}
impl Drop for Run {
fn drop(&mut self) {
let key = self.key.get();
if key != 0
&& let Some(executor) = self.executor.upgrade()
{
executor.act(Action::Animation(AnimationOp::ReleaseComposite { key }));
}
}
}
impl Animation {
fn new(spec: Composite, values: Vec<NativeValue>) -> Self {
let executor = values
.first()
.map(NativeValue::executor)
.unwrap_or_default();
Self(Rc::new(Composed {
spec,
values,
run: Run {
executor,
key: Cell::new(0),
animation: Cell::new(0),
},
}))
}
fn run(value: &NativeValue, driver: Driver) -> Self {
let node = value.0.id();
Self::new(Composite::Run { node, driver }, vec![value.clone()])
}
pub fn timing(value: &NativeValue, to: f32, timing: Timing) -> Self {
Self::run(value, timing.driver(to))
}
pub fn spring(value: &NativeValue, to: f32, spring: Spring) -> Self {
Self::run(value, spring.driver(to))
}
pub fn decay(value: &NativeValue, velocity: Option<f32>, deceleration: f32) -> Self {
Self::run(
value,
Driver::Decay {
velocity,
deceleration,
clamp: None,
bounce: 0.0,
},
)
}
pub fn decay_within(
value: &NativeValue,
velocity: Option<f32>,
deceleration: f32,
(min, max): (f32, f32),
bounce: f32,
) -> Self {
Self::run(
value,
Driver::Decay {
velocity,
deceleration,
clamp: Some((min, max)),
bounce,
},
)
}
pub fn delay(ms: f32) -> Self {
Self::new(Composite::Delay(ms), Vec::new())
}
fn into_parts(self) -> (Composite, Vec<NativeValue>) {
match Rc::try_unwrap(self.0) {
Ok(Composed { spec, values, .. }) => (spec, values),
Err(shared) => (shared.spec.clone(), shared.values.clone()),
}
}
fn group(
animations: impl IntoIterator<Item = Animation>,
make: impl FnOnce(Vec<Composite>) -> Composite,
) -> Self {
let mut specs = Vec::new();
let mut values: Vec<NativeValue> = Vec::new();
for animation in animations {
let (spec, of) = animation.into_parts();
specs.push(spec);
for value in of {
if !values.contains(&value) {
values.push(value);
}
}
}
Self::new(make(specs), values)
}
pub fn sequence(animations: impl IntoIterator<Item = Animation>) -> Self {
Self::group(animations, Composite::Sequence)
}
pub fn parallel(animations: impl IntoIterator<Item = Animation>) -> Self {
Self::group(animations, |children| Composite::Parallel {
children,
stop_together: true,
})
}
pub fn stagger(ms: f32, animations: impl IntoIterator<Item = Animation>) -> Self {
let staged = animations
.into_iter()
.enumerate()
.map(|(i, a)| Self::sequence([Self::delay(ms * i as f32), a]));
Self::parallel(staged)
}
pub fn looped(self, iterations: Option<u32>) -> Self {
let (spec, values) = self.into_parts();
Self::new(
Composite::Loop {
child: Box::new(spec),
iterations,
reset: true,
},
values,
)
}
pub fn stop_together(self, stop_together: bool) -> Self {
let (mut spec, values) = self.into_parts();
if let Composite::Parallel {
stop_together: s, ..
} = &mut spec
{
*s = stop_together;
}
Self::new(spec, values)
}
pub fn reset_before_iteration(self, reset: bool) -> Self {
let (mut spec, values) = self.into_parts();
if let Composite::Loop { reset: r, .. } = &mut spec {
*r = reset;
}
Self::new(spec, values)
}
pub fn start(&self) -> AnimationEnd {
let (end, slot) = Answer::new();
let run = &self.0.run;
let Some(executor) = run.executor.upgrade() else {
if self.0.values.is_empty() {
slot.borrow_mut().deliver(true);
}
return AnimationEnd(end);
};
self.stop();
if run.key.get() == 0 {
run.key.set(executor.next_animation_id());
}
let animation = executor.next_animation_id();
run.animation.set(animation);
executor.act(Action::Animate {
op: AnimationOp::StartComposite {
animation,
key: run.key.get(),
spec: self.0.spec.clone(),
},
animation,
end: slot,
});
AnimationEnd(end)
}
pub fn stop(&self) {
let run = &self.0.run;
let animation = run.animation.replace(0);
if animation != 0
&& let Some(executor) = run.executor.upgrade()
{
executor.act(Action::Animation(AnimationOp::StopAnimation { animation }));
}
}
pub fn reset(&self) {
let run = &self.0.run;
run.animation.set(0);
let key = run.key.get();
if key != 0
&& let Some(executor) = run.executor.upgrade()
{
executor.act(Action::Animation(AnimationOp::ResetComposite { key }));
}
}
}
impl fmt::Debug for Animation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Animation").field(&self.0.spec).finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn released(executor: &Executor) -> usize {
executor
.take_actions()
.into_iter()
.filter(|a| matches!(a, Action::Animation(AnimationOp::Release { .. })))
.count()
}
#[test]
fn a_derived_chain_keeps_its_middle_nodes() {
let executor = Rc::new(Executor::default());
let v = NativeValue::new(&executor, 0.5);
let end = v.node().mul(2.0).sub(1.0);
assert_eq!(released(&executor), 0, "the product lives with the end");
drop(end);
assert_eq!(released(&executor), 2, "then both go");
drop(v);
assert_eq!(released(&executor), 1);
}
fn ops(executor: &Executor) -> Vec<AnimationOp> {
executor
.take_actions()
.into_iter()
.filter_map(|a| match a {
Action::Animation(op) | Action::Animate { op, .. } => Some(op),
_ => None,
})
.collect()
}
fn timing(to: f32, ms: f32) -> Driver {
Timing::new(ms, Easing::Linear).driver(to)
}
#[test]
fn composites_describe_their_steps() {
let executor = Rc::new(Executor::default());
let (a, b) = (
NativeValue::new(&executor, 0.0),
NativeValue::new(&executor, 1.0),
);
let (na, nb) = (a.node().id(), b.node().id());
let run = |node, to| Composite::Run {
node,
driver: timing(to, 100.0),
};
let step =
|v: &NativeValue, to| Animation::timing(v, to, Timing::new(100.0, Easing::Linear));
let staggered = Animation::stagger(50.0, [step(&a, 1.0), step(&b, 2.0)]);
let delayed = |ms, c| Composite::Sequence(vec![Composite::Delay(ms), c]);
assert_eq!(
staggered.0.spec,
Composite::Parallel {
children: vec![delayed(0.0, run(na, 1.0)), delayed(50.0, run(nb, 2.0))],
stop_together: true,
}
);
assert_eq!(staggered.0.values, [a.clone(), b.clone()]);
let looped = Animation::sequence([step(&a, 1.0), Animation::delay(10.0), step(&a, 0.0)])
.looped(Some(3))
.reset_before_iteration(false);
assert_eq!(
looped.0.spec,
Composite::Loop {
child: Box::new(Composite::Sequence(vec![
run(na, 1.0),
Composite::Delay(10.0),
run(na, 0.0)
])),
iterations: Some(3),
reset: false,
}
);
assert_eq!(looped.0.values, std::slice::from_ref(&a));
let apart = Animation::parallel([step(&a, 1.0)]).stop_together(false);
assert!(matches!(
apart.0.spec,
Composite::Parallel {
stop_together: false,
..
}
));
let delayed = Animation::timing(
&a,
1.0,
Timing {
delay_ms: 40.0,
..Timing::default()
},
);
assert!(matches!(
delayed.0.spec,
Composite::Run {
driver: Driver::Timing {
delay_ms: 40.0,
duration_ms: 300.0,
easing: Easing::EaseInOut,
..
},
..
}
));
}
#[test]
fn composites_start_stop_reset_and_release_by_key() {
let executor = Rc::new(Executor::default());
let x = NativeValue::new(&executor, 0.0);
let _ = ops(&executor);
let jump = Animation::sequence([
Animation::timing(&x, 10.0, Timing::default()),
Animation::spring(&x, 0.0, Spring::default()),
]);
jump.stop();
jump.reset();
assert_eq!(ops(&executor), []);
let _ = jump.start();
let [
AnimationOp::StartComposite {
animation,
key,
spec,
},
] = &ops(&executor)[..]
else {
panic!("a composite start");
};
assert_eq!((animation % 2, key % 2), (1, 1), "the core's ids are odd");
assert_eq!(spec, &jump.0.spec);
let (first, key) = (*animation, *key);
let _ = jump.clone().start();
let again = ops(&executor);
assert!(matches!(
&again[..],
[
AnimationOp::StopAnimation { animation: a },
AnimationOp::StartComposite { animation: b, key: k, .. },
] if *a == first && *b != first && *k == key
));
jump.stop();
assert!(matches!(
&ops(&executor)[..],
[AnimationOp::StopAnimation { .. }]
));
jump.stop();
assert_eq!(ops(&executor), [], "stopped once");
jump.reset();
assert_eq!(ops(&executor), [AnimationOp::ResetComposite { key }]);
drop(jump);
assert_eq!(ops(&executor), [AnimationOp::ReleaseComposite { key }]);
}
#[test]
fn delays_alone_end_at_once() {
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
let end = Animation::sequence([Animation::delay(100.0)]).start();
assert!(runtime.block_on(end.into_future()));
}
#[test]
fn values_derive_like_their_nodes() {
let executor = Rc::new(Executor::default());
let t = NativeValue::new(&executor, 0.0);
let right = Interpolation {
extrapolate_right: Extrapolate::Extend,
..Interpolation::default()
};
let angle = t.interpolate_with(&[0.0, 1.0], Output::Numbers(vec![0.0, 180.0]), right);
let [
..,
AnimationOp::CreateInterpolate {
extrapolate_left,
extrapolate_right,
easing,
..
},
] = &ops(&executor)[..]
else {
panic!("an interpolation");
};
assert_eq!(
(*extrapolate_left, *extrapolate_right, *easing),
(Extrapolate::Clamp, Extrapolate::Extend, Easing::Linear)
);
assert_eq!(
angle,
t.node()
.interpolate_with(&[0.0, 1.0], Output::Numbers(vec![0.0, 180.0]), right)
);
assert_eq!(t.diff_clamp(0.0, 44.0), t.node().diff_clamp(0.0, 44.0));
assert_eq!(t.mul(-1.0), t.node().mul(-1.0));
}
#[test]
fn curves_sample_as_the_graph_runs_them() {
let spring = sample_spring(0.0, 1.0, Spring::default(), 60.0);
assert_eq!(spring[0], 0.0);
assert!((spring.last().unwrap() - 1.0).abs() < 1e-3, "{spring:?}");
let fast = sample_spring(0.0, 1.0, Spring::default(), 120.0);
assert!(fast.len() > spring.len() * 3 / 2, "{}", fast.len());
let undamped = Spring {
damping: 0.0,
..Spring::default()
};
assert_eq!(
sample_spring(0.0, 1.0, undamped, 60.0).len(),
nsh_animation::MAX_SAMPLES
);
let decay = sample_decay(0.0, 1000.0, 0.998, 60.0);
assert!(decay.windows(2).all(|w| w[1] >= w[0]), "{decay:?}");
assert!(*decay.last().unwrap() > 400.0, "{decay:?}");
let within = sample_decay_within(0.0, 1000.0, 0.998, (0.0, 100.0), 0.0, 60.0);
assert!(within.iter().all(|&x| (0.0..=100.0).contains(&x)));
assert_eq!(*within.last().unwrap(), 100.0);
let curve = super::super::sample_easing(Easing::EaseInOut, 5);
assert_eq!((curve[0], curve[4], curve.len()), (0.0, 1.0, 5));
}
}