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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
declare_tween!(
    /// A circular tween in. Go [here](https://easings.net/#easeInCirc) for a visual demonstration.
    pub struct CircIn;

    /// Creates a new [CircIn] Tweener.
    pub fn circ_in;

    /// Creates a new [CircIn] Tweener at the given time.
    pub fn circ_in_at;

    pub fn tween<Value: crate::TweenValue>(&mut self, value_delta: Value, percent: f32) -> Value {
        #[cfg(feature = "libm")]
        let scalar = 1.0 - libm::sqrtf(1.0 - percent * percent);

        #[cfg(feature = "std")]
        let scalar = 1.0 - (1.0 - percent * percent).sqrt();

        value_delta.scale(scalar)
    }
);

declare_tween!(
    /// A circular tween out. Go [here](https://easings.net/#easeOutCirc) for a visual demonstration.
    pub struct CircOut;

    /// Creates a new [CircOut] Tweener.
    pub fn circ_out;

    /// Creates a new [CircOut] Tweener at the given time.
    pub fn circ_out_at;

    pub fn tween<Value: crate::TweenValue>(&mut self, value_delta: Value, percent: f32) -> Value {
        let t = percent - 1.0;

        #[cfg(feature = "libm")]
        let scalar = libm::sqrtf(1.0 - t * t);

        #[cfg(feature = "std")]
        let scalar = (1.0 - t * t).sqrt();

        value_delta.scale(scalar)
    }
);

declare_tween!(
    /// A circular tween in and out. Go [here](https://easings.net/#easeInOutCirc) for a visual demonstration.
    pub struct CircInOut;

    /// Creates a new [CircInOut] Tweener.
    pub fn circ_in_out;

    /// Creates a new [CircInOut] Tweener at the given time.
    pub fn circ_in_out_at;

    pub fn tween<Value: crate::TweenValue>(&mut self, value_delta: Value, mut percent: f32) -> Value {
        percent *= 2.0;

        let scalar = if percent < 1.0 {
            #[cfg(feature = "libm")]
            let o = 1.0 - libm::sqrtf(1.0 - percent * percent);

            #[cfg(feature = "std")]
            let o = 1.0 - (1.0 - percent * percent).sqrt();

            o
        } else {
            let percent = percent - 2.0;

            #[cfg(feature = "libm")]
            let o = libm::sqrtf(1.0 - percent * percent) + 1.0;

            #[cfg(feature = "std")]
            let o = (1.0 - percent * percent).sqrt() + 1.0;

            o
        };

        value_delta.scale(scalar / 2.0)
    }
);

test_tween!(Circ);