Skip to content

Commit 198aa5c

Browse files
committed
unit test for the catmull-rom and b-spline
1 parent ac73797 commit 198aa5c

File tree

2 files changed

+110
-15
lines changed

2 files changed

+110
-15
lines changed

Diff for: README.md

+72-14
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,80 @@ Package provides C++ implementation of spline interpolation
1010

1111
# Usage
1212

13+
# Bezier
14+
1315
To create a Bezier Curve in 2D or 3D environment:
1416

1517
```cpp
16-
Bezier* curve = new Bezier();
17-
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
18-
19-
curve->add_way_point(Vector(1, 1, 0));
20-
curve->add_way_point(Vector(2, 3, 0));
21-
curve->add_way_point(Vector(3, 2, 0));
22-
curve->add_way_point(Vector(4, 6, 0));
23-
...
24-
25-
std::cout << "nodes: " << curve->node_count() << std::endl;
26-
std::cout << "total length: " << curve->total_length() << std::endl;
27-
for (int i = 0; i < curve->node_count(); ++i) {
28-
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
18+
#include <iostream>
19+
#include "../../main/cpp/Bezier.h"
20+
int main(char** argv, int argc) {
21+
Curve* curve = new Bezier();
22+
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
23+
24+
curve->add_way_point(Vector(1, 1, 0));
25+
curve->add_way_point(Vector(2, 3, 0));
26+
curve->add_way_point(Vector(3, 2, 0));
27+
curve->add_way_point(Vector(4, 6, 0));
28+
...
29+
30+
std::cout << "nodes: " << curve->node_count() << std::endl;
31+
std::cout << "total length: " << curve->total_length() << std::endl;
32+
for (int i = 0; i < curve->node_count(); ++i) {
33+
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
34+
}
35+
delete curve;
36+
}
37+
```
38+
39+
# BSpline
40+
41+
To create a BSpline Curve in 2D or 3D environment:
42+
43+
```cpp
44+
#include <iostream>
45+
#include "../../main/cpp/BSpline.h"
46+
int main(char** argv, int argc) {
47+
Curve* curve = new BSpline();
48+
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
49+
50+
curve->add_way_point(Vector(1, 1, 0));
51+
curve->add_way_point(Vector(2, 3, 0));
52+
curve->add_way_point(Vector(3, 2, 0));
53+
curve->add_way_point(Vector(4, 6, 0));
54+
...
55+
56+
std::cout << "nodes: " << curve->node_count() << std::endl;
57+
std::cout << "total length: " << curve->total_length() << std::endl;
58+
for (int i = 0; i < curve->node_count(); ++i) {
59+
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
60+
}
61+
delete curve;
62+
}
63+
```
64+
65+
# CatmullRom
66+
67+
To create a CatmullRom Curve in 2D or 3D environment:
68+
69+
```cpp
70+
#include <iostream>
71+
#include "../../main/cpp/CatmullRom.h"
72+
int main(char** argv, int argc) {
73+
Curve* curve = new CatmullRom();
74+
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
75+
76+
curve->add_way_point(Vector(1, 1, 0));
77+
curve->add_way_point(Vector(2, 3, 0));
78+
curve->add_way_point(Vector(3, 2, 0));
79+
curve->add_way_point(Vector(4, 6, 0));
80+
...
81+
82+
std::cout << "nodes: " << curve->node_count() << std::endl;
83+
std::cout << "total length: " << curve->total_length() << std::endl;
84+
for (int i = 0; i < curve->node_count(); ++i) {
85+
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
86+
}
87+
delete curve;
2988
}
30-
delete curve;
3189
```

Diff for: spline/src/test/cpp/main.cpp

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
#include <iostream>
22
#include "../../main/cpp/Bezier.h"
3+
#include "../../main/cpp/BSpline.h"
4+
#include "../../main/cpp/CatmullRom.h"
5+
36
void demo_bezier();
7+
void demo_bspline();
8+
void demo_catmullrom();
49

510
int main(char** argv, int argc) {
611
demo_bezier();
12+
demo_bspline();
13+
demo_catmullrom();
714
}
815

916
void demo_bezier() {
10-
Bezier* curve = new Bezier();
17+
Curve* curve = new Bezier();
18+
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
19+
curve->add_way_point(Vector(1, 1, 0));
20+
curve->add_way_point(Vector(2, 3, 0));
21+
curve->add_way_point(Vector(3, 2, 0));
22+
curve->add_way_point(Vector(4, 6, 0));
23+
std::cout << "nodes: " << curve->node_count() << std::endl;
24+
std::cout << "total length: " << curve->total_length() << std::endl;
25+
for (int i = 0; i < curve->node_count(); ++i) {
26+
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
27+
}
28+
delete curve;
29+
}
30+
31+
void demo_bspline() {
32+
Curve* curve = new BSpline();
33+
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
34+
curve->add_way_point(Vector(1, 1, 0));
35+
curve->add_way_point(Vector(2, 3, 0));
36+
curve->add_way_point(Vector(3, 2, 0));
37+
curve->add_way_point(Vector(4, 6, 0));
38+
std::cout << "nodes: " << curve->node_count() << std::endl;
39+
std::cout << "total length: " << curve->total_length() << std::endl;
40+
for (int i = 0; i < curve->node_count(); ++i) {
41+
std::cout << "node #" << i << ": " << curve->node(i).toString() << " (length so far: " << curve->length_from_starting_point(i) << ")" << std::endl;
42+
}
43+
delete curve;
44+
}
45+
46+
void demo_catmullrom() {
47+
Curve* curve = new CatmullRom();
1148
curve->set_steps(100); // generate 100 interpolate points between the last 4 way points
1249
curve->add_way_point(Vector(1, 1, 0));
1350
curve->add_way_point(Vector(2, 3, 0));

0 commit comments

Comments
 (0)