GCC Code Coverage Report


Directory: ./
File: firmware/libfirmware/util/include/rusefi/interpolation.h
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 74.8% 709 0 948
Functions: 77.7% 87 0 112
Branches: 66.7% 256 0 384
Decisions: 29.2% 42 - 144

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 90663 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<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2412 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1120 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1180 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2426 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 5546 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 4689 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 7764 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1055 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 966 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 18098 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, 8>(float, float const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 3978 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✗ Branch 1 not taken.
✓ Branch 2 taken 41 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, 4>(float, float const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
priv::BinResult priv::getBin<float, 3>(float, float const (&) [3]):
✗ Branch 1 not taken.
✓ Branch 2 taken 7 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<unsigned short, 12>(float, unsigned short const (&) [12]):
✗ Branch 1 not taken.
✓ Branch 2 taken 4585 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1950 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2246 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1137 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1124 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1124 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1131 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1428 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 158 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 575 times.
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<int, 4>(float, int const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 1 not taken.
✓ Branch 2 taken 341 times.
3/24
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 short, 6>(float, unsigned short const (&) [6]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 5546 times.
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 short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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 18098 times.
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<float, 16>(float, float const (&) [16]):
✗ 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<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 341 times.
90663 if (std::isnan(value)) {
35 2 return { 0, 0.0f };
36 }
37
38 // Handle off-scale low
39
57/72
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 771 times.
✓ Branch 1 taken 1641 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1119 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1172 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 1398 times.
✓ Branch 1 taken 1028 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 4035 times.
✓ Branch 1 taken 1511 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 2975 times.
✓ Branch 1 taken 1714 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 3196 times.
✓ Branch 1 taken 4568 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 563 times.
✓ Branch 1 taken 492 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 965 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 6583 times.
✓ Branch 1 taken 11515 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, 8>(float, float const (&) [8]):
✓ Branch 0 taken 1655 times.
✓ Branch 1 taken 2323 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 8 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 32 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, 4>(float, float const (&) [4]):
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 81 times.
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, 2>(float, float const (&) [2]):
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 8 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 997 times.
✓ Branch 1 taken 3588 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1950 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2241 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1137 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 55 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1124 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1124 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 0 not taken.
✗ 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 int, 2>(float, unsigned int const (&) [2]):
✓ Branch 0 taken 1131 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 852 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 153 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 2>(float, signed char const (&) [2]):
✓ Branch 0 taken 575 times.
✗ 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<int, 4>(float, int const (&) [4]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 52 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 0 not taken.
✓ Branch 1 taken 341 times.
5/24
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 short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 4035 times.
✓ Decision 'false' taken 1511 times.
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 short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 6583 times.
✓ Decision 'false' taken 11515 times.
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<float, 16>(float, float const (&) [16]):
✗ 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<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 341 times.
90661 if (value <= bins[0]) {
40 24587 return { 0, 0.0f };
41 }
42
43 // Handle off-scale high
44
55/72
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 1097 times.
✓ Branch 1 taken 544 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 1090 times.
✓ Branch 1 taken 29 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1164 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1023 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1493 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 1683 times.
✓ Branch 1 taken 31 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 4528 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 477 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 964 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 8722 times.
✓ Branch 1 taken 2793 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, 8>(float, float const (&) [8]):
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2294 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 7 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 29 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, 4>(float, float const (&) [4]):
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 68 times.
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, 2>(float, float const (&) [2]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 1085 times.
✓ Branch 1 taken 2503 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1950 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 2172 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1136 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1124 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1124 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 0 not taken.
✗ 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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 851 times.
✓ Branch 1 taken 1 time.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 4 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ 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<unsigned short, 3>(float, unsigned short const (&) [3]):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 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<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 293 times.
6/24
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 short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 18 times.
✓ Decision 'false' taken 1493 times.
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 short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 8722 times.
✓ Decision 'false' taken 2793 times.
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<float, 16>(float, float const (&) [16]):
✗ 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<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 48 times.
✓ Decision 'false' taken 293 times.
66074 if (value >= bins[TSize - 1]) {
45 14974 return { TSize - 2, 1.0f };
46 }
47
48 51100 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<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 1125 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 3417 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 5766 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 5327 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 41091 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 1219 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 4819 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 4238 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, 8>(float, float const (&) [8]):
✓ Branch 0 taken 10970 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 0 taken 100 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, 4>(float, float const (&) [4]):
✓ Branch 0 taken 156 times.
✗ 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, 2>(float, float const (&) [2]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 15415 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 0 taken 52578 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 21538 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 5670 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 0 taken 12211 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 0 taken 4474 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<unsigned short, 2>(float, unsigned short const (&) [2]):
✗ Branch 0 not taken.
✗ 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<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 5 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, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ 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<unsigned short, 3>(float, unsigned short const (&) [3]):
✓ Branch 0 taken 3 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<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 1473 times.
✗ Branch 1 not taken.
3/24
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 short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 5327 times.
✗ 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 short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 4238 times.
✗ 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<float, 16>(float, float const (&) [16]):
✗ 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<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 1473 times.
✗ Decision 'false' not taken.
31428152 for (idx = 0; idx < TSize - 1; idx++) {
54
60/72
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 1 taken 544 times.
✓ Branch 2 taken 581 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 66 times.
priv::BinResult priv::getBin<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 1 taken 1164 times.
✓ Branch 2 taken 2253 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 1 taken 1023 times.
✓ Branch 2 taken 4743 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 1 taken 1493 times.
✓ Branch 2 taken 3834 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 19 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 1 taken 4528 times.
✓ Branch 2 taken 36563 times.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 1 taken 477 times.
✓ Branch 2 taken 742 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 1 taken 964 times.
✓ Branch 2 taken 3855 times.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Branch 1 taken 2793 times.
✓ Branch 2 taken 1445 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, 8>(float, float const (&) [8]):
✓ Branch 1 taken 2294 times.
✓ Branch 2 taken 8676 times.
priv::BinResult priv::getBin<unsigned char, 16>(float, unsigned char const (&) [16]):
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 38 times.
priv::BinResult priv::getBin<unsigned char, 10>(float, unsigned char const (&) [10]):
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 47 times.
priv::BinResult priv::getBin<unsigned short, 10>(float, unsigned short const (&) [10]):
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 71 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, 4>(float, float const (&) [4]):
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 88 times.
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, 2>(float, float const (&) [2]):
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 1 taken 2503 times.
✓ Branch 2 taken 12912 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 1 taken 1950 times.
✓ Branch 2 taken 50628 times.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 1 taken 2172 times.
✓ Branch 2 taken 19366 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 1 taken 1136 times.
✓ Branch 2 taken 4534 times.
priv::BinResult priv::getBin<unsigned char, 2>(float, unsigned char const (&) [2]):
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 1 taken 1124 times.
✓ Branch 2 taken 11087 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 1 taken 1124 times.
✓ Branch 2 taken 3350 times.
priv::BinResult priv::getBin<float, 32>(float, float const (&) [32]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
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, 4>(float, short const (&) [4]):
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 6 times.
priv::BinResult priv::getBin<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<signed char, 2>(float, signed char 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<int, 4>(float, int const (&) [4]):
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 56 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Branch 1 taken 293 times.
✓ Branch 2 taken 1180 times.
6/24
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 short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 1493 times.
✓ Decision 'false' taken 3834 times.
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 short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 2793 times.
✓ Decision 'false' taken 1445 times.
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<float, 16>(float, float const (&) [16]):
✗ 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<float, 32>(float, float const (&) [32]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 293 times.
✓ Decision 'false' taken 1180 times.
31428152 if (bins[idx + 1] > value) {
55 51100 break;
56 }
57 }
58
59 51100 float low = bins[idx];
60 51100 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 51100 float fraction = (value - low) / (high - low);
65
66 51100 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 82248 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<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 82240 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
2/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 82240 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
82248 if (std::isnan(value)) {
87 return { 0, -1.0f };
88 }
89
90 82248 const size_t lastIdx = TSize - 1;
91 82248 size_t idx = 0;
92 float closest;
93 float step;
94
95
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 80741 times.
✓ Branch 1 taken 1499 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 80741 times.
✓ Decision 'false' taken 1499 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 5 times.
82248 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 80744 step = bins[1] - bins[0];
99 80744 idx = 0;
100
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1487 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 12 times.
✓ Decision 'false' taken 1487 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 2 times.
1504 } 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 15 step = bins[lastIdx] - bins[lastIdx - 1];
104 15 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
3/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 13430 times.
✓ Branch 1 taken 10 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 13430 times.
✓ Decision 'false' taken 10 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✗ Decision 'false' not taken.
13443 for (idx = 0; idx < lastIdx - 1; idx++) {
110 // ( -0.5, 05 ]
111 // if (bins[idx] + bins[idx + 1] / 2 >= value) {
112
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 2 taken 1477 times.
✓ Branch 3 taken 11953 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 time.
4/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 1477 times.
✓ Decision 'false' taken 11953 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
13433 if (bins[idx] + bins[idx + 1] >= 2 * value) {
113 1479 break;
114 }
115 }
116
117 1489 step = bins[idx + 1] - bins[idx];
118 }
119
120
2/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 82240 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
2/4
priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 82240 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
82248 if (step <= 0) {
121 // bins are not ascending or two bins are equal
122 return { idx, 1.0f };
123 }
124
125 82248 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 82248 float distance = (value - closest) / step;
133
134 82248 return { idx, distance };
135 }
136
137 template<class TBin, int TSize, int TMult, int TDiv>
138 15904 BinResult getBin(float value, const scaled_channel<TBin, TMult, TDiv> (&bins)[TSize]) {
139 15904 return getBin(value * (float(TMult) / TDiv), *reinterpret_cast<const TBin (*)[TSize]>(&bins));
140 }
141
142 114225 static inline float linterp(float low, float high, float frac)
143 {
144 114225 return high * frac + low * (1 - frac);
145 }
146 } // namespace priv
147
148 template <class TBin, class TValue, int TSize>
149 43497 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 43497 auto b = priv::getBin(value, bin);
154
155 // Convert to float as we read it out
156 43497 float low = static_cast<float>(values[b.Idx]);
157 43497 float high = static_cast<float>(values[b.Idx + 1]);
158 43497 float frac = b.Frac;
159
160 43497 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 5325 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 5325 auto row = priv::getBin(yRowValue, rowBins);
171 5325 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 5325 float lowerLeft = table[row.Idx ][col.Idx ];
176 5325 float upperLeft = table[row.Idx + 1][col.Idx ];
177 5325 float lowerRight = table[row.Idx ][col.Idx + 1];
178 5325 float upperRight = table[row.Idx + 1][col.Idx + 1];
179
180 // Interpolate each side by itself
181 5325 float left = priv::linterp(lowerLeft, upperLeft, row.Frac);
182 5325 float right = priv::linterp(lowerRight, upperRight, row.Frac);
183
184 // Then interpolate between those
185 5325 return priv::linterp(left, right, col.Frac);
186 }
187