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 → 70 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 68 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 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 → 70 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 68 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 76 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 → 84 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 → 84 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 39 → 25 taken 10 times.
✓ Branch 39 → 40 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 39 → 25 taken 11 times.
✓ Branch 39 → 40 taken 4 times.
35 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 27 → 28 taken 6 times.
✓ Branch 27 → 29 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 27 → 28 taken 8 times.
✓ Branch 27 → 29 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 40 → 41 taken 1 time.
✓ Branch 40 → 42 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 40 → 41 taken 2 times.
✓ Branch 40 → 42 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 44 → 45 taken 3 times.
✗ Branch 44 → 90 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 → 45 taken 4 times.
✗ Branch 44 → 90 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 65 → 47 taken 10 times.
✓ Branch 65 → 66 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 65 → 47 taken 11 times.
✓ Branch 65 → 66 taken 4 times.
35 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 49 → 50 taken 6 times.
✓ Branch 49 → 52 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 49 → 50 taken 8 times.
✓ Branch 49 → 52 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 50 → 51 taken 6 times.
✗ Branch 50 → 87 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 50 → 51 taken 8 times.
✗ Branch 50 → 87 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 52 → 53 taken 2 times.
✓ Branch 52 → 54 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 52 → 53 taken 2 times.
✓ Branch 52 → 54 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 53 → 56 taken 2 times.
✗ Branch 53 → 89 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 53 → 56 taken 2 times.
✗ Branch 53 → 89 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 54 → 55 taken 2 times.
✗ Branch 54 → 88 not taken.
std::vector<int, std::allocator<int> > eu::core::perform_table_layout<int>(std::vector<int, std::allocator<int> > const&, int, int):
✓ Branch 54 → 55 taken 1 time.
✗ Branch 54 → 88 not taken.
3 ret.push_back(size);
63 }
64 }
65 }
66 7 return ret;
67 }
68
69 }
70
71