33#include <NDEVR/Buffer.h>
34#include <NDEVR/Time.h>
35#include <NDEVR/TimeSpan.h>
71 if (current_time <=
mX[0]) {
74 if (current_time >=
mX.last()) {
80 while (current_time >=
mX[i + 1])
83 if (current_time ==
mX[i])
87 fltp08 h = (
mX[i + 1] -
mX[i]).elapsedSeconds();
88 fltp08 t = (current_time -
mX[i]).elapsedSeconds() / h;
89 return (
mY[i] * (1 + 2 * t) + h *
mM[i] * t) * (1 - t) * (1 - t)
90 + (
mY[i + 1] * (3 - 2 * t) + h *
mM[i + 1] * (t - 1)) * t * t;
96 throw Exception(
"There must be at least two control points and the arrays must be of equal length.");
102 for (
uint04 i = 0; i < n - 1; i++)
104 fltp08 h = (time[i + 1] - time[i]).elapsedSeconds();
106 throw Exception(
"The control points must all have strictly increasing X values:" +
String(time[i]) +
" " +
String(time[i + 1]));
112 for (
uint04 i = 1; i < n - 1; i++)
114 mx[i] = (dx[i - 1] + dx[i]) * 0.5f;
116 mx[n - 1] = dx[n - 2];
119 for (
uint04 i = 0; i < n - 1; i++)
128 float a = mx[i] / dx[i];
129 float b = mx[i + 1] / dx[i];
130 if (a < 0.0f || b < 0.0f) {
134 float h = (float)hypot(a, b);
137 mx[i] = t * a * dx[i];
138 mx[i + 1] = t * b * dx[i];
142 return Path(time, y, mx);
147 if (time.
size() != y.size() || time.
size() < 2)
149 throw new Exception(
"There must be at least two control points and the arrays must be of equal length.");
156 temp_time.
add(time[i]);
157 if((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) > 180.0)
159 temp_y.
add( 179.99f);
160 temp_y.
add(-179.99f);
161 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
162 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
164 if ((y[i].as<DEGREES>() - y[i + 1].as<DEGREES>()) > 180.0)
166 temp_y.
add(-179.99f);
167 temp_y.
add( 179.99f);
168 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
169 temp_time.
add(time[i] + (time[i + 1] - time[i]) / 2.0);
180 sorted_path.
add(std::pair<Time, fltp04>(time[i], y[i]));
182 std::sort(sorted_path.
begin(), sorted_path.
end(), [](
const std::pair<Time, fltp04>& p1,
const std::pair<Time, fltp04>& p2)
184 return p1.first > p2.first;
190 corrected_value.
add(sorted_path[i].second);
191 corrected_time.
add(sorted_path[i].first);
204 return p1.first > p2.first;
210 corrected_value.
add(sorted_path[i].second);
211 corrected_time.
add(sorted_path[i].first);
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
void add(t_type &&object)
Adds object to the end of the buffer.
Definition Buffer.hpp:186
constexpr t_index_type size() const
Definition Buffer.hpp:823
decltype(auto) last()
Definition Buffer.hpp:588
decltype(auto) end()
Definition Buffer.hpp:507
decltype(auto) begin()
Definition Buffer.hpp:402
Provides consistent interface to handle errors through the throw expression. All exceptions generated...
Definition Exception.hpp:47
An interpolated path in 3D space.
Definition TimePath.h:42
static Path createMonotoneCubicPathSorted(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Definition TimePath.h:175
Path & operator=(const Path &path)
Definition TimePath.h:216
static Path createMonotoneAngleCubicPathSorted(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Definition TimePath.h:195
Path(const Path &path)
Definition TimePath.h:52
Buffer< Time > mX
Definition TimePath.h:224
static Path createMonotoneCubicPath(const Buffer< Time > &time, const Buffer< fltp04 > &y)
Definition TimePath.h:93
static Path createMonotoneCubicPathAzimuth(const Buffer< Time > &time, const Buffer< Angle< fltp08 > > &y)
Definition TimePath.h:145
Path(const Buffer< Time > &time, const Buffer< fltp04 > &y, const Buffer< fltp04 > &m)
Definition TimePath.h:46
fltp08 interpolateX(const Time ¤t_time)
Definition TimePath.h:64
Path()
Definition TimePath.h:44
Buffer< fltp04 > mM
Definition TimePath.h:226
Buffer< fltp04 > mY
Definition TimePath.h:225
Path(const Path &&path)
Definition TimePath.h:58
The core String class for the NDEVR API.
Definition String.h:69
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233