#pragma once #include #include #include #include #include #include #include #include #include #include namespace test_common { template void run_test_cases(const std::vector ¶ms, Fun test_case) { for(const auto &p : params) test_case(p); } inline std::vector closed_genus_0_meshes() { return { "cube.obj", "decimated-knight.obj", "boolean_minus_test_cube.obj", "boolean_minus_test_green.obj", }; }; inline std::vector closed_manifold_meshes() { std::vector meshes = closed_genus_0_meshes(); meshes.insert(meshes.end(), { "TinyTorus.obj", }); return meshes; }; inline std::vector manifold_meshes() { std::vector meshes = closed_manifold_meshes(); meshes.insert(meshes.end(), { "bunny.off", "elephant.off", "hemisphere.obj", }); return meshes; }; inline std::vector tet_meshes() { return { "decimated-knight.mesh" }; }; inline std::vector all_meshes() { std::vector meshes = manifold_meshes(); meshes.insert(meshes.end(), { "truck.obj", }); return meshes; }; inline std::string data_path(std::string s) { return std::string(LIBIGL_DATA_DIR) + "/" + s; }; // TODO: this seems like a pointless indirection. Should just find and // replace test_common::load_mesh(X,...) with // igl::read_triangle_mesh(test_common::data_path(X),...) template void load_mesh( const std::string& filename, Eigen::PlainObjectBase& V, Eigen::PlainObjectBase& F) { igl::read_triangle_mesh(data_path(filename), V, F); } // TODO: this seems like a pointless indirection. Should just find and // replace test_common::load_matrix(X,...) with // igl::readDMAT(test_common::data_path(X),...) template void load_matrix( const std::string& filename, Eigen::PlainObjectBase& M) { igl::readDMAT(data_path(filename), M); } template void assert_eq( const Eigen::MatrixBase & A, const Eigen::MatrixBase & B) { // Sizes should match REQUIRE(A.rows() == B.rows()); REQUIRE(A.cols() == B.cols()); for(int i = 0;i Aijv {i,j,A(i,j)}; std::tuple Bijv {i,j,B(i,j)}; REQUIRE(Aijv == Bijv); } } } template void assert_eq( const Eigen::SparseMatrix & A, const Eigen::SparseMatrix & B) { // Sizes should match REQUIRE(A.rows() == B.rows()); REQUIRE(A.cols() == B.cols()); Eigen::Matrix AI,AJ; Eigen::Matrix BI,BJ; Eigen::Matrix AV; Eigen::Matrix BV; // Assumes A and B are in same Major Ordering igl::find(A,AI,AJ,AV); igl::find(B,BI,BJ,BV); // This doesn't generalized to assert_near nicely, and it makes it hard to // tell which entries are different: assert_eq(AI,BI); assert_eq(AJ,BJ); assert_eq(AV,BV); } template void assert_near( const Eigen::MatrixBase & A, const Eigen::MatrixBase & B, const EpsType & eps) { // Sizes should match REQUIRE(A.rows() == B.rows()); REQUIRE(A.cols() == B.cols()); for(int i = 0;i Aijv {i,j,A(i,j)}; // std::tuple Bijv {i,j,B(i,j)+eps}; REQUIRE(A(i,j) < B(i,j)+eps); } { // std::tuple Aijv {i,j,A(i,j)+eps}; // std::tuple Bijv {i,j,B(i,j)}; REQUIRE(A(i,j)+eps > B(i,j)); } } } } }