-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bezier.cpp
42 lines (37 loc) · 1.22 KB
/
Bezier.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Bezier.hpp"
//template<uint8_t N>
//Node bezier_curve(std::array<Node, N> nodes, float ratio) {
// if (nodes.size() == 0) {
// return Node{ 0, 0 };
// }
// else if (nodes.size() == 1) {
// return nodes[0];
// }
//
// std::array<Node, N - 1> new_nodes;
//
// for (uint8_t i = 0; i < nodes.size() - 1; i++) {
// Node new_node{ 0, 0 };
// new_node.first = nodes[i].first + (nodes[i + 1].first - nodes[i].first) * ratio;
// new_node.second = nodes[i].second + (nodes[i + 1].second - nodes[i].second) * ratio;
// new_nodes[i] = new_node;
// }
//
// return bezier_curve<N - 1>(new_nodes, ratio);
//}
Node bezier_curve(std::vector<Node> nodes, float ratio) {
if (nodes.size() == 0) {
return Node{ 0, 0 };
}
else if (nodes.size() == 1) {
return nodes[0];
}
std::vector<Node> new_nodes;
for (uint8_t i = 0; i < nodes.size() - 1; i++) {
Node new_node{ 0, 0 };
new_node.first = nodes[i].first + (nodes[i + 1].first - nodes[i].first) * ratio;
new_node.second = nodes[i].second + (nodes[i + 1].second - nodes[i].second) * ratio;
new_nodes.push_back(new_node);
}
return bezier_curve(new_nodes, ratio);
}