doublearea.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <test_common.h>
  2. #include <igl/doublearea.h>
  3. class doublearea : public ::testing::TestWithParam<std::string> {};
  4. TEST_CASE("doublearea: VF_vs_ABC", "[igl]")
  5. {
  6. auto test_case = [](const std::string &param)
  7. {
  8. Eigen::MatrixXd V, TC;
  9. Eigen::MatrixXi F;
  10. test_common::load_mesh(param, V, F, TC);
  11. // Check that computing double area with (V,F) is the same as computing
  12. // double area with (V1,V2,V2)
  13. Eigen::VectorXd A1,A2;
  14. igl::doublearea(V,F,A1);
  15. Eigen::MatrixXd A(F.rows(),3);
  16. Eigen::MatrixXd B(F.rows(),3);
  17. Eigen::MatrixXd C(F.rows(),3);
  18. for(int f = 0;f<F.rows();f++)
  19. {
  20. A.row(f) = V.row(F(f,0));
  21. B.row(f) = V.row(F(f,1));
  22. C.row(f) = V.row(F(f,2));
  23. }
  24. igl::doublearea(A,B,C,A2);
  25. REQUIRE (A2.size() == A1.size());
  26. for(int a = 0;a<A1.size();a++)
  27. {
  28. REQUIRE (A2(a) == Approx (A1(a)).margin(1e-15));
  29. }
  30. };
  31. test_common::run_test_cases(test_common::all_meshes(), test_case);
  32. }
  33. INSTANTIATE_TEST_CASE_P
  34. (
  35. all_meshes,
  36. doublearea,
  37. ::testing::ValuesIn(test_common::all_meshes()),
  38. test_common::string_test_name
  39. );