35 std::runtime_error(
"Error While Executing Path Code: " + description)
51 { a - b } -> std::same_as<T>;
52 { a* t } -> std::same_as<T>;
53 { a + b } -> std::same_as<T>;
54 { a.t } -> std::convertible_to<RealType>;
65template <Interpolatable T>
84template <Interpolatable T>
92 auto xrp = std::ranges::upper_bound(coords, t, {}, &T::t);
94 if (xrp == coords.begin())
98 else if (xrp == coords.end())
104 auto xri = std::distance(coords.begin(), xrp);
107 const RealType iw = coords[xri].t - coords[xli].t;
108 const RealType rw = (coords[xri].t - t) / iw;
111 coord = coords[xri] * lw + coords[xli] * rw;
127template <Interpolatable T>
135 auto xrp = std::ranges::upper_bound(coords, t, {}, &T::t);
137 if (xrp == coords.begin())
141 else if (xrp == coords.end())
147 auto xri = std::distance(coords.begin(), xrp);
150 const RealType xrd = coords[xri].t - t;
151 const RealType xld = t - coords[xli].t;
152 const RealType iw = coords[xri].t - coords[xli].t;
156 const RealType c = (a * a * a - a) * iws;
157 const RealType d = (b * b * b - b) * iws;
159 coord = coords[xli] * a + coords[xri] * b + dd[xli] * c + dd[xri] * d;
172template <Interpolatable T>
175 const int size =
static_cast<int>(coords.size());
181 std::vector<T> tmp(size);
187 for (
int i = 1; i < size - 1; ++i)
189 const T yrd = coords[i + 1] - coords[i];
190 const T yld = coords[i] - coords[i - 1];
191 const RealType xrd = coords[i + 1].t - coords[i].t;
192 const RealType xld = coords[i].t - coords[i - 1].t;
193 const RealType iw = coords[i + 1].t - coords[i - 1].t;
195 const T p = dd[i - 1] * si + 2.0;
196 dd[i] = (si - 1.0) / p;
197 tmp[i] = ((yrd / xrd - yld / xld) * 6.0 / iw - tmp[i - 1] * si) / p;
200 for (
int i = size - 2; i >= 0; --i)
202 dd[i] = dd[i] * dd[i + 1] + tmp[i];
Exception class for handling path-related errors.
PathException(const std::string &description)
Constructor for PathException.
Concept for types that can be interpolated.
double RealType
Type for real numbers.
void getPositionLinear(RealType t, T &coord, const std::vector< T > &coords)
Performs linear interpolation between coordinate points.
void getPositionStatic(T &coord, const std::vector< T > &coords)
Interpolates a static position from a list of coordinates.
void finalizeCubic(const std::vector< T > &coords, std::vector< T > &dd)
Finalizes cubic spline interpolation by calculating second derivatives.
void getPositionCubic(RealType t, T &coord, const std::vector< T > &coords, const std::vector< T > &dd)
Performs cubic spline interpolation between coordinate points.