predicates.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <test_common.h>
  2. #include <igl/predicates/predicates.h>
  3. #include <limits>
  4. #include <igl/triangle/triangulate.h>
  5. TEST_CASE("predicates", "[igl][predicates]") {
  6. using namespace igl::predicates;
  7. using Scalar = double;
  8. igl::predicates::exactinit();
  9. SECTION("2D") {
  10. using Point = Eigen::Matrix<Scalar, 2, 1>;
  11. Point a(2,1),b(2,1),c(2,1),d(2,1),e(2,1),f(2,1);
  12. a << 0.0, 0.0;
  13. b << 1.0, 0.0;
  14. c << 1.0, 1.0;
  15. d << 2.0, 0.0;
  16. e << 0.0, 1.0;
  17. f << 0.5, 0.5;
  18. REQUIRE(orient2d(a, b, c) == Orientation::POSITIVE);
  19. REQUIRE(orient2d(a, c, b) == Orientation::NEGATIVE);
  20. REQUIRE(orient2d(a, b, b) == Orientation::COLLINEAR);
  21. REQUIRE(orient2d(a, a, a) == Orientation::COLLINEAR);
  22. REQUIRE(orient2d(a, b, d) == Orientation::COLLINEAR);
  23. REQUIRE(orient2d(a, f, c) == Orientation::COLLINEAR);
  24. REQUIRE(incircle(a,b,c,e) == Orientation::COCIRCULAR);
  25. REQUIRE(incircle(a,b,c,a) == Orientation::COCIRCULAR);
  26. REQUIRE(incircle(a,b,c,d) == Orientation::OUTSIDE);
  27. REQUIRE(incircle(a,b,c,f) == Orientation::INSIDE);
  28. }
  29. SECTION("3D") {
  30. using Point = Eigen::Matrix<Scalar, 3, 1>;
  31. Point a(3,1),b(3,1),c(3,1),d(3,1),e(3,1),f(3,1);
  32. a << 0.0, 0.0, 0.0;
  33. b << 1.0, 0.0, 0.0;
  34. c << 0.0, 1.0, 0.0;
  35. d << 0.0, 0.0, 1.0;
  36. e << 1.0, 1.0, 1.0;
  37. f << std::numeric_limits<Scalar>::epsilon(), 0.0, 0.0;
  38. REQUIRE(orient3d(a, b, c, d) == Orientation::NEGATIVE);
  39. REQUIRE(orient3d(a, b, d, c) == Orientation::POSITIVE);
  40. REQUIRE(orient3d(a, b, d, d) == Orientation::COPLANAR);
  41. REQUIRE(orient3d(a, a, a, a) == Orientation::COPLANAR);
  42. REQUIRE(orient3d(a, b, f, c) == Orientation::COPLANAR);
  43. REQUIRE(insphere(a, b, c, d, e) == Orientation::COSPHERICAL);
  44. REQUIRE(insphere(a, b, d, e, c) == Orientation::COSPHERICAL);
  45. REQUIRE(insphere(b, c, e, d, ((a+b)*0.5).eval()) == Orientation::INSIDE);
  46. REQUIRE(insphere(b, c, e, d, (-f).eval()) == Orientation::OUTSIDE);
  47. REQUIRE(insphere(f, b, d, c, e) == Orientation::INSIDE);
  48. }
  49. SECTION("Predicate and triangle") {
  50. Eigen::Matrix<double, -1, -1> vertices(4, 2);
  51. Eigen::Matrix<double, -1, -1> holes;
  52. Eigen::Matrix<int, -1, -1> edges;
  53. vertices << 0.0, 0.0,
  54. 1.0, 0.0,
  55. 0.0, 1.0,
  56. 1.0, 1.0;
  57. Eigen::Matrix<double, -1, -1> out_vertices;
  58. Eigen::Matrix<int, -1, -1> out_faces;
  59. // Run constrained Delaunay.
  60. igl::triangle::triangulate(vertices, edges, holes, "QcYY",
  61. out_vertices, out_faces);
  62. REQUIRE(out_vertices.rows() == 4);
  63. REQUIRE(out_vertices.cols() == 2);
  64. REQUIRE(out_faces.rows() == 2);
  65. REQUIRE(out_faces.cols() == 3);
  66. }
  67. }