| 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 | 89704 | 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/72priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1035 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, 2>(float, unsigned char const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 76 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1105 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 946 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2386 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 3924 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1105 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 5446 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 4613 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1118 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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1112 times.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 7671 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2375 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, 4>(float, unsigned short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 17794 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✗ Branch 1 not taken.
✓ Branch 2 taken 159 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1380 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<unsigned char, 5>(float, unsigned char const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1161 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, 5>(float, float const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 284 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✗ Branch 1 not taken.
✓ Branch 2 taken 4590 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1952 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<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2208 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✗ Branch 1 not taken.
✓ Branch 2 taken 1101 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, 3>(float, unsigned short const (&) [3]):
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 1 not taken.
✓ Branch 2 taken 341 times.
|
3/24priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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<unsigned short, 6>(float, unsigned short const (&) [6]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 5446 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<short, 8>(float, short 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 char, 4>(float, unsigned char const (&) [4]):
✗ 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 17794 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ 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<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.
|
89704 | if (std::isnan(value)) { |
| 35 | 2 | return { 0, 0.0f }; | ||
| 36 | } | |||
| 37 | ||||
| 38 | // Handle off-scale low | |||
| 39 |
57/72priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 539 times.
✓ Branch 1 taken 496 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, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 56 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1105 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 945 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 1378 times.
✓ Branch 1 taken 1008 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 1608 times.
✓ Branch 1 taken 2316 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1105 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 3949 times.
✓ Branch 1 taken 1497 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 2913 times.
✓ Branch 1 taken 1700 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1118 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 int, 2>(float, unsigned int const (&) [2]):
✓ Branch 0 taken 1112 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 3126 times.
✓ Branch 1 taken 4545 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 1628 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, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 6391 times.
✓ Branch 1 taken 11403 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 154 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 552 times.
✓ Branch 1 taken 828 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<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1153 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, 5>(float, float const (&) [5]):
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 241 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 998 times.
✓ Branch 1 taken 3592 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1952 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<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2203 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1100 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, 3>(float, unsigned short const (&) [3]):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✗ Branch 0 not taken.
✓ Branch 1 taken 341 times.
|
5/24priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 3949 times.
✓ Decision 'false' taken 1497 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<short, 8>(float, short 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 char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 6391 times.
✓ Decision 'false' taken 11403 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ 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<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.
|
89702 | if (value <= bins[0]) { |
| 40 | 23996 | return { 0, 0.0f }; | ||
| 41 | } | |||
| 42 | ||||
| 43 | // Handle off-scale high | |||
| 44 |
55/72priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 481 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, 2>(float, unsigned char const (&) [2]):
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1105 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 944 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1003 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2287 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1105 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1479 times.
priv::BinResult priv::getBin<unsigned char, 6>(float, unsigned char const (&) [6]):
✓ Branch 0 taken 1669 times.
✓ Branch 1 taken 31 times.
priv::BinResult priv::getBin<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1117 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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 4505 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 550 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, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 8570 times.
✓ Branch 1 taken 2833 times.
priv::BinResult priv::getBin<short, 4>(float, short const (&) [4]):
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 4 times.
priv::BinResult priv::getBin<short, 6>(float, short const (&) [6]):
✓ Branch 0 taken 827 times.
✓ Branch 1 taken 1 time.
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 char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1145 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, 5>(float, float const (&) [5]):
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 209 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 1086 times.
✓ Branch 1 taken 2506 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1952 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<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 2134 times.
priv::BinResult priv::getBin<short, 5>(float, short const (&) [5]):
✓ Branch 0 taken 1071 times.
✓ Branch 1 taken 29 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, 3>(float, unsigned short const (&) [3]):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
priv::BinResult priv::getBin<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 293 times.
|
6/24priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 18 times.
✓ Decision 'false' taken 1479 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<short, 8>(float, short 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 char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 8570 times.
✓ Decision 'false' taken 2833 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ 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<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.
|
65706 | if (value >= bins[TSize - 1]) { |
| 45 | 14748 | return { TSize - 2, 1.0f }; | ||
| 46 | } | |||
| 47 | ||||
| 48 | 50958 | 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/72priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 0 taken 1237 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, 2>(float, unsigned char const (&) [2]):
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 0 taken 12002 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 0 taken 4719 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 0 taken 5646 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 0 taken 10914 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 0 taken 4398 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 0 taken 5267 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<short, 8>(float, short const (&) [8]):
✓ Branch 0 taken 5575 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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 40839 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 0 taken 1139 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, 4>(float, unsigned short const (&) [4]):
✓ Branch 0 taken 4310 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, 6>(float, short const (&) [6]):
✓ Branch 0 taken 5 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<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 0 taken 3360 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, 5>(float, float const (&) [5]):
✓ Branch 0 taken 511 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 0 taken 15433 times.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 0 taken 52632 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<short, 10>(float, short const (&) [10]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 0 taken 21158 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<float, 32>(float, float const (&) [32]):
✗ 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<float, 11>(float, float const (&) [11]):
✓ Branch 0 taken 1473 times.
✗ Branch 1 not taken.
|
3/24priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 5267 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<short, 8>(float, short 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 char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 4310 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, 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, 11>(float, float const (&) [11]):
✓ Decision 'true' taken 1473 times.
✗ Decision 'false' not taken.
|
31426924 | for (idx = 0; idx < TSize - 1; idx++) { |
| 54 |
60/72priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✓ Branch 1 taken 481 times.
✓ Branch 2 taken 756 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, 2>(float, unsigned char const (&) [2]):
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<short, 16>(float, short const (&) [16]):
✓ Branch 1 taken 1105 times.
✓ Branch 2 taken 10897 times.
priv::BinResult priv::getBin<signed char, 8>(float, signed char const (&) [8]):
✓ Branch 1 taken 944 times.
✓ Branch 2 taken 3775 times.
priv::BinResult priv::getBin<unsigned char, 8>(float, unsigned char const (&) [8]):
✓ Branch 1 taken 1003 times.
✓ Branch 2 taken 4643 times.
priv::BinResult priv::getBin<float, 8>(float, float const (&) [8]):
✓ Branch 1 taken 2287 times.
✓ Branch 2 taken 8627 times.
priv::BinResult priv::getBin<float, 6>(float, float const (&) [6]):
✓ Branch 1 taken 1105 times.
✓ Branch 2 taken 3293 times.
priv::BinResult priv::getBin<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Branch 1 taken 1479 times.
✓ Branch 2 taken 3788 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<short, 8>(float, short const (&) [8]):
✓ Branch 1 taken 1117 times.
✓ Branch 2 taken 4458 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 int, 2>(float, unsigned int const (&) [2]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 1 taken 4505 times.
✓ Branch 2 taken 36334 times.
priv::BinResult priv::getBin<unsigned char, 4>(float, unsigned char const (&) [4]):
✓ Branch 1 taken 550 times.
✓ Branch 2 taken 589 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, 4>(float, unsigned short const (&) [4]):
✓ Branch 1 taken 2833 times.
✓ Branch 2 taken 1477 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, 6>(float, short const (&) [6]):
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 4 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<unsigned char, 5>(float, unsigned char const (&) [5]):
✓ Branch 1 taken 1145 times.
✓ Branch 2 taken 2215 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<float, 5>(float, float const (&) [5]):
✓ Branch 1 taken 209 times.
✓ Branch 2 taken 302 times.
priv::BinResult priv::getBin<unsigned short, 12>(float, unsigned short const (&) [12]):
✓ Branch 1 taken 2506 times.
✓ Branch 2 taken 12927 times.
priv::BinResult priv::getBin<float, 28>(float, float const (&) [28]):
✓ Branch 1 taken 1952 times.
✓ Branch 2 taken 50680 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<short, 10>(float, short const (&) [10]):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
priv::BinResult priv::getBin<float, 16>(float, float const (&) [16]):
✓ Branch 1 taken 2134 times.
✓ Branch 2 taken 19024 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<float, 32>(float, float const (&) [32]):
✗ 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<float, 11>(float, float const (&) [11]):
✓ Branch 1 taken 293 times.
✓ Branch 2 taken 1180 times.
|
6/24priv::BinResult priv::getBin<unsigned short, 8>(float, unsigned short const (&) [8]):
✗ 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<unsigned short, 6>(float, unsigned short const (&) [6]):
✓ Decision 'true' taken 1479 times.
✓ Decision 'false' taken 3788 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<short, 8>(float, short 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 char, 4>(float, unsigned char const (&) [4]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
priv::BinResult priv::getBin<unsigned short, 4>(float, unsigned short const (&) [4]):
✓ Decision 'true' taken 2833 times.
✓ Decision 'false' taken 1477 times.
priv::BinResult priv::getBin<float, 5>(float, float const (&) [5]):
✗ 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<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.
|
31426924 | if (bins[idx + 1] > value) { |
| 55 | 50958 | break; | ||
| 56 | } | |||
| 57 | } | |||
| 58 | ||||
| 59 | 50958 | float low = bins[idx]; | ||
| 60 | 50958 | 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 | 50958 | float fraction = (value - low) / (high - low); | ||
| 65 | ||||
| 66 | 50958 | 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 | 82210 | 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/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 1 not taken.
✓ Branch 2 taken 82202 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
2/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 82202 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
|
82210 | if (std::isnan(value)) { |
| 87 | ✗ | return { 0, -1.0f }; | ||
| 88 | } | |||
| 89 | ||||
| 90 | 82210 | const size_t lastIdx = TSize - 1; | ||
| 91 | 82210 | size_t idx = 0; | ||
| 92 | float closest; | |||
| 93 | float step; | |||
| 94 | ||||
| 95 |
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 80717 times.
✓ Branch 1 taken 1485 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
|
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 80717 times.
✓ Decision 'false' taken 1485 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 5 times.
|
82210 | 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 | 80720 | step = bins[1] - bins[0]; | ||
| 99 | 80720 | idx = 0; | ||
| 100 |
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1473 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 12 times.
✓ Decision 'false' taken 1473 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 2 times.
|
1490 | } 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/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 0 taken 13289 times.
✓ Branch 1 taken 12 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 13289 times.
✓ Decision 'false' taken 12 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 3 times.
✗ Decision 'false' not taken.
|
13304 | for (idx = 0; idx < lastIdx - 1; idx++) { |
| 110 | // ( -0.5, 05 ] | |||
| 111 | // if (bins[idx] + bins[idx + 1] / 2 >= value) { | |||
| 112 |
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Branch 2 taken 1461 times.
✓ Branch 3 taken 11828 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 time.
|
4/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✓ Decision 'true' taken 1461 times.
✓ Decision 'false' taken 11828 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
|
13292 | if (bins[idx] + bins[idx + 1] >= 2 * value) { |
| 113 | 1463 | break; | ||
| 114 | } | |||
| 115 | } | |||
| 116 | ||||
| 117 | 1475 | step = bins[idx + 1] - bins[idx]; | ||
| 118 | } | |||
| 119 | ||||
| 120 |
2/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 82202 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
2/4priv::BinResult priv::getClosestBin<unsigned short, 16>(float, unsigned short const (&) [16]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 82202 times.
priv::BinResult priv::getClosestBin<float, 14>(float, float const (&) [14]):
✗ Decision 'true' not taken.
✓ Decision 'false' taken 8 times.
|
82210 | if (step <= 0) { |
| 121 | // bins are not ascending or two bins are equal | |||
| 122 | ✗ | return { idx, 1.0f }; | ||
| 123 | } | |||
| 124 | ||||
| 125 | 82210 | 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 | 82210 | float distance = (value - closest) / step; | ||
| 133 | ||||
| 134 | 82210 | return { idx, distance }; | ||
| 135 | } | |||
| 136 | ||||
| 137 | template<class TBin, int TSize, int TMult, int TDiv> | |||
| 138 | 15719 | BinResult getBin(float value, const scaled_channel<TBin, TMult, TDiv> (&bins)[TSize]) { | ||
| 139 | 15719 | return getBin(value * (float(TMult) / TDiv), *reinterpret_cast<const TBin (*)[TSize]>(&bins)); | ||
| 140 | } | |||
| 141 | ||||
| 142 | 112878 | static inline float linterp(float low, float high, float frac) | ||
| 143 | { | |||
| 144 | 112878 | return high * frac + low * (1 - frac); | ||
| 145 | } | |||
| 146 | } // namespace priv | |||
| 147 | ||||
| 148 | template <class TBin, class TValue, int TSize> | |||
| 149 | 43314 | 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 | 43314 | auto b = priv::getBin(value, bin); | ||
| 154 | ||||
| 155 | // Convert to float as we read it out | |||
| 156 | 43314 | float low = static_cast<float>(values[b.Idx]); | ||
| 157 | 43314 | float high = static_cast<float>(values[b.Idx + 1]); | ||
| 158 | 43314 | float frac = b.Frac; | ||
| 159 | ||||
| 160 | 43314 | 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 | 5245 | 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 | 5245 | auto row = priv::getBin(yRowValue, rowBins); | ||
| 171 | 5245 | 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 | 5245 | float lowerLeft = table[row.Idx ][col.Idx ]; | ||
| 176 | 5245 | float upperLeft = table[row.Idx + 1][col.Idx ]; | ||
| 177 | 5245 | float lowerRight = table[row.Idx ][col.Idx + 1]; | ||
| 178 | 5245 | float upperRight = table[row.Idx + 1][col.Idx + 1]; | ||
| 179 | ||||
| 180 | // Interpolate each side by itself | |||
| 181 | 5245 | float left = priv::linterp(lowerLeft, upperLeft, row.Frac); | ||
| 182 | 5245 | float right = priv::linterp(lowerRight, upperRight, row.Frac); | ||
| 183 | ||||
| 184 | // Then interpolate between those | |||
| 185 | 5245 | return priv::linterp(left, right, col.Frac); | ||
| 186 | } | |||
| 187 |