GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 73.0% 710 / 0 / 972
Functions: 76.7% 89 / 0 / 116
Branches: 64.8% 249 / 0 / 384
Decisions: 22.7% 35 / - / 154

firmware/libfirmware/util/include/rusefi/interpolation.h
Line Branch Decision Exec Source
1 /**
2 * @file interpolation.h
3 */
4
5 #pragma once
6
7 #include <cstdint>
8
9 #include "scaled_channel.h"
10
11 namespace priv {
12 struct BinResult
13 {
14 size_t Idx;
15 float Frac;
16 };
17
18 /**
19 * @brief Finds the location of a value in the bin array.
20 *
21 * @param value The value to find in the bins.
22 * @return A result containing the index to the left of the value,
23 * and how far from (idx) to (idx + 1) the value is located.
24 */
25 template<class TBin, int TSize>
26 4241819 BinResult getBin(float value, const TBin (&bins)[TSize]) {
27 // Enforce numeric only (int, float, uintx_t, etc)
28 static_assert(std::is_arithmetic_v<TBin>, "Table bins must be an arithmetic type");
29
30 // Enforce that there are enough bins to make sense (what does one bin even mean?)
31 static_assert(TSize >= 2);
32
33 // Handle NaN
34
34/72
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 1 not taken.
✓ Branch 2 taken 341 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 182684 times.
priv::BinResult priv::getBin<float, 2500>(float, float const (&) [2500]):
✗ Branch 1 not taken.
✓ Branch 2 taken 25000 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1988 times.
priv::BinResult priv::getBin<float, 2>(float, float const (&) [2]):
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 15 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
priv::BinResult priv::getBin<float, 4>(float, float const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 284 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91144 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 353190 times.
priv::BinResult priv::getBin<int, 4>(float, int const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91144 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 29155 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91140 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 40714 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91157 times.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 551 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 57350 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 1 not taken.
✓ Branch 2 taken 381 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 179 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 20875 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 203252 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91200 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 345807 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 124471 times.
priv::BinResult priv::getBin<unsigned int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 91151 times.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✗ Branch 1 not taken.
✓ Branch 2 taken 381 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✗ Branch 1 not taken.
✓ Branch 2 taken 4680 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 438940 times.
priv::BinResult priv::getBin<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned short, 3>(float, unsigned short const (&) [3]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1416786 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 385974 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 61720 times.
3/26
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 341 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 1416786 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 385974 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
4241819 if (std::isnan(value)) {
35 2 return { 0, 0.0f };
36 }
37
38 // Handle off-scale low
39
57/72
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 0 not taken.
✓ Branch 1 taken 341 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 403 times.
✓ Branch 1 taken 182281 times.
priv::BinResult priv::getBin<float, 2500>(float, float const (&) [2500]):
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 24990 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1988 times.
priv::BinResult priv::getBin<float, 2>(float, float const (&) [2]):
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 8 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 6 times.
priv::BinResult priv::getBin<float, 4>(float, float const (&) [4]):
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 81 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 241 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 91144 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 146961 times.
✓ Branch 1 taken 206229 times.
priv::BinResult priv::getBin<int, 4>(float, int const (&) [4]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 52 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 91144 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 29150 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 91139 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 552 times.
✓ Branch 1 taken 40162 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 0 not taken.
✓ Branch 1 taken 91157 times.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✓ Branch 0 taken 551 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 57349 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 0 not taken.
✓ Branch 1 taken 381 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 178 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20855 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 74135 times.
✓ Branch 1 taken 129117 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 91192 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 234597 times.
✓ Branch 1 taken 111210 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 66242 times.
✓ Branch 1 taken 58229 times.
priv::BinResult priv::getBin<unsigned int, 2>(float, unsigned int const (&) [2]):
✓ Branch 0 taken 91151 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 179 times.
✓ Branch 1 taken 202 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 1016 times.
✓ Branch 1 taken 3664 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 205637 times.
✓ Branch 1 taken 233303 times.
priv::BinResult priv::getBin<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 3>(float, unsigned short const (&) [3]):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 639615 times.
✓ Branch 1 taken 777171 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 273540 times.
✓ Branch 1 taken 112434 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 39822 times.
✓ Branch 1 taken 21898 times.
5/26
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 341 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 639615 times.
✓ Decision 'false' taken 777171 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 273540 times.
✓ Decision 'false' taken 112434 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
4241817 if (value <= bins[0]) {
40 1774519 return { 0, 0.0f };
41 }
42
43 // Handle off-scale high
44
55/72
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 293 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 349 times.
✓ Branch 1 taken 181932 times.
priv::BinResult priv::getBin<float, 2500>(float, float const (&) [2500]):
✗ Branch 0 not taken.
✓ Branch 1 taken 24990 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1988 times.
priv::BinResult priv::getBin<float, 2>(float, float const (&) [2]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 5 times.
priv::BinResult priv::getBin<float, 4>(float, float const (&) [4]):
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 68 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 209 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 91144 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 5536 times.
✓ Branch 1 taken 200693 times.
priv::BinResult priv::getBin<int, 4>(float, int const (&) [4]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 44 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 91144 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 29146 times.
✓ Branch 1 taken 4 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 91108 times.
✓ Branch 1 taken 31 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 40161 times.
✓ Branch 1 taken 1 time.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 91156 times.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 57348 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 0 not taken.
✓ Branch 1 taken 381 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 177 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✗ Branch 0 not taken.
✓ Branch 1 taken 20855 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 91039 times.
✓ Branch 1 taken 38078 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 91184 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 91026 times.
✓ Branch 1 taken 20184 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 58224 times.
priv::BinResult priv::getBin<unsigned int, 2>(float, unsigned int const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 48 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 1104 times.
✓ Branch 1 taken 2560 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 233053 times.
priv::BinResult priv::getBin<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 3>(float, unsigned short const (&) [3]):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 707466 times.
✓ Branch 1 taken 69705 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 112311 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 21883 times.
6/26
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 48 times.
✓ Decision 'false' taken 293 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 707466 times.
✓ Decision 'false' taken 69705 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 123 times.
✓ Decision 'false' taken 112311 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
2467298 if (value >= bins[TSize - 1]) {
45 1057600 return { TSize - 2, 1.0f };
46 }
47
48 1409698 size_t idx = 0;
49
50 // Find the last index less than the searched value
51 // Linear search for now, maybe binary search in future
52 // after collecting real perf data
53
31/72
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 1473 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 1818570 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 2500>(float, float const (&) [2500]):
✓ Branch 0 taken 31235592 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 0 taken 53604 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 2>(float, float const (&) [2]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 4>(float, float const (&) [4]):
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✓ Branch 0 taken 511 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 0 taken 364552 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 1004439 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<int, 4>(float, int const (&) [4]):
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 0 taken 996097 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 456746 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 286739 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 1612 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 20855 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 60240 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 273294 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 35387 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 348305 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned int, 2>(float, unsigned int const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 15757 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 1952727 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 3>(float, unsigned short const (&) [3]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 90766 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 401380 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 30633 times.
✗ Branch 1 not taken.
3/26
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 1473 times.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 90766 times.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 401380 times.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
39450552 for (idx = 0; idx < TSize - 1; idx++) {
54
60/72
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Branch 1 taken 293 times.
✓ Branch 2 taken 1180 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 1 taken 181932 times.
✓ Branch 2 taken 1636638 times.
priv::BinResult priv::getBin<float, 2500>(float, float const (&) [2500]):
✓ Branch 1 taken 24990 times.
✓ Branch 2 taken 31210602 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 1 taken 1988 times.
✓ Branch 2 taken 51616 times.
priv::BinResult priv::getBin<float, 2>(float, float const (&) [2]):
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
priv::BinResult priv::getBin<float, 4>(float, float const (&) [4]):
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 88 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✓ Branch 1 taken 209 times.
✓ Branch 2 taken 302 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 1 taken 91144 times.
✓ Branch 2 taken 273408 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 1 taken 200693 times.
✓ Branch 2 taken 803746 times.
priv::BinResult priv::getBin<int, 4>(float, int const (&) [4]):
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 56 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 1 taken 91144 times.
✓ Branch 2 taken 904953 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 6 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 70 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 4 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 1 taken 91156 times.
✓ Branch 2 taken 365590 times.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 1 taken 57348 times.
✓ Branch 2 taken 229391 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✓ Branch 1 taken 381 times.
✓ Branch 2 taken 387 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 1 taken 177 times.
✓ Branch 2 taken 1435 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 1 taken 20855 times.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 1 taken 38078 times.
✓ Branch 2 taken 22162 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 1 taken 91184 times.
✓ Branch 2 taken 182110 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 1 taken 20184 times.
✓ Branch 2 taken 15203 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 1 taken 58224 times.
✓ Branch 2 taken 290081 times.
priv::BinResult priv::getBin<unsigned int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 71 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 1 taken 2560 times.
✓ Branch 2 taken 13197 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 1 taken 233053 times.
✓ Branch 2 taken 1719674 times.
priv::BinResult priv::getBin<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned short, 3>(float, unsigned short const (&) [3]):
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 time.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 1 taken 69705 times.
✓ Branch 2 taken 21061 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 1 taken 112311 times.
✓ Branch 2 taken 289069 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 1 taken 21883 times.
✓ Branch 2 taken 8750 times.
6/26
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 293 times.
✓ Decision 'false' taken 1180 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 69705 times.
✓ Decision 'false' taken 21061 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 112311 times.
✓ Decision 'false' taken 289069 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
39450552 if (bins[idx + 1] > value) {
55 1409698 break;
56 }
57 }
58
59 1409698 float low = bins[idx];
60 1409698 float high = bins[idx + 1];
61
62 // Compute how far along the bin we are
63 // (0.0f = left side, 1.0f = right side)
64 1409698 float fraction = (value - low) / (high - low);
65
66 1409698 return { idx, fraction };
67 }
68
69 /**
70 * @brief Finds the location of a closest value in the bin array.
71 *
72 * @param value The value to find in the bins.
73 * @return A result containing the index of the closest to bin value,
74 * and how far from (idx) to (idx + 1) or (idx - 1) the value is located.
75 * If value is outside of bin - {0, <-1.0} or {Tsize - 1, >+1.0} is returned
76 */
77 template<class TBin, int TSize>
78 80008 struct BinResult getClosestBin(float value, const TBin (&bins)[TSize]) {
79 // Enforce numeric only (int, float, uintx_t, etc)
80 static_assert(std::is_arithmetic_v<TBin>, "Table bins must be an arithmetic type");
81
82 // Enforce that there are enough bins to make sense (what does one bin even mean?)
83 static_assert(TSize >= 2);
84
85 // Handle NaN
86
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 80000 times.
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 80000 times.
80008 if (std::isnan(value)) {
87 return { 0, -1.0f };
88 }
89
90 80008 const size_t lastIdx = TSize - 1;
91 80008 size_t idx = 0;
92 float closest;
93 float step;
94
95
3/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 80000 times.
✗ Branch 1 not taken.
3/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 5 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 80000 times.
✗ Decision 'false' not taken.
80008 if (value <= bins[0]) {
96 // Handle off-scale low
97 // virtual bins[-1] located at the same distance to the left from bins[0], as bins[1] from bins[0]
98 80003 step = bins[1] - bins[0];
99 80003 idx = 0;
100
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 2 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
5 } else if (value >= bins[lastIdx]) {
101 // Handle off-scale high
102 // virtual bins[lastIdx + 1] located at the same distance to the right from bins[lastIdx], as bins[lastIdx - 1] from bins[lastIdx]
103 3 step = bins[lastIdx] - bins[lastIdx - 1];
104 3 idx = lastIdx;
105 } else {
106 // Find the closest bin. 50/50 divide distance between bins
107 // Linear search for now, maybe binary search in future
108 // after collecting real perf data
109
1/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✗ Decision 'false' not taken.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
3 for (idx = 0; idx < lastIdx - 1; idx++) {
110 // ( -0.5, 05 ]
111 // if (bins[idx] + bins[idx + 1] / 2 >= value) {
112
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 time.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
3 if (bins[idx] + bins[idx + 1] >= 2 * value) {
113 2 break;
114 }
115 }
116
117 2 step = bins[idx + 1] - bins[idx];
118 }
119
120
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 80000 times.
2/4
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 80000 times.
80008 if (step <= 0) {
121 // bins are not ascending or two bins are equal
122 return { idx, 1.0f };
123 }
124
125 80008 closest = bins[idx];
126
127 // Compute how far from the closest bin we are:
128 // 0.0f = rigft in the bin
129 // -0.5f = half way to previous bin, 0.5f = half way to next bin
130 // <= -1.0f = to far below zero bin
131 // >= 1.0f = to far above last bin
132 80008 float distance = (value - closest) / step;
133
134 80008 return { idx, distance };
135 }
136
137 template<class TBin, int TSize, int TMult, int TDiv>
138 900484 BinResult getBin(float value, const scaled_channel<TBin, TMult, TDiv> (&bins)[TSize]) {
139 900484 return getBin(value * (float(TMult) / TDiv), *reinterpret_cast<const TBin (*)[TSize]>(&bins));
140 }
141
142 5892288 static inline float linterp(float low, float high, float frac)
143 {
144 5892288 return high * frac + low * (1 - frac);
145 }
146 } // namespace priv
147
148 template <class TBin, class TValue, int TSize>
149 940839 float interpolate2d(const float value, const TBin (&bin)[TSize], const TValue (&values)[TSize]) {
150 // Enforce numeric only (int, float, uintx_t, etc)
151 static_assert(std::is_arithmetic_v<TBin> || is_scaled_channel<TBin>, "Table values must be an arithmetic type or scaled channel");
152
153 940839 auto b = priv::getBin(value, bin);
154
155 // Convert to float as we read it out
156 940839 float low = static_cast<float>(values[b.Idx]);
157 940839 float high = static_cast<float>(values[b.Idx + 1]);
158 940839 float frac = b.Frac;
159
160 940839 return priv::linterp(low, high, frac);
161 }
162
163 // TS defines tables as [y_row_count x x_column_count] and we follow that weird Y, X order of arguments here
164 // todo: add support for scaled_channel to match Map3D flexibility?
165 template<typename VType, unsigned RNum, typename RType, unsigned X_ColumnNum, typename X_CType>
166 1650483 float interpolate3d(const VType (&table)[RNum][X_ColumnNum],
167 const RType (&rowBins)[RNum], float yRowValue,
168 const X_CType (&colBins)[X_ColumnNum], float xColValue)
169 {
170 1650483 auto row = priv::getBin(yRowValue, rowBins);
171 1650483 auto col = priv::getBin(xColValue, colBins);
172
173 // Orient the table such that (0, 0) is the bottom left corner,
174 // then the following variable names will make sense
175 1650483 float lowerLeft = table[row.Idx ][col.Idx ];
176 1650483 float upperLeft = table[row.Idx + 1][col.Idx ];
177 1650483 float lowerRight = table[row.Idx ][col.Idx + 1];
178 1650483 float upperRight = table[row.Idx + 1][col.Idx + 1];
179
180 // Interpolate each side by itself
181 1650483 float left = priv::linterp(lowerLeft, upperLeft, row.Frac);
182 1650483 float right = priv::linterp(lowerRight, upperRight, row.Frac);
183
184 // Then interpolate between those
185 1650483 return priv::linterp(left, right, col.Frac);
186 }
187