Fixed C++ quickstart example.
int main(int argc, char **argv)
{
- // Create a clamped spline of degree 3 in 2D consisting of 7 control points.
- ts::BSpline spline(3, 2, 7, TS_CLAMPED);
+ // Create a spline...
+ tinyspline::BSpline spline(
+ 3, // ... of degree 3...
+ 2, // ... in 2D...
+ 7, // ... consisting of 7 control points...
+ TS_CLAMPED // ... using a clamped knot vector.
+ );
- // Setup the control points.
- std::vector<ts::rational> ctrlp = spline.ctrlp();
+ // Setup control points.
+ std::vector<tinyspline::rational> ctrlp = spline.ctrlp();
ctrlp[0] = -1.75f; // x0
ctrlp[1] = -1.0f; // y0
ctrlp[2] = -1.5f; // x1
@@ -24,15 +29,20 @@ int main(int argc, char** argv)
ctrlp[13] = 0.0f; // y6
spline.setCtrlp(ctrlp);
- // Evaluate `spline` at u = 0.4
- std::vector<ts::rational> result = spline.evaluate(0.4f).result();
+ // Stores our evaluation results.
+ std::vector<tinyspline::rational> result;
+
+ // Evaluate `spline` at u = 0.4 using 'evaluate'.
+ result = spline.evaluate(0.4f).result();
std::cout << "x = " << result[0] << ", y = " << result[1] << std::endl;
// Derive `spline` and subdivide it into a sequence of Bezier curves.
- ts::BSpline beziers = spline.derive().toBeziers();
+ tinyspline::BSpline beziers = spline.derive().toBeziers();
- // Evaluate `beziers` at u = 0.3
- result = beziers(0.3f).result(); // you can use '()' instead of 'evaluate'
+ // Evaluate `beziers` at u = 0.3 using '()' instead of 'evaluate'.
+ result = beziers(0.3f).result();
std::cout << "x = " << result[0] << ", y = " << result[1] << std::endl;
+
+ return 0;
}
