![]() |
Speeduino
|
Support functions for 3D table interpolation. More...
Classes | |
struct | row_col2d |
Row and column coordinates in a 2D table. More... | |
Axis Bin Searching | |
using | table3d_bin_t = _table2d_detail::Bin< table3d_axis_t > |
Perform a linear search on an array for the bin that contains value. | |
TESTABLE_INLINE_STATIC table3d_dim_t | linear_bin_search (const table3d_axis_t *pStart, const table3d_dim_t length, const table3d_axis_t value) |
Perform a linear search on an array for the bin that contains value. | |
table3d_dim_t | find_bin_max (const table3d_axis_t &value, const table3d_axis_t *pAxis, table3d_dim_t length, table3d_dim_t lastBinMax) |
Find the bin that covers the test value. | |
Fixed point math | |
typedef uint16_t | QU1X8_t |
Unsigned fixed point number type with 1 integer bit & 8 fractional bits. | |
constexpr QU1X8_t | QU1X8_INTEGER_SHIFT = 8 |
Integer shift to convert to/from QU1X8_t. | |
TESTABLE_CONSTEXPR QU1X8_t | QU1X8_ONE = toQU1X8(1U) |
Precomputed value of 1 in QU1X8_t. | |
TESTABLE_CONSTEXPR QU1X8_t | QU1X8_HALF = QU1X8_ONE/2U |
Precomputed value of 0.5 in QU1X8_t. | |
static constexpr QU1X8_t | toQU1X8 (uint16_t base) |
Unsigned fixed point number type with 1 integer bit & 8 fractional bits. | |
static constexpr uint16_t | fromQU1X8 (QU1X8_t base) |
Unsigned fixed point number type with 1 integer bit & 8 fractional bits. | |
TESTABLE_INLINE_STATIC QU1X8_t | mulQU1X8 (QU1X8_t a, QU1X8_t b) |
Multiply two QU1X8_t values. | |
Support functions for 3D table interpolation.
Unsigned fixed point number type with 1 integer bit & 8 fractional bits.
This is specialised for the number range 0..1 - a generic fixed point class would miss some important optimisations. Specifically, we can avoid type promotion during multiplication.
Perform a linear search on an array for the bin that contains value.
pStart | Pointer to the start of the array. |
length | Length of the array. |
value | Value to search for. |
TESTABLE_INLINE_STATIC table3d_value_t bilinear_interpolation | ( | const table3d_value_t & | tl, |
const table3d_value_t & | tr, | ||
const table3d_value_t & | bl, | ||
const table3d_value_t & | br, | ||
const QU1X8_t & | dx, | ||
const QU1X8_t & | dy | ||
) |
2d interpolation, given 4 corner values and x/y percentages
tl----------------tr | | | | | | |>>>>>dx>>>>? | | ^ | | dy | | ^ | bl----------------br
tl | Top left value |
tr | Top right value |
bl | Bottom left value |
br | Bottom right value |
dx | X distance |
dy | Y distance |
TESTABLE_INLINE_STATIC QU1X8_t compute_bin_position | ( | const uint16_t & | value, |
const table3d_dim_t & | upperBinIndex, | ||
const table3d_axis_t * | pAxis, | ||
const uint16_t & | multiplier | ||
) |
Compute the % position of a value within a bin.
value | The value to check. |
upperBinIndex | The upper bin index into pAxis. |
pAxis | The axis array. |
multiplier | The multiplier for the axis values. |
table3d_dim_t find_bin_max | ( | const table3d_axis_t & | value, |
const table3d_axis_t * | pAxis, | ||
table3d_dim_t | length, | ||
table3d_dim_t | lastBinMax | ||
) |
Find the bin that covers the test value.
For example, 4 in { 1, 3, 5, 7, 9 } would be 2
value | The value to search for. |
pAxis | The axis to search. |
length | The length of the axis. |
lastBinMax | The last bin max. |
Unsigned fixed point number type with 1 integer bit & 8 fractional bits.
This is specialised for the number range 0..1 - a generic fixed point class would miss some important optimisations. Specifically, we can avoid type promotion during multiplication.
table3d_value_t interpolate_3d_value | ( | const xy_values & | lookUpValues, |
const xy_coord2d & | upperBinIndices, | ||
const table3d_dim_t & | axisSize, | ||
const table3d_value_t * | pValues, | ||
const table3d_axis_t * | pXAxis, | ||
const uint16_t | xMultiplier, | ||
const table3d_axis_t * | pYAxis, | ||
const uint16_t | yMultiplier | ||
) |
Interpolate a table value from axis bins & values.
lookUpValues | The x & y axis values we are interpolating |
upperBinIndices | The x & y axis bin indices that contain lookUpValues |
axisSize | The length of an axis |
pValues | The interpolation source values |
pXAxis | The x-axis |
xMultiplier | The x-axis multiplier |
pYAxis | The y-axis |
yMultiplier | The y-axis multiplier |
TESTABLE_INLINE_STATIC table3d_dim_t linear_bin_search | ( | const table3d_axis_t * | pStart, |
const table3d_dim_t | length, | ||
const table3d_axis_t | value | ||
) |
Perform a linear search on an array for the bin that contains value.
pStart | Pointer to the start of the array. |
length | Length of the array. |
value | Value to search for. |
TESTABLE_INLINE_STATIC QU1X8_t mulQU1X8 | ( | QU1X8_t | a, |
QU1X8_t | b | ||
) |
Multiply two QU1X8_t values.
|
inlinestatic |
Get the bottom left corner of the value coordinates in a 3D table, based on top right corner.
Unsigned fixed point number type with 1 integer bit & 8 fractional bits.
This is specialised for the number range 0..1 - a generic fixed point class would miss some important optimisations. Specifically, we can avoid type promotion during multiplication.
|
inlinestatic |
Get the top right corner of the value coordinates in a 3D table, based on x/y axis coords.
TESTABLE_CONSTEXPR QU1X8_t QU1X8_HALF = QU1X8_ONE/2U |
Precomputed value of 0.5 in QU1X8_t.
TESTABLE_CONSTEXPR QU1X8_t QU1X8_ONE = toQU1X8(1U) |
Precomputed value of 1 in QU1X8_t.