Browse Source

Add unit tests for predicates.

Qingnan Zhou 6 years ago
parent
commit
01a18ac2ed

+ 73 - 1
include/igl/predicates/predicates.cpp

@@ -24,7 +24,7 @@ IGL_INLINE Orientation orient2d(
 
     if (r > 0) return Orientation::POSITIVE;
     else if (r < 0) return Orientation::NEGATIVE;
-    else return Orientation::COLINEAR;
+    else return Orientation::COLLINEAR;
 }
 
 template<typename Vector3D>
@@ -123,6 +123,22 @@ const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&
 );
+template
+igl::predicates::Orientation
+igl::predicates::orient2d<Eigen::Matrix<double, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&
+);
+template
+igl::predicates::Orientation
+igl::predicates::orient2d<Eigen::Matrix<float, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&
+);
 
 
 template
@@ -143,6 +159,24 @@ const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&
 );
+template
+igl::predicates::Orientation
+igl::predicates::orient3d<Eigen::Matrix<double, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&
+);
+template
+igl::predicates::Orientation
+igl::predicates::orient3d<Eigen::Matrix<float, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&
+);
 
 
 template
@@ -163,6 +197,24 @@ const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&
 );
+template
+igl::predicates::Orientation
+igl::predicates::incircle<Eigen::Matrix<double, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&
+);
+template
+igl::predicates::Orientation
+igl::predicates::incircle<Eigen::Matrix<float, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&
+);
 
 
 template
@@ -185,5 +237,25 @@ const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&,
 const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 1, -1, -1>>&
 );
+template
+igl::predicates::Orientation
+igl::predicates::insphere<Eigen::Matrix<double, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&
+);
+template
+igl::predicates::Orientation
+igl::predicates::insphere<Eigen::Matrix<float, -1, -1, 0, -1, -1>>
+(
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&,
+const Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1>>&
+);
 
 #endif

+ 1 - 1
include/igl/predicates/predicates.h

@@ -10,7 +10,7 @@ namespace igl {
     enum class Orientation {
       POSITIVE=1, INSIDE=1,
       NEGATIVE=-1, OUTSIDE=-1,
-      COLINEAR=0, COPLANAR=0, COCIRCULAR=0, COSPHERICAL=0, DEGENERATE=0
+      COLLINEAR=0, COPLANAR=0, COCIRCULAR=0, COSPHERICAL=0, DEGENERATE=0
     };
 
     template<typename Vector2D>

+ 8 - 0
tests/CMakeLists.txt

@@ -76,6 +76,14 @@ if(LIBIGL_WITH_EMBREE)
   target_link_libraries(libigl_tests PUBLIC igl::embree)
 endif()
 
+if(LIBIGL_WITH_PREDICATES)
+  file(GLOB TEST_SRC_FILES ./include/igl/predicates/*.cpp)
+  file(GLOB TEST_INC_FILES ./include/igl/predicates/*.h ./include/igl/predicates/*.inl)
+  target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})
+
+  target_link_libraries(libigl_tests PUBLIC igl::predicates)
+endif()
+
 file(GLOB TEST_SRC_FILES ./include/igl/*.cpp)
 file(GLOB TEST_INC_FILES ./include/igl/*.h ./include/igl/*.inl)
 target_sources(libigl_tests PRIVATE ${TEST_SRC_FILES} ${TEST_INC_FILES})

+ 54 - 0
tests/include/igl/predicates/predicates.cpp

@@ -0,0 +1,54 @@
+#include <test_common.h>
+#include <igl/predicates/predicates.h>
+#include <limits>
+
+TEST_CASE("predicates", "[igl][predicates]") {
+    using namespace igl::predicates;
+    using Scalar = double;
+
+    SECTION("2D") {
+        using Point = Eigen::Matrix<Scalar, -1, -1>;
+        Point a(2,1),b(2,1),c(2,1),d(2,1),e(2,1),f(2,1);
+        a << 0.0, 0.0;
+        b << 1.0, 0.0;
+        c << 1.0, 1.0;
+        d << 2.0, 0.0;
+        e << 0.0, 1.0;
+        f << 0.5, 0.5;
+
+        REQUIRE(orient2d(a, b, c) == Orientation::POSITIVE);
+        REQUIRE(orient2d(a, c, b) == Orientation::NEGATIVE);
+        REQUIRE(orient2d(a, b, b) == Orientation::COLLINEAR);
+        REQUIRE(orient2d(a, a, a) == Orientation::COLLINEAR);
+        REQUIRE(orient2d(a, b, d) == Orientation::COLLINEAR);
+        REQUIRE(orient2d(a, f, c) == Orientation::COLLINEAR);
+
+        REQUIRE(incircle(a,b,c,e) == Orientation::COCIRCULAR);
+        REQUIRE(incircle(a,b,c,a) == Orientation::COCIRCULAR);
+        REQUIRE(incircle(a,b,c,d) == Orientation::OUTSIDE);
+        REQUIRE(incircle(a,b,c,f) == Orientation::INSIDE);
+    }
+
+    SECTION("3D") {
+        using Point = Eigen::Matrix<Scalar, -1, -1>;
+        Point a(3,1),b(3,1),c(3,1),d(3,1),e(3,1),f(3,1);
+        a << 0.0, 0.0, 0.0;
+        b << 1.0, 0.0, 0.0;
+        c << 0.0, 1.0, 0.0;
+        d << 0.0, 0.0, 1.0;
+        e << 1.0, 1.0, 1.0;
+        f << std::numeric_limits<Scalar>::epsilon(), 0.0, 0.0;
+
+        REQUIRE(orient3d(a, b, c, d) == Orientation::NEGATIVE);
+        REQUIRE(orient3d(a, b, d, c) == Orientation::POSITIVE);
+        REQUIRE(orient3d(a, b, d, d) == Orientation::COPLANAR);
+        REQUIRE(orient3d(a, a, a, a) == Orientation::COPLANAR);
+        REQUIRE(orient3d(a, b, f, c) == Orientation::COPLANAR);
+
+        REQUIRE(insphere(a, b, c, d, e) == Orientation::COSPHERICAL);
+        REQUIRE(insphere(a, b, d, e, c) == Orientation::COSPHERICAL);
+        REQUIRE(insphere(b, c, e, d, ((a+b)*0.5).eval()) == Orientation::INSIDE);
+        REQUIRE(insphere(b, c, e, d, (-f).eval()) == Orientation::OUTSIDE);
+        REQUIRE(insphere(f, b, d, c, e) == Orientation::INSIDE);
+    }
+}