20 using Sink = std::function<void(
const std::string&)>;
22 void SetSink(Sink sink) { m_sink = std::move(sink); }
25 void Warn(
const std::string& message)
27 if (m_count++ == 0 && m_sink) {
33 int Count()
const {
return m_count; }
55 if (axis.size() < 2) {
56 return {0, axis.empty() ? x : axis.front(), axis.empty() || x != axis.front()};
58 if (!(x >= axis.front())) {
59 return {0, axis.front(),
true};
61 if (x > axis.back()) {
62 return {axis.size() - 2, axis.back(),
true};
64 std::size_t lower = 0;
65 while (lower + 2 < axis.size() && axis[lower + 1] < x) {
68 return {lower, x,
false};
72inline double Lerp(
double xLow,
double xHigh,
double yLow,
double yHigh,
double x)
77 return yLow + (yHigh - yLow) * (x - xLow) / (xHigh - xLow);
Definition TableLookup.h:18
void Warn(const std::string &message)
Passes message to the sink the first time only.
Definition TableLookup.h:25
int Count() const
How many times Warn was called.
Definition TableLookup.h:33
Simple waypoint object.
Definition CableAttach.h:16
AxisInterval FindInterval(const std::vector< double > &axis, double x)
Definition TableLookup.h:53
double Lerp(double xLow, double xHigh, double yLow, double yHigh, double x)
The linear value at x between the nodes (xLow, yLow) and (xHigh, yHigh); yLow when the nodes coincide...
Definition TableLookup.h:72
The interval of an ascending axis that holds a value, with the value held at the edges.
Definition TableLookup.h:42
bool held
true when the queried value was outside the axis
Definition TableLookup.h:45
double value
the queried value held to [axis.front(), axis.back()]
Definition TableLookup.h:44
std::size_t lower
index of the lower node; lower + 1 is the upper node. Zero for an axis of one node.
Definition TableLookup.h:43