fit_cubic_bezier.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include <test_common.h>
  9. #include <igl/fit_cubic_bezier.h>
  10. #include <igl/bezier.h>
  11. #include <igl/PI.h>
  12. TEST_CASE("fit_cubic_bezier: hemicircle", "[igl]")
  13. {
  14. // Create a hemicircle
  15. Eigen::MatrixXd d(101,2);
  16. for(int i=0;i<d.rows();i++)
  17. {
  18. const double th = double(i)/double(d.rows()-1)*igl::PI;
  19. d(i,0) = cos(th);
  20. d(i,1) = sin(th);
  21. }
  22. const double error = 0.000001;
  23. std::vector<Eigen::MatrixXd> cubics;
  24. igl::fit_cubic_bezier(d,error,cubics);
  25. REQUIRE(cubics.size()>1);
  26. REQUIRE(cubics.size()<10);
  27. // Generate a dense sampling
  28. const Eigen::VectorXd T = Eigen::VectorXd::LinSpaced(1000,0,1);
  29. Eigen::MatrixXd X;
  30. igl::bezier(cubics,T,X);
  31. for(int j=0;j<d.rows();j++)
  32. {
  33. const double sd =
  34. ((X.rowwise()-d.row(j)).rowwise().squaredNorm()).minCoeff();
  35. REQUIRE(sd < error);
  36. }
  37. }