| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Created by kifir on 7/29/24. | |||
| 3 | // | |||
| 4 | ||||
| 5 | #pragma once | |||
| 6 | ||||
| 7 | #include <optional> | |||
| 8 | ||||
| 9 | class ValueProvider2D { | |||
| 10 | public: | |||
| 11 | virtual std::optional<float> getValue(float x) const = 0; | |||
| 12 | }; | |||
| 13 | ||||
| 14 | template<int TLength, typename TValue, typename TBin> | |||
| 15 | class Map2D : public ValueProvider2D { | |||
| 16 | public: | |||
| 17 | Map2D(const char* const name); | |||
| 18 | ||||
| 19 | void initTable(const TValue (&values)[TLength], const TBin (&bins)[TLength]); | |||
| 20 | ||||
| 21 | virtual std::optional<float> getValue(const float x) const; | |||
| 22 | private: | |||
| 23 | const char* const m_name; | |||
| 24 | ||||
| 25 | const TValue (*m_values)[TLength] = nullptr; | |||
| 26 | const TBin (*m_bins)[TLength] = nullptr; | |||
| 27 | }; | |||
| 28 | ||||
| 29 | template<int TLength, typename TValue, typename TBin> | |||
| 30 | 8 | Map2D<TLength, TValue, TBin>::Map2D(const char* const name) : m_name(name) { | ||
| 31 | 8 | } | ||
| 32 | ||||
| 33 | template<int TLength, typename TValue, typename TBin> | |||
| 34 | 2416 | void Map2D<TLength, TValue, TBin>::initTable(const TValue (&values)[TLength], const TBin (&bins)[TLength]) { | ||
| 35 | 2416 | m_values = &values; | ||
| 36 | 2416 | m_bins = &bins; | ||
| 37 | 2416 | } | ||
| 38 | ||||
| 39 | template<int TLength, typename TValue, typename TBin> | |||
| 40 | 164 | std::optional<float> Map2D<TLength, TValue, TBin>::getValue(const float x) const { | ||
| 41 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 164 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 164 times.
|
164 | if (!m_bins) { |
| 42 | ✗ | criticalError("Access to uninitialized bins: %s", m_name); | ||
| 43 | ✗ | return {}; | ||
| 44 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 164 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 164 times.
|
164 | } else if (!m_values) { |
| 45 | ✗ | criticalError("Access to uninitialized values: %s", m_name); | ||
| 46 | ✗ | return {}; | ||
| 47 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 164 times.
|
164 | } else if ((1 < TLength) && ((*m_bins)[0] == 0.0f) && ((*m_bins)[1] == 0.0f)) { |
| 48 | // bins are uninitialized, but it isn't critical - maybe old configuration | |||
| 49 | ✗ | return {}; | ||
| 50 | } else { | |||
| 51 |
1/1✓ Branch 2 taken 164 times.
|
164 | return std::make_optional(interpolate2d(x, *m_bins, *m_values)); | |
| 52 | } | |||
| 53 | } | |||
| 54 |