1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Instantaneous movement after a delay.

use num_traits::Float;

use super::{Approximation, Curve};

/// Instantaneous movement after a delay.
#[derive(Copy, Clone, Debug)]
pub struct Delay<T>
where
    T: Float,
{
    /// Start value of the animation.
    pub from_value: T,

    /// Target value of the animation.
    pub to_value: T,

    /// The amount of time to wait before movement.
    pub duration: f32,
}

impl<T> Curve for Delay<T>
where
    T: Float,
{
    type Value = T;
    type Velocity = T;

    fn approximate(&self, time: f32) -> Approximation<T> {
        if time < self.duration {
            Approximation {
                value: self.from_value,
                velocity: T::zero(),
            }
        } else {
            Approximation {
                value: self.to_value,
                velocity: T::zero(),
            }
        }
    }

    fn target(&self) -> T {
        self.to_value
    }
}