turning_number.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <test_common.h>
  2. #include <igl/turning_number.h>
  3. #include <igl/matlab_format.h>
  4. #include <igl/PI.h>
  5. #include <iostream>
  6. TEST_CASE("turning_number: pentagon", "[igl]")
  7. {
  8. Eigen::MatrixXd V(5, 2);
  9. V << 0, 0 ,
  10. 1, 0 ,
  11. 1, 1 ,
  12. 0.5, 1.5,
  13. 0, 1 ;
  14. const double t_ccw = igl::turning_number(V);
  15. // Reverse rows of V
  16. V = V.colwise().reverse().eval();
  17. const double t_cw = igl::turning_number(V);
  18. REQUIRE( abs(t_ccw - 1) < 1e-16 );
  19. REQUIRE( abs(t_cw - -1) < 1e-16 );
  20. }
  21. TEST_CASE("turning_number: heptagram", "[igl]")
  22. {
  23. Eigen::MatrixXd V(7,2);
  24. for (int i = 0; i < 7; i++)
  25. {
  26. // Multiply by 3 to get the {7/3} skipping pattern
  27. double theta = 2.0 * igl::PI * (3 * i) / 7;
  28. V(i, 0) = std::cos(theta);
  29. V(i, 1) = std::sin(theta);
  30. }
  31. const double t_ccw = igl::turning_number(V);
  32. // Reverse rows of V
  33. V = V.colwise().reverse().eval();
  34. const double t_cw = igl::turning_number(V);
  35. REQUIRE( abs(t_ccw - 3) < 1e-16 );
  36. REQUIRE( abs(t_cw - -3) < 1e-16 );
  37. }