predicates.cpp 2.3 KB

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