predicates.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <test_common.h>
  2. #include <igl/predicates/predicates.h>
  3. #include <limits>
  4. TEST_CASE("predicates", "[igl][predicates]") {
  5. using namespace igl::predicates;
  6. using Scalar = double;
  7. SECTION("2D") {
  8. using Point = Eigen::Matrix<Scalar, -1, -1>;
  9. Point a(2,1),b(2,1),c(2,1),d(2,1),e(2,1),f(2,1);
  10. a << 0.0, 0.0;
  11. b << 1.0, 0.0;
  12. c << 1.0, 1.0;
  13. d << 2.0, 0.0;
  14. e << 0.0, 1.0;
  15. f << 0.5, 0.5;
  16. REQUIRE(orient2d(a, b, c) == Orientation::POSITIVE);
  17. REQUIRE(orient2d(a, c, b) == Orientation::NEGATIVE);
  18. REQUIRE(orient2d(a, b, b) == Orientation::COLLINEAR);
  19. REQUIRE(orient2d(a, a, a) == Orientation::COLLINEAR);
  20. REQUIRE(orient2d(a, b, d) == Orientation::COLLINEAR);
  21. REQUIRE(orient2d(a, f, c) == Orientation::COLLINEAR);
  22. REQUIRE(incircle(a,b,c,e) == Orientation::COCIRCULAR);
  23. REQUIRE(incircle(a,b,c,a) == Orientation::COCIRCULAR);
  24. REQUIRE(incircle(a,b,c,d) == Orientation::OUTSIDE);
  25. REQUIRE(incircle(a,b,c,f) == Orientation::INSIDE);
  26. }
  27. SECTION("3D") {
  28. using Point = Eigen::Matrix<Scalar, -1, -1>;
  29. Point a(3,1),b(3,1),c(3,1),d(3,1),e(3,1),f(3,1);
  30. a << 0.0, 0.0, 0.0;
  31. b << 1.0, 0.0, 0.0;
  32. c << 0.0, 1.0, 0.0;
  33. d << 0.0, 0.0, 1.0;
  34. e << 1.0, 1.0, 1.0;
  35. f << std::numeric_limits<Scalar>::epsilon(), 0.0, 0.0;
  36. REQUIRE(orient3d(a, b, c, d) == Orientation::NEGATIVE);
  37. REQUIRE(orient3d(a, b, d, c) == Orientation::POSITIVE);
  38. REQUIRE(orient3d(a, b, d, d) == Orientation::COPLANAR);
  39. REQUIRE(orient3d(a, a, a, a) == Orientation::COPLANAR);
  40. REQUIRE(orient3d(a, b, f, c) == Orientation::COPLANAR);
  41. REQUIRE(insphere(a, b, c, d, e) == Orientation::COSPHERICAL);
  42. REQUIRE(insphere(a, b, d, e, c) == Orientation::COSPHERICAL);
  43. REQUIRE(insphere(b, c, e, d, ((a+b)*0.5).eval()) == Orientation::INSIDE);
  44. REQUIRE(insphere(b, c, e, d, (-f).eval()) == Orientation::OUTSIDE);
  45. REQUIRE(insphere(f, b, d, c, e) == Orientation::INSIDE);
  46. }
  47. }