6 #ifndef PROJECT_INTERPOLATION_H 7 #define PROJECT_INTERPOLATION_H 10 #include <type_traits> 17 template <
typename y_t,
typename x_t>
18 y_t
lerp(y_t y0, y_t yf, x_t x) {
19 static_assert(std::is_floating_point<x_t>::value,
20 "must use floating point value");
21 assert(x >= 0 && x <= 1);
22 return y0 + (yf - y0) * x;
28 template <
typename y_t,
typename x_t>
30 static_assert(std::is_floating_point<x_t>::value,
31 "must use floating point value");
32 assert(x >= 0 && x <= 1);
34 x_t bezier = x * x * x + x_t(3) * (x * x * (x_t(1) - x));
35 return y0 + bezier * yDiff;
42 template <
typename y_t,
typename x_t>
44 static_assert(std::is_floating_point<x_t>::value,
45 "must use floating point value");
46 assert(x >= 0 && x <= 1);
48 x_t bezier = x_t(6) * x * (x_t(1) - x);
49 return bezier * yDiff;
56 template <
typename y_t,
typename x_t>
58 static_assert(std::is_floating_point<x_t>::value,
59 "must use floating point value");
60 assert(x >= 0 && x <= 1);
62 x_t bezier = x_t(6) - x_t(12) * x;
63 return bezier * yDiff;
68 #endif // PROJECT_INTERPOLATION_H
y_t lerp(y_t y0, y_t yf, x_t x)
y_t cubicBezierFirstDerivative(y_t y0, y_t yf, x_t x)
y_t cubicBezier(y_t y0, y_t yf, x_t x)
y_t cubicBezierSecondDerivative(y_t y0, y_t yf, x_t x)