eazy_core/easing/logarithmic/
log10.rs

1//! # The Log10 Curve.
2
3use crate::easing::Curve;
4
5use libm::log10f;
6
7/// ### The [`InLog10`] Easing Function.
8///
9/// #### examples.
10///
11/// ```rust
12/// use eazy::Curve;
13/// use eazy::logarithmic::log10::InLog10;
14///
15/// let p = InLog10.y(0.25);
16/// ```
17#[derive(Debug)]
18pub struct InLog10;
19
20impl Curve for InLog10 {
21  #[inline(always)]
22  fn y(&self, p: f32) -> f32 {
23    1.0 - OutLog10.y(1.0 - p)
24  }
25}
26
27#[test]
28fn test_in_log10() {
29  let p = InLog10.y(1.0);
30
31  assert_eq!(p, 1.0);
32}
33
34/// ### The [`OutLog10`] Easing Function.
35///
36/// #### examples.
37///
38/// ```rust
39/// use eazy::Curve;
40/// use eazy::logarithmic::log10::OutLog10;
41///
42/// let p = OutLog10.y(0.25);
43/// ```
44#[derive(Debug)]
45pub struct OutLog10;
46
47impl Curve for OutLog10 {
48  #[inline(always)]
49  fn y(&self, p: f32) -> f32 {
50    log10f((p * 9.0) + 1.0)
51  }
52}
53
54#[test]
55fn test_out_log10() {
56  let p = OutLog10.y(1.0);
57
58  assert_eq!(p, 1.0);
59}
60
61/// ### The [`InOutLog10`] Easing Function.
62///
63/// #### examples.
64///
65/// ```rust
66/// use eazy::Curve;
67/// use eazy::logarithmic::log10::InOutLog10;
68///
69/// let p = InOutLog10.y(0.25);
70/// ```
71#[derive(Debug)]
72pub struct InOutLog10;
73
74impl Curve for InOutLog10 {
75  #[inline(always)]
76  fn y(&self, p: f32) -> f32 {
77    let t = p * 2.0;
78
79    if t < 1.0 {
80      return 0.5 - 0.5 * OutLog10.y(1.0 - t);
81    }
82
83    0.5 + 0.5 * OutLog10.y(t - 1.0)
84  }
85}
86
87#[test]
88fn test_in_out_log10() {
89  let p = InOutLog10.y(1.0);
90
91  assert_eq!(p, 1.0);
92}