point_cubic_squared_distance.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <test_common.h>
  2. #include <igl/cycodebase/point_cubic_squared_distance.h>
  3. TEST_CASE("point_cubic_squared_distance: simple2d", "[igl/cycodebase]" )
  4. {
  5. Eigen::MatrixXd C(4,2);
  6. C<<0,0,
  7. 1,2,
  8. 2,-2,
  9. 3,0;
  10. Eigen::MatrixXd Q(3,2);
  11. //[1.5 0;2 0.5;2.5 1]
  12. Q<<
  13. 1.5,0,
  14. 2,0.5,
  15. 2.5,1;
  16. Eigen::VectorXd sqrD,S;
  17. Eigen::MatrixXd K;
  18. igl::cycodebase::point_cubic_squared_distance(Q,C,sqrD,S,K);
  19. REQUIRE(sqrD.size() == 3);
  20. REQUIRE(S.size() == 3);
  21. REQUIRE(K.rows() == 3);
  22. REQUIRE(K.cols() == 2);
  23. // sqrd = [0;0.5;1.25]
  24. REQUIRE(sqrD[0] == Approx(0.0).margin(1e-12));
  25. REQUIRE(sqrD[1] == Approx(0.5).margin(1e-12));
  26. REQUIRE(sqrD[2] == Approx(1.25).margin(1e-12));
  27. // S = [0.5;0.5;1.0]
  28. REQUIRE(S[0] == Approx(0.5).margin(1e-12));
  29. REQUIRE(S[1] == Approx(0.5).margin(1e-12));
  30. REQUIRE(S[2] == Approx(1.0).margin(1e-12));
  31. // [1.5 0;1.5 0;3 0]
  32. REQUIRE(K(0,0) == Approx(1.5).margin(1e-12));
  33. REQUIRE(K(0,1) == Approx(0.0).margin(1e-12));
  34. REQUIRE(K(1,0) == Approx(1.5).margin(1e-12));
  35. REQUIRE(K(1,1) == Approx(0.0).margin(1e-12));
  36. REQUIRE(K(2,0) == Approx(3.0).margin(1e-12));
  37. REQUIRE(K(2,1) == Approx(0.0).margin(1e-12));
  38. }