PERRY v1.0.0
P-E-R-R-Y/PERRY helps creating games with a bunch of tools.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
interpolation.hpp
1#include <vector>
2#include <array>
3
4template <int k>
6 public:
7 static inline double cubic(double factor, double start, double end) {
8 return start + factor * factor * (3.0 - 2.0 * factor) * (end - start);
9 }
10
11 static inline double linear(double factor, double start, double end) {
12 return start + factor * (end - start);
13 }
14
15 static inline std::array<double, k> linear(double factor, std::vector<std::array<double, k>> vec) {
16 std::array<std::vector<double>, k> result;
17 std::array<double, k> result_array;
18
19 for (size_t j = 0; j < k; j++) {
20 for (size_t i = 0; i < vec.size(); i++) {
21 result[j].push_back(vec[i][j]);
22 }
23 }
24
25 while (result[0].size() > 1) {
26 std::array<std::vector<double>, k> temp_result;
27
28 // Interpolate between adjacent vectors
29 for (size_t i = 0; i < k; i++) {
30 for (size_t j = 0; j < result[i].size() - 1; j++) {
31 temp_result[i].push_back(linear(factor, result[i][j], result[i][j + 1]));
32 }
33 }
34
35 result = temp_result;
36 }
37
38 for (int i = 0; i < k; i++) {
39 result_array[i] = result[i][0];
40 }
41 return result_array;
42 }
43};
Definition interpolation.hpp:5