33#include <NDEVR/Buffer.h>
34#include <NDEVR/Time.h>
35#include <NDEVR/TimeSpan.h>
103 return Constant<fltp08>::Invalid;
105 if (current_time <=
mX[0]) {
108 if (current_time >=
mX.last()) {
114 while (current_time >=
mX[i + 1])
117 if (current_time ==
mX[i])
121 fltp08 h = (
mX[i + 1] -
mX[i]).elapsedSeconds();
122 fltp08 t = (current_time -
mX[i]).elapsedSeconds() / h;
123 return (
mY[i] * (1 + 2 * t) + h *
mM[i] * t) * (1 - t) * (1 - t)
124 + (
mY[i + 1] * (3 - 2 * t) + h *
mM[i + 1] * (t - 1)) * t * t;
142 if (time.size() != y.size() || time.size() < 2)
143 throw Exception(_t(
"There must be at least two control points and the arrays must be of equal length."));
149 for (
uint04 i = 0; i < n - 1; i++)
151 fltp08 h = (time[i + 1] - time[i]).elapsedSeconds();
153 throw Exception(
"The control points must all have strictly increasing X values:" +
String(time[i]) +
" " +
String(time[i + 1]));
159 for (
uint04 i = 1; i < n - 1; i++)
161 mx[i] = (dx[i - 1] + dx[i]) * 0.5f;
163 mx[n - 1] = dx[n - 2];
166 for (
uint04 i = 0; i < n - 1; i++)
175 float a = mx[i] / dx[i];
176 float b = mx[i + 1] / dx[i];
177 if (a < 0.0f || b < 0.0f) {
181 float h = (float)
hypot(a, b);
184 mx[i] = t * a * dx[i];
185 mx[i + 1] = t * b * dx[i];
189 return Path(time, y, mx);
210 if (time.size() != y.size() || time.size() < 2)
212 throw new Exception(_t(
"There must be at least two control points and the arrays must be of equal length."));
216 for (
uint04 i = 0; i < time.size() - 1; i++)
219 temp_time.
add(time[i]);
220 if((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) > 180.0)
222 temp_y.
add( 179.99f);
223 temp_y.
add(-179.99f);
224 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
225 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
227 if ((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) < -180.0)
229 temp_y.
add(-179.99f);
230 temp_y.
add( 179.99f);
231 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
232 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
255 for (
uint04 i = 0; i < time.size(); i++)
257 sorted_path.
add(std::pair<Time, fltp04>(time[i], y[i]));
259 std::sort(sorted_path.begin(), sorted_path.end(), [](
const std::pair<Time, fltp04>& p1,
const std::pair<Time, fltp04>& p2)
261 return p1.first > p2.first;
265 for (
uint04 i = 0; i < time.size(); i++)
267 corrected_value.
add(sorted_path[i].second);
268 corrected_time.
add(sorted_path[i].first);
288 for (
uint04 i = 0; i < time.size(); i++)
294 return p1.first > p2.first;
298 for (
uint04 i = 0; i < time.size(); i++)
300 corrected_value.
add(sorted_path[i].second);
301 corrected_time.
add(sorted_path[i].first);
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
The equivelent of std::vector but with a bit more control.
void add(t_type &&object)
Adds object to the end of the buffer.
Provides consistent interface to handle errors through the throw expression.
Path(const Buffer< Time > &time, const Buffer< fltp04 > &y, const Buffer< fltp04 > &m)
Constructs a Path from pre-computed time, value, and tangent buffers.
fltp08 interpolateX(const Time ¤t_time)
Interpolates the path value at a given time using cubic Hermite spline interpolation.
Buffer< fltp04 > mM
The tangent (slope) values at each control point, used for Hermite interpolation.
Buffer< fltp04 > mY
The interpolated values (Y-axis) at each control point.
Path(const Path &&path)
Move constructor.
static Path createMonotoneCubicPathAzimuth(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Creates a monotone cubic Hermite spline path for azimuth (angular) values over time.
Path & operator=(const Path &path)
Copy assignment operator.
static Path createMonotoneAngleCubicPathSorted(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Creates a monotone cubic angle path after sorting the control points by time in descending order.
Path(const Path &path)
Copy constructor.
static Path createMonotoneCubicPath(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Creates a monotone cubic Hermite spline path from time-value control points.
Buffer< Time > mX
The time values (X-axis) for each control point.
Path()
Default constructor.
static Path createMonotoneCubicPathSorted(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Creates a monotone cubic path after sorting the control points by time in descending order.
The core String class for the NDEVR API.
Represents a timestamp with utilities for manipulation and conversion.
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
T hypot(T x, T y)
return the hypot of x and y
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.