Speeduino
Loading...
Searching...
No Matches
table3d.h
Go to the documentation of this file.
1
46#pragma once
47#include "src/utils/nominmax.h"
48#include "table3d_interpolate.h"
49#include "table3d_axes.h"
50#include <array>
51
52#define TO_TYPE_KEY(size, xDom, yDom) table3d ## size ## xDom ## yDom ## _key
53
69enum class TableType : uint8_t {
72 #define TABLE3D_GEN_TYPEKEY(size, xDom, yDom) TO_TYPE_KEY(size, xDom, yDom),
73 TABLE3D_GENERATOR(TABLE3D_GEN_TYPEKEY)
75};
76
77// A marker type for 3d tables.
79{
80};
81
82// Generate the 3D table types
83#define TABLE3D_GEN_TYPE_INNER(size, xDom, yDom, typeName) \
84 \
85 struct typeName : public table3d_t \
86 { \
87 /* This will take up zero space unless we take the address somewhere */ \
88 static constexpr TableType type_key = TableType::TO_TYPE_KEY(size, xDom, yDom); \
89 static constexpr AxisDomain XDomain = AxisDomain::xDom; \
90 static constexpr AxisDomain YDomain = AxisDomain::yDom; \
91 \
92 mutable table3DGetValueCache get_value_cache; \
93 std::array<table3d_axis_t, (size)*(size)> values; \
94 std::array<table3d_axis_t, (size)> axisX; \
95 std::array<table3d_axis_t, (size)> axisY; \
96 };
97#define TABLE3D_GEN_TYPE(size, xDom, yDom) TABLE3D_GEN_TYPE_INNER(size, xDom, yDom, TABLE3D_TYPENAME_BASE(size, xDom, yDom))
98
99// LCOV_EXCL_START
101// LCOV_EXCL_STOP
102
103// =============================== Table function calls =========================
104
105template <typename TTable>
106static inline table3d_value_t get3DTableValue(const TTable *pTable, const uint16_t y, const uint16_t x) noexcept
107{
108 constexpr uint16_t xFactor = getConversionFactor(TTable::XDomain);
109 constexpr uint16_t yFactor = getConversionFactor(TTable::YDomain);
110 return get3DTableValue<xFactor, yFactor>( &pTable->get_value_cache,
111 pTable->values,
112 pTable->axisX,
113 pTable->axisY,
114 { x, y });
115}
116
const uint16_t y
Definition table3d.h:106
return get3DTableValue< xFactor, yFactor >(&pTable->get_value_cache, pTable->values, pTable->axisX, pTable->axisY, { x, y })
#define TABLE3D_GEN_TYPE(size, xDom, yDom)
Definition table3d.h:97
TableType
Table type identifiers. Limited compile time RTTI.
Definition table3d.h:69
static constexpr uint16_t getConversionFactor(AxisDomain domain)
Definition table3d_axes.h:24
uint8_t table3d_value_t
The type of each table value.
Definition table3d_typedefs.h:25
constexpr uint16_t yFactor
Definition table3d.h:109
#define TABLE3D_GENERATOR(GENERATOR,...)
Core 3d table generation macro.
Definition table3d_typedefs.h:36
static uint8_t x
Definition maths.cpp:10
Workaround when min() & max() are defined as macros, which generates compile errors in most C++ stand...
Definition table3d.h:79
3D table axis types and iterators
Functions for interpolating values from 3D tables.
table3d_value_t get3DTableValue(struct table3DGetValueCache *pValueCache, const TValues &values, const TXAxis &xAxis, const TYAxis &yAxis, const xy_pair_t &lookupValues)
Get a value from a 3D table using the specified lookup values.
Definition table3d_interpolate.h:119