qxLib
easing_functions.h
Go to the documentation of this file.
1 /**
2 
3  @file easing_functions.h
4  @brief File contains easing functions
5  @details See https://doc.magnum.graphics/magnum/namespaceMagnum_1_1Animation_1_1Easing.html
6  for details
7  For all y = f(x):
8  0.0 <= x <= 1.0
9  f(0.0) = 0.0 (with epsilon = qx::easing::eps<T>())
10  f(1.0) = 1.0 (with epsilon = qx::easing::eps<T>())
11  @author Khrapov
12  @date 4.05.2021
13  @copyright (c) Nick Khrapov, 2021. All right reserved.
14 
15 **/
16 #pragma once
17 
18 #include <qx/math/float_compare.h>
19 
20 #include <cmath>
21 #include <functional>
22 #include <numbers>
23 
24 namespace qx::easing
25 {
26 
27 // ------------------------------- function type -------------------------------
28 
29 template<class T>
30 using func = std::function<T(T)>;
31 
32 // ---------------------- epsilon for borders guarantees -----------------------
33 
34 template<class T>
35 constexpr T eps();
36 
37 template<>
38 constexpr float eps();
39 
40 // ----------------------------- easing functions ------------------------------
41 
42 template<class T>
43 constexpr T linear_func(T x) noexcept;
44 
45 constexpr auto linear = linear_func<float>;
46 
47 template<class T>
48 constexpr T step_func(T x) noexcept;
49 
50 constexpr auto step = step_func<float>;
51 
52 template<class T>
53 inline T smooth_step_func(T x) noexcept;
54 
55 constexpr auto smooth_step = smooth_step_func<float>;
56 
57 template<class T>
58 inline T smoother_step_func(T x) noexcept;
59 
60 constexpr auto smoother_step = smoother_step_func<float>;
61 
62 template<class T>
63 inline T quadratic_in_func(T x) noexcept;
64 
65 constexpr auto quadratic_in = quadratic_in_func<float>;
66 
67 template<class T>
68 constexpr T quadratic_out_func(T x) noexcept;
69 
70 constexpr auto quadratic_out = quadratic_out_func<float>;
71 
72 template<class T>
73 inline T quadratic_in_out_func(T x) noexcept;
74 
75 constexpr auto quadratic_in_out = quadratic_in_out_func<float>;
76 
77 template<class T>
78 inline T cubic_in_func(T x) noexcept;
79 
80 constexpr auto cubic_in = cubic_in_func<float>;
81 
82 template<class T>
83 inline T cubic_out_func(T x) noexcept;
84 
85 constexpr auto cubic_out = cubic_out_func<float>;
86 
87 template<class T>
88 inline T cubic_in_out_func(T x) noexcept;
89 
90 constexpr auto cubic_in_out = cubic_in_out_func<float>;
91 
92 template<class T>
93 inline T quartic_in_func(T x) noexcept;
94 
95 constexpr auto quartic_in = quartic_in_func<float>;
96 
97 template<class T>
98 inline T quartic_out_func(T x) noexcept;
99 
100 constexpr auto quartic_out = quartic_out_func<float>;
101 
102 template<class T>
103 inline T quartic_in_out_func(T x) noexcept;
104 
105 constexpr auto quartic_in_out = quartic_in_out_func<float>;
106 
107 template<class T>
108 inline T quintic_in_func(T x) noexcept;
109 
110 constexpr auto quintic_in = quintic_in_func<float>;
111 
112 template<class T>
113 inline T quintic_out_func(T x) noexcept;
114 
115 constexpr auto quintic_out = quintic_out_func<float>;
116 
117 template<class T>
118 inline T quintic_in_out_func(T x) noexcept;
119 
120 constexpr auto quintic_in_out = quintic_in_out_func<float>;
121 
122 template<class T>
123 inline T sine_in_func(T x) noexcept;
124 
125 constexpr auto sine_in = sine_in_func<float>;
126 
127 template<class T>
128 inline T sine_out_func(T x) noexcept;
129 
130 constexpr auto sine_out = sine_out_func<float>;
131 
132 template<class T>
133 inline T sine_in_out_func(T x) noexcept;
134 
135 constexpr auto sine_in_out = sine_in_out_func<float>;
136 
137 template<class T>
138 inline T circular_in_func(T x) noexcept;
139 
140 constexpr auto circular_in = circular_in_func<float>;
141 
142 template<class T>
143 inline T circular_out_func(T x) noexcept;
144 
145 constexpr auto circular_out = circular_out_func<float>;
146 
147 template<class T>
148 inline T circular_in_out_func(T x) noexcept;
149 
150 constexpr auto circular_in_out = circular_in_out_func<float>;
151 
152 template<class T>
153 inline T exponential_in_func(T x) noexcept;
154 
155 constexpr auto exponential_in = exponential_in_func<float>;
156 
157 template<class T>
158 inline T exponential_out_func(T x) noexcept;
159 
160 constexpr auto exponential_out = exponential_out_func<float>;
161 
162 template<class T>
163 inline T exponential_in_out_func(T x) noexcept;
164 
165 constexpr auto exponential_in_out = exponential_in_out_func<float>;
166 
167 template<class T>
168 inline T elastic_in_func(T x) noexcept;
169 
170 constexpr auto elastic_in = elastic_in_func<float>;
171 
172 template<class T>
173 inline T elastic_out_func(T x) noexcept;
174 
175 constexpr auto elastic_out = elastic_out_func<float>;
176 
177 template<class T>
178 inline T elastic_in_out_func(T x) noexcept;
179 
180 constexpr auto elastic_in_out = elastic_in_out_func<float>;
181 
182 template<class T>
183 inline T back_in_func(T x) noexcept;
184 
185 constexpr auto back_in = back_in_func<float>;
186 
187 template<class T>
188 inline T back_out_func(T x) noexcept;
189 
190 constexpr auto back_out = back_out_func<float>;
191 
192 template<class T>
193 inline T back_in_out_func(T x) noexcept;
194 
195 constexpr auto back_in_out = back_in_out_func<float>;
196 
197 template<class T>
198 inline T bounce_out_func(T x) noexcept;
199 
200 constexpr auto bounce_out = bounce_out_func<float>;
201 
202 template<class T>
203 inline T bounce_in_func(T x) noexcept;
204 
205 constexpr auto bounce_in = bounce_in_func<float>;
206 
207 template<class T>
208 inline T bounce_in_out_func(T x) noexcept;
209 
210 constexpr auto bounce_in_out = bounce_in_out_func<float>;
211 
212 } // namespace qx::easing
213