segment_segment_intersect.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <test_common.h>
  2. #include <igl/segment_segment_intersect.h>
  3. TEST_CASE("segment_segment_intersect: examples", "[igl]")
  4. {
  5. // example 1
  6. // https://github.com/libigl/libigl/issues/965
  7. auto s1 = Eigen::RowVector3d(581, 388, -54);
  8. auto dir1 = Eigen::RowVector3d(0.75, -4.36, 0.64);
  9. auto s2 = Eigen::RowVector3d(636, 77, -10);
  10. auto dir2 = Eigen::RowVector3d(-2.79, 0.96, 0.39);
  11. double a1, a2;
  12. bool sect1 = igl::segment_segment_intersect(s1, dir1, s2, dir2, a1, a2);
  13. bool intersectCondition1 = (a1 >= 0 && a1 <= 1 && a2 >= 0 && a2 <= 1);
  14. REQUIRE(sect1 == false);
  15. REQUIRE(intersectCondition1 == false);
  16. // example 2
  17. // https://github.com/libigl/libigl/issues/957
  18. auto s3 = Eigen::RowVector3d(-56.6, 0, -201.7);
  19. auto dir3 = Eigen::RowVector3d(0, 0, 1);
  20. auto s4 = Eigen::RowVector3d(-65.6, 0, 258.8);
  21. auto dir4 = Eigen::RowVector3d(15.4, 0, 1.9);
  22. double a3, a4;
  23. bool sect2 = igl::segment_segment_intersect(s3, dir3, s4, dir4, a3, a4);
  24. bool intersectCondition2 = (a3 >= 0 && a3 <= 1 && a4 >= 0 && a4 <= 1);
  25. REQUIRE(sect2 == false);
  26. REQUIRE(intersectCondition2 == false);
  27. }