33#include <NDEVR/Buffer.h>
34#include <NDEVR/Time.h>
35#include <NDEVR/TimeSpan.h>
65 if (
isNaN(current_time) || n == 0) {
68 if (current_time <=
mX[0]) {
71 if (current_time >=
mX.last()) {
77 while (current_time >=
mX[i + 1])
80 if (current_time ==
mX[i])
84 fltp08 h = (
mX[i + 1] -
mX[i]).elapsedSeconds();
85 fltp08 t = (current_time -
mX[i]).elapsedSeconds() / h;
86 return (
mY[i] * (1 + 2 * t) + h *
mM[i] * t) * (1 - t) * (1 - t)
87 + (
mY[i + 1] * (3 - 2 * t) + h *
mM[i + 1] * (t - 1)) * t * t;
93 throw Exception(
"There must be at least two control points and the arrays must be of equal length.");
99 for (
uint04 i = 0; i < n - 1; i++)
101 fltp08 h = (time[i + 1] - time[i]).elapsedSeconds();
103 throw Exception(
"The control points must all have strictly increasing X values:" +
String(time[i]) +
" " +
String(time[i + 1]));
104 dx[i] = (y[i + 1] - y[i]) / h;
109 for (
uint04 i = 1; i < n - 1; i++)
111 mx[i] = (dx[i - 1] + dx[i]) * 0.5f;
113 mx[n - 1] = dx[n - 2];
116 for (
uint04 i = 0; i < n - 1; i++)
125 float a = mx[i] / dx[i];
126 float b = mx[i + 1] / dx[i];
127 if (a < 0.0f || b < 0.0f) {
131 float h = (float)hypot(a, b);
134 mx[i] = t * a * dx[i];
135 mx[i + 1] = t * b * dx[i];
139 return Path(time, y, mx);
144 if (time.
size() != y.size() || time.
size() < 2)
146 throw new Exception(
"There must be at least two control points and the arrays must be of equal length.");
150 for (
int i = 0; i < time.
size() - 1; i++)
152 temp_y.
add(y[i].as<DEGREES>());
153 temp_time.
add(time[i]);
154 if((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) > 180.0)
158 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
159 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
161 if ((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) > 180.0)
165 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
166 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
177 sorted_path.
add(std::pair<Time, fltp04>(time[i], y[i]));
179 std::sort(sorted_path.
begin(), sorted_path.
end(), [](
const std::pair<Time, fltp04>& p1,
const std::pair<Time, fltp04>& p2)
181 return p1.first > p2.first;
187 corrected_value.
add(sorted_path[i].second);
188 corrected_time.
add(sorted_path[i].first);
201 return p1.first > p2.first;
207 corrected_value.
add(sorted_path[i].second);
208 corrected_time.
add(sorted_path[i].first);
Stores an angle in an optimized format.
Definition StringStream.h:352
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
constexpr t_index_type size() const
Definition Buffer.hpp:1461
decltype(auto) last()
Definition Buffer.hpp:977
decltype(auto) end()
Definition Buffer.hpp:746
decltype(auto) begin()
Definition Buffer.hpp:504
Definition Exception.hpp:56
static Path createMonotoneCubicPathSorted(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Definition TimePath.h:172
Path & operator=(const Path &path)
Definition TimePath.h:213
static Path createMonotoneAngleCubicPathSorted(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Definition TimePath.h:192
Path(const Path &path)
Definition TimePath.h:49
Buffer< Time > mX
Definition TimePath.h:221
static Path createMonotoneCubicPath(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Definition TimePath.h:90
static Path createMonotoneCubicPathAzimuth(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Definition TimePath.h:142
Path(const Buffer< Time > &time, const Buffer< fltp04 > &y, const Buffer< fltp04 > &m)
Definition TimePath.h:43
fltp08 interpolateX(const Time ¤t_time)
Definition TimePath.h:61
Path()
Definition TimePath.h:41
Buffer< fltp04 > mM
Definition TimePath.h:223
Buffer< fltp04 > mY
Definition TimePath.h:222
Path(const Path &&path)
Definition TimePath.h:55
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272