eazy_core/easing/root/sqrt.rs
1//! # The Square Root Curve.
2//!
3//! An algebric curve of degree 1/2.
4
5use crate::easing::Curve;
6
7use libm::sqrtf;
8
9/// ### The [`InSqrt`] Easing Function.
10///
11/// #### examples.
12///
13/// ```rust
14/// use eazy::Curve;
15/// use eazy::root::sqrt::InSqrt;
16///
17/// let p = InSqrt.y(0.25);
18/// ```
19#[derive(Debug)]
20pub struct InSqrt;
21
22impl Curve for InSqrt {
23 #[inline(always)]
24 fn y(&self, p: f32) -> f32 {
25 1.0 - OutSqrt.y(1.0 - p)
26 }
27}
28
29/// ### The [`InOutSqrt`] Easing Function.
30///
31/// #### examples.
32///
33/// ```rust
34/// use eazy::Curve;
35/// use eazy::root::sqrt::InOutSqrt;
36///
37/// let p = InOutSqrt.y(0.25);
38/// ```
39#[derive(Debug)]
40pub struct InOutSqrt;
41
42impl Curve for InOutSqrt {
43 #[inline(always)]
44 fn y(&self, p: f32) -> f32 {
45 let t = p * 2.0;
46
47 if t < 1.0 {
48 return 0.5 - 0.5 * OutSqrt.y(1.0 - t);
49 }
50
51 0.5 + 0.5 * OutSqrt.y(t - 1.0)
52 }
53}
54
55/// ### The [`OutSqrt`] Easing Function.
56///
57/// #### examples.
58///
59/// ```rust
60/// use eazy::Curve;
61/// use eazy::root::sqrt::OutSqrt;
62///
63/// let p = OutSqrt.y(0.25);
64/// ```
65#[derive(Debug)]
66pub struct OutSqrt;
67
68impl Curve for OutSqrt {
69 #[inline(always)]
70 fn y(&self, p: f32) -> f32 {
71 sqrtf(p)
72 }
73}