GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
14 of 19, 0 excluded
73.7%
Functions:
4 of 5, 0 excluded
80.0%
Branches:
4 of 6, 0 excluded
66.7%

libs/core/src/eu/core/scurve.cc
Line Branch Exec Source
1 #include "eu/core/scurve.h"
2
3 #include "eu/assert/assert.h"
4 #include "eu/base/cint.h"
5
6 #include <cmath>
7
8 namespace eu::core
9 {
10
11 5 float square(float x)
12 {
13 5 return x * x;
14 }
15
16 3 SCurve s_curve_from_input(float mx, float my)
17 {
18 3 const auto p0 = mx;
19 // gustav addition: switch p1 to match curve to xy
20
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 1 time.
3 const auto p1 = mx > 0.5f ? my : 1 - my;
21
22 6 const auto o = [](float x)
23 {
24
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 5 times.
6 return x < 0.5f ? -0.5f * (2.0f * x * (2.0f * x - 2.0f)) : 2.0f * (square(x - 0.5f)) + 0.5f;
25 };
26 3 const auto q0 = o(p0);
27 3 const auto q1 = o(p1);
28
29 3 const auto a = [](float x)
30 {
31 3 return std::pow(3.0f, x);
32 };
33 3 const auto slope = a(10 * (q0 - 0.5f));
34 3 const auto threshold = 0.5f + (0.5f * (1.0f - q1));
35 3 return {slope, threshold};
36 }
37
38 float calculate_s_curve(float x, float slope, float threshold)
39 {
40 constexpr float machine_epsilon = 0.00001f;
41 return x < threshold ?
42 threshold * x / (x + slope * (threshold - x) + machine_epsilon) :
43 ((1 - threshold) * (x - 1)) / (1 - x - slope * (threshold - x) + machine_epsilon) + 1
44 ;
45 }
46
47 } // namespace eu::core
48