GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
44 of 46, 0 excluded
95.7%
Functions:
2 of 2, 0 excluded
100.0%
Branches:
36 of 84, 0 excluded
42.9%

libs/core/src/eu/core/tablelayout.h
Line Branch Exec Source
1 #pragma once
2
3
4 #include "eu/base/numeric.h"
5
6 #include "eu/assert/assert.h"
7
8
9 namespace eu::core
10 {
11 /** Calculates a table layout based on the input layout.
12 * Since rows and columns are handled the same, this functions only handled 1d tables.
13 *
14 * Positive values in the array mean absolute pixel size
15 * Zero values are invalid.
16 * Negative values indicate the scaling size and the exact ration will be proportional to the rest of the scaling values.
17 *
18 * If available size < min_size scaling areas will have "zero" and absolute areas will be resized.
19 */
20 template <typename T>
21 std::vector<T>
22 7 perform_table_layout(const std::vector<T>& pieces, T total_size, T zero = 0)
23 {
24
2/20
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 16 taken 3 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 54 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 52 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 16 taken 4 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 54 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 52 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
7 ASSERTX(total_size >= 0, total_size);
25
2/12
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 23 taken 3 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 23 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 68 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 23 taken 4 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 23 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 68 not taken.
7 ASSERT(zero <= 0);
26
27 7 T min_size = 0;
28 7 T total_percentage = 0;
29
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 31 → 25 taken 10 times.
✓ Branch 31 → 32 taken 3 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 31 → 25 taken 11 times.
✓ Branch 31 → 32 taken 4 times.
28 for(T f: pieces)
30 {
31
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 26 → 27 taken 6 times.
✓ Branch 26 → 28 taken 4 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 26 → 27 taken 8 times.
✓ Branch 26 → 28 taken 3 times.
21 if(f > 0)
32 {
33 14 min_size += f;
34 }
35 else
36 {
37 7 total_percentage += -f;
38 }
39 }
40 7 const T size_left = total_size - min_size;
41
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 34 taken 2 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 32 → 33 taken 2 times.
✓ Branch 32 → 34 taken 2 times.
7 const T fixed_scale = min_size < total_size ? 1 : total_size / min_size;
42
43 7 std::vector<T> ret;
44
2/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 36 → 37 taken 3 times.
✗ Branch 36 → 74 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 36 → 37 taken 4 times.
✗ Branch 36 → 74 not taken.
7 ret.reserve(pieces.size());
45
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 49 → 39 taken 10 times.
✓ Branch 49 → 50 taken 3 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 49 → 39 taken 11 times.
✓ Branch 49 → 50 taken 4 times.
28 for(T f: pieces)
46 {
47
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 40 → 41 taken 6 times.
✓ Branch 40 → 43 taken 4 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 40 → 41 taken 8 times.
✓ Branch 40 → 43 taken 3 times.
21 if(f > 0)
48 {
49
2/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 41 → 42 taken 6 times.
✗ Branch 41 → 71 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 41 → 42 taken 8 times.
✗ Branch 41 → 71 not taken.
14 ret.push_back(f * fixed_scale);
50 }
51 else
52 {
53
4/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 43 → 44 taken 2 times.
✓ Branch 43 → 45 taken 2 times.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 43 → 44 taken 2 times.
✓ Branch 43 → 45 taken 1 time.
7 if(size_left <= 0)
54 {
55 // no more room, add 0
56
2/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 44 → 47 taken 2 times.
✗ Branch 44 → 73 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 44 → 47 taken 2 times.
✗ Branch 44 → 73 not taken.
4 ret.push_back(zero);
57 }
58 else
59 {
60 3 const T p = (-f / total_percentage);
61 3 const T size = p * size_left;
62
2/4
std::vector<float, std::allocator<float> > eu::core::perform_table_layout<float>(std::vector<float, std::allocator<float> > const&, float, float):
✓ Branch 45 → 46 taken 2 times.
✗ Branch 45 → 72 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 72 not taken.
3 ret.push_back(size);
63 }
64 }
65 }
66 7 return ret;
67 }
68
69 }
70
71