39 #include <gtest/gtest.h>
40 #include <Eigen/Dense>
63 return Vector3d{vector.v[0], vector.v[1], vector.v[2]};
69 const ccd_vec3_t& tested,
72 return ::testing::AssertionFailure() <<
"Invalid tolerance: "
77 Vector3d error = (expected - ccd).cwiseAbs();
79 for (
int i = 0; i < 3; ++i) {
81 return ::testing::AssertionFailure()
82 <<
"Values at index " << i
83 <<
" exceed tolerance; " << expected(i) <<
" vs "
84 << ccd(i) <<
", diff = " << error(i)
85 <<
", tolerance = " <<
tolerance <<
"\nexpected = "
86 << expected.transpose() <<
"\ntested = "
87 << ccd.transpose() <<
"\n|delta| = "
91 return ::testing::AssertionSuccess();
123 const ccd_real_t almost_eps = eps * 0.75;
124 const ccd_real_t extra_eps = eps * 1.5;
142 const double scale = 100;
143 p << scale, scale, scale;
160 p << 0.01, 0.01, 0.01;
251 const ccd_real_t theta_e = asin(eps);
258 const ccd_real_t colinear_theta = tan(theta_e * 0.75);
259 Vector3d c_prime = b + (b.norm() * colinear_theta) * v_hat;
265 const ccd_real_t good_tan = tan(theta_e * 1.5);
266 c_prime = b + (b.norm() * good_tan) * v_hat;
281 for (
int i = 0; i < 3; ++i) {
301 const char* message) {
339 return a * s + b * (1 - s);
348 const Vector3d t1_[3] = {{0, 0.25, 0.25}, {1, 0.25, 0.25}, {0.5, 0.8, 1.0}};
391 EvaluateExtractClosestPoint(&simplex_, v0_, t1_[0], &closest,
392 "ExtractFrom1Simplex");
409 const double s = 1 / 3.0;
410 ASSERT_TRUE(s >= 0 && s <= 1);
414 const Vector3d p1_expected = lerp(t1_[0], t1_[1], s);
418 &simplex_.ps[0], &simplex_.ps[1],
nullptr,
nullptr, &closest));
422 &simplex_.ps[0], &simplex_.ps[1], &p0,
nullptr, &closest));
427 &simplex_.ps[0], &simplex_.ps[1],
nullptr, &p1, &closest));
434 &simplex_.ps[0], &simplex_.ps[1], &p0, &p1, &closest));
448 const double s = 1 / 3.0;
449 ASSERT_TRUE(s >= 0 && s <= 1);
453 const Vector3d p1_expected = lerp(t1_[0], t1_[1], s);
455 EvaluateExtractClosestPoint(&simplex_, p0_expected, p1_expected, &closest,
456 "ExtractFrom2Simplex");
470 simplex_.ps[1].v.v[0] += eps;
471 simplex_.ps[1].v1.v[0] += eps;
473 ASSERT_TRUE(
are_same(v0_, simplex_.ps[0].v1, kTolerance));
479 EvaluateExtractClosestPoint(&simplex_, v0_, t1_[0], &closest,
480 "ExtractFrom2SimplexDegenerate");
488 const double alpha = 0.25;
489 const double beta = 0.33;
490 ASSERT_TRUE(alpha >= 0 && alpha <= 1 && beta >= 0 && beta <= 1 &&
500 return a * s1 + b * s2 + c * (1 - s1 - s2);
503 ccd_vec3_t closest =
eigen_to_ccd(interpolate(m0, m1, m2, alpha, beta));
505 const Vector3d p1_expected = interpolate(t1_[0], t1_[1], t1_[2], alpha, beta);
507 EvaluateExtractClosestPoint(&simplex_, p0_expected, p1_expected, &closest,
508 "ExtractFrom3Simplex");
523 for (
auto i : {1, 2}) {
525 simplex_.ps[i].v.v[0] += eps;
526 simplex_.ps[i].v1.v[0] += eps;
529 ASSERT_TRUE(
are_same(v0_, simplex_.ps[0].v1, kTolerance));
535 EvaluateExtractClosestPoint(&simplex_, v0_, t1_[0], &closest,
536 "ExtractFrom3SimplexDegenerateCoincident");
548 const double s = 1 / 3.0;
549 ASSERT_TRUE(s >= 0 && s <= 1);
553 const Vector3d p1_expected = lerp(t1_[0], t1_[1], s);
562 auto linearly_combine = [](
const ccd_vec3_t& a,
const ccd_vec3_t& b,
569 linearly_combine(simplex_.ps[0].v, simplex_.ps[1].v, &simplex_.ps[2].v);
570 linearly_combine(simplex_.ps[0].v1, simplex_.ps[1].v1, &simplex_.ps[2].v1);
571 linearly_combine(simplex_.ps[0].v2, simplex_.ps[1].v2, &simplex_.ps[2].v2);
573 EvaluateExtractClosestPoint(&simplex_, p0_expected, p1_expected, &closest,
574 "ExtractFrom3SimplexDegenerateColinear");
581 int main(
int argc,
char* argv[]) {
582 ::testing::InitGoogleTest(&argc, argv);
583 return RUN_ALL_TESTS();