segment_segment_intersect.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <test_common.h>
  2. #include <igl/predicates/segment_segment_intersect.h>
  3. #include <iomanip>
  4. TEST_CASE("segment_segment_intersect: robust", "[igl/predicates]")
  5. {
  6. // example 1: vanila intersecting case
  7. auto A1 = Eigen::RowVector2d(0, 128.5);
  8. auto B1 = Eigen::RowVector2d(-77.44,1.2);
  9. auto C1 = Eigen::RowVector2d(-83.2,2.8);
  10. auto D1 = Eigen::RowVector2d(-1.0,-1.0);
  11. bool check1 = igl::predicates::segment_segment_intersect(A1,B1,C1,D1);
  12. REQUIRE(check1 == true);
  13. // example 2: colinear overlapping
  14. auto A2 = Eigen::RowVector2d(1.0,5.0);
  15. auto B2 = Eigen::RowVector2d(1.0,9.0);
  16. auto C2 = Eigen::RowVector2d(1.0,8.0);
  17. auto D2 = Eigen::RowVector2d(1.0,12.0);
  18. bool check2 = igl::predicates::segment_segment_intersect(A2,B2,C2,D2);
  19. REQUIRE(check2 == true);
  20. // example 3: colinear touching endpoint
  21. auto A3 = Eigen::RowVector2d(0.0,0.0);
  22. auto B3 = Eigen::RowVector2d(1.5,1.5);
  23. auto C3 = Eigen::RowVector2d(1.5,1.5);
  24. auto D3 = Eigen::RowVector2d(2.0,2.0);
  25. bool check3 = igl::predicates::segment_segment_intersect(A3,B3,C3,D3);
  26. REQUIRE(check3 == true);
  27. // example 6: colinear not touching endpoint
  28. double eps = 1e-14;
  29. auto A4 = Eigen::RowVector2d(0.0,0.0);
  30. auto B4 = Eigen::RowVector2d(1.5,1.5);
  31. auto C4 = Eigen::RowVector2d(1.5+eps,1.5+eps);
  32. auto D4 = Eigen::RowVector2d(2.0,2.0);
  33. bool check4 = igl::predicates::segment_segment_intersect(A4,B4,C4,D4);
  34. REQUIRE(check4 == false);
  35. }