Only extrapolate views

This commit is contained in:
Patrick Nicolas
2024-03-08 15:03:59 +01:00
parent 97ec53868f
commit 883e1808db
5 changed files with 76 additions and 60 deletions
+14 -6
View File
@@ -26,7 +26,7 @@
#include <algorithm>
#include "clock_offset.h"
template <typename Derived, typename Data, size_t MaxSamples = 10>
template <typename Derived, typename Data, bool extrapolate = false, size_t MaxSamples = 10>
class history
{
struct TimedData : public Data
@@ -75,7 +75,10 @@ public:
if (data.front().at_timestamp_ns > at_timestamp_ns)
{
return Derived::extrapolate(data[0], data[1], data[0].at_timestamp_ns, data[1].at_timestamp_ns, at_timestamp_ns);
if (extrapolate)
return Derived::extrapolate(data[0], data[1], data[0].at_timestamp_ns, data[1].at_timestamp_ns, at_timestamp_ns);
else
return data.front();
}
for (size_t i = 1; i < data.size(); ++i)
@@ -88,9 +91,14 @@ public:
}
}
const auto & d0 = data[data.size() - 2];
const auto & d1 = data.back();
return Derived::extrapolate(d0, d1, d0.at_timestamp_ns, d1.at_timestamp_ns, at_timestamp_ns);
if (extrapolate)
{
const auto & d0 = data[data.size() - 2];
const auto & d1 = data.back();
return Derived::extrapolate(d0, d1, d0.at_timestamp_ns, d1.at_timestamp_ns, at_timestamp_ns);
}
else {
return data.back();
}
}
};