GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
22 of 28, 0 excluded
78.6%
Functions:
10 of 11, 0 excluded
90.9%
Branches:
12 of 16, 0 excluded
75.0%

libs/base/src/base/numeric.h
Line Branch Exec Source
1 #pragma once
2
3 #include "base/ints.h"
4
5
6 namespace eu
7 {
8 namespace kk
9 {
10 constexpr float epsilon = 0.0001f;
11 }
12
13 constexpr float pi = 3.1415926535897932384626433832795f;
14 // constexpr float half_pi = pi / 2.0f;
15
16 438 constexpr float cabs(float r)
17 {
18 return r >= 0.0f
19
2/2
✓ Branch 2 → 3 taken 429 times.
✓ Branch 2 → 4 taken 9 times.
438 ? r
20 438 : -r
21 ;
22 }
23
24 /** \addtogroup math
25 * @{
26 */
27 414 constexpr bool is_zero(float r, float epsilon = kk::epsilon)
28 {
29 414 return cabs(r) < epsilon;
30 }
31
32 constexpr bool
33 345 is_equal(float lhs, float rhs, float epsilon = kk::epsilon)
34 {
35 345 return is_zero(lhs - rhs, epsilon);
36 }
37
38 int
39 floor_to_int(float v);
40
41 int
42 ceil_to_int(float v);
43
44
45 /** Calculates the sign as a positive or a negative int.
46 @returns 1 if r is greater than 0, -1 if not.
47 */
48 constexpr int
49 3 get_sign(float r)
50 {
51
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 1 time.
3 if(r >= 0.0f) { return 1; }
52 1 else { return -1; }
53 }
54
55
56 /// Returns `1` if `true` or -1
57 constexpr float
58 2 get_sign(bool b)
59 {
60
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
2 if(b) { return 1.0f; }
61 1 else { return -1.0f; }
62 }
63
64
65 constexpr float
66 8 lerp_float(float f, float scale, float t)
67 {
68 8 return f + (t - f) * scale;
69 }
70
71 /// Return `r * r`
72 constexpr float
73 1 square(float r)
74 {
75 1 return r * r;
76 }
77
78
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
2 constexpr float min(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; }
79
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 4 taken 1 time.
2 constexpr float max(float lhs, float rhs) { return lhs > rhs ? lhs : rhs; }
80
81
82 /// If the `value` is close to zero, `def` is returned
83 constexpr float
84 12 clamp_zero(float value, float def = 0.0f, float epsilon = kk::epsilon)
85 {
86
2/2
✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 5 taken 7 times.
12 if(is_zero(value, epsilon)) { return def; }
87 7 else { return value; }
88 }
89
90 constexpr float keep_within01(float f)
91 {
92 if (f <= 0)
93 {
94 return 0;
95 }
96
97 if (f >= 1)
98 {
99 return 1;
100 }
101
102 return f;
103 }
104
105 /** @}*/
106 }
107
108