37 #define BOOST_TEST_MODULE COAL_NORMAL_AND_NEAREST_POINTS
38 #include <boost/test/included/unit_test.hpp>
74 template <
typename ShapeType1,
typename ShapeType2>
76 const ShapeType1& o1,
const ShapeType2& o2,
82 #ifndef NDEBUG // if debug mode
90 std::vector<Transform3s> transforms;
112 for (
size_t i = 0; i < n; i++) {
126 BOOST_CHECK(dist <= 0.);
127 BOOST_CHECK_CLOSE(dist, distres.
min_distance, dummy_precision);
155 size_t new_col =
collide(&o1, new_tf1, &o2,
tf2, colreq, new_colres);
157 distance(&o1, new_tf1, &o2,
tf2, distreq, new_distres);
158 BOOST_CHECK(new_dist > 0);
159 BOOST_CHECK(!new_col);
165 BOOST_CHECK_CLOSE(new_dist, (new_cp1 - new_cp2).norm(), epa_tolerance);
169 Vec3s new_separation_vector = new_dist * new_distres.
normal;
175 (new_cp2 - new_cp1).normalized(), gjk_tolerance);
178 BOOST_CHECK(dist >= 0.);
179 BOOST_CHECK_CLOSE(distres.
min_distance, dist, dummy_precision);
184 BOOST_CHECK_CLOSE(dist, (cp1 - cp2).norm(), gjk_tolerance);
208 collide(&o1, new_tf1, &o2,
tf2, colreq, new_colres);
210 distance(&o1, new_tf1, &o2,
tf2, distreq, new_distres);
211 BOOST_CHECK(new_dist < dist);
225 -(new_cp2 - new_cp1).norm(), epa_tolerance);
229 Vec3s new_separation_vector =
236 contact.
normal, -(new_cp2 - new_cp1).normalized(), epa_tolerance);
243 template <
int VecSize>
246 typedef Eigen::Matrix<CoalScalar, VecSize, 1> VecType;
248 VecType
v = VecType::Random() * (max - min) * 0.5 +
249 VecType::Ones() * (max + min) * 0.5;
257 return r * (max - min) * 0.5 + (max + min) * 0.5;
261 for (
size_t i = 0; i < 10; ++i) {
262 Vec2d radii = generateRandomVector<2>(0.05, 1.0);
263 shared_ptr<Sphere> o1(
new Sphere(radii(0)));
264 shared_ptr<Sphere> o2(
new Sphere(radii(1)));
271 for (
size_t i = 0; i < 10; ++i) {
272 Vec2d radii = generateRandomVector<2>(0.05, 1.0);
274 shared_ptr<Sphere> o1(
new Sphere(radii(0)));
275 shared_ptr<Capsule> o2(
new Capsule(radii(1), h));
283 for (
size_t i = 0; i < 10; ++i) {
284 shared_ptr<Box> o1(
new Box(generateRandomVector<3>(0.05, 1.0)));
293 for (
size_t i = 0; i < 10; ++i) {
295 Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
299 Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
308 gjk_tolerance, epa_max_iterations,
315 Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
318 shared_ptr<Box> o2(
new Box(generateRandomVector<3>(0.05, 1.0)));
325 for (
size_t i = 0; i < 10; ++i) {
327 Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
330 shared_ptr<Ellipsoid> o2(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
348 for (
size_t i = 0; i < 10; ++i) {
349 shared_ptr<Ellipsoid> o1(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
350 shared_ptr<Ellipsoid> o2(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
358 size_t epa_max_iterations = 250;
366 gjk_tolerance, epa_max_iterations,
372 for (
size_t i = 0; i < 10; ++i) {
373 shared_ptr<Box> o1(
new Box(generateRandomVector<3>(0.05, 1.0)));
375 Vec3s n = Vec3s::Random();
377 shared_ptr<Plane> o2(
new Plane(n, offset));
385 for (
size_t i = 0; i < 10; ++i) {
386 shared_ptr<Box> o1(
new Box(generateRandomVector<3>(0.05, 1.0)));
388 Vec3s n = Vec3s::Random();
390 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
398 for (
size_t i = 0; i < 10; ++i) {
401 shared_ptr<Capsule> o1(
new Capsule(
r, h));
403 Vec3s n = Vec3s::Random();
405 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
413 for (
size_t i = 0; i < 10; ++i) {
416 Vec3s n = Vec3s::Random();
418 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
426 for (
size_t i = 0; i < 10; ++i) {
429 Vec3s n = Vec3s::Random();
431 shared_ptr<Plane> o2(
new Plane(n, offset));
439 for (
size_t i = 0; i < 10; ++i) {
441 Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
445 Vec3s n = Vec3s::Random();
447 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
455 for (
size_t i = 0; i < 10; ++i) {
456 Vec2d r = generateRandomVector<2>(0.05, 1.0);
457 Vec2d h = generateRandomVector<2>(0.15, 1.0);
458 shared_ptr<Cone> o1(
new Cone(
r(0), h(0)));
459 shared_ptr<Cylinder> o2(
new Cylinder(
r(1), h(1)));
463 size_t epa_max_iterations = 250;
466 gjk_tolerance, epa_max_iterations,
469 gjk_tolerance, epa_max_iterations,
475 for (
size_t i = 0; i < 10; ++i) {
476 shared_ptr<Ellipsoid> o1(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
477 Vec2d r = generateRandomVector<2>(0.05, 1.0);
478 Vec2d h = generateRandomVector<2>(0.15, 1.0);
479 shared_ptr<Cylinder> o2(
new Cylinder(
r(1), h(1)));
483 size_t epa_max_iterations = 250;
486 gjk_tolerance, epa_max_iterations,
489 gjk_tolerance, epa_max_iterations,
495 for (
size_t i = 0; i < 10; ++i) {
498 shared_ptr<Cone> o1(
new Cone(
r, h));
500 Vec3s n = Vec3s::Random();
502 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
510 for (
size_t i = 0; i < 10; ++i) {
513 shared_ptr<Cylinder> o1(
new Cylinder(
r, h));
515 Vec3s n = Vec3s::Random();
517 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
525 for (
size_t i = 0; i < 10; ++i) {
528 shared_ptr<Cone> o1(
new Cone(
r, h));
530 Vec3s n = Vec3s::Random();
532 shared_ptr<Plane> o2(
new Plane(n, offset));
540 for (
size_t i = 0; i < 10; ++i) {
543 shared_ptr<Cylinder> o1(
new Cylinder(
r, h));
545 Vec3s n = Vec3s::Random();
547 shared_ptr<Plane> o2(
new Plane(n, offset));
555 for (
size_t i = 0; i < 10; ++i) {
558 shared_ptr<Capsule> o1(
new Capsule(
r, h));
560 Vec3s n = Vec3s::Random();
562 shared_ptr<Plane> o2(
new Plane(n, offset));
570 for (
size_t i = 0; i < 10; ++i) {
571 Vec2d r = generateRandomVector<2>(0.05, 1.0);
572 Vec2d h = generateRandomVector<2>(0.15, 1.0);
573 shared_ptr<Capsule> o1(
new Capsule(
r(0), h(0)));
574 shared_ptr<Capsule> o2(
new Capsule(
r(1), h(1)));
582 for (
size_t i = 0; i < 10; ++i) {
583 Vec2d r = generateRandomVector<2>(0.05, 1.0);
585 shared_ptr<Sphere> o1(
new Sphere(
r(0)));
586 shared_ptr<Cylinder> o2(
new Cylinder(
r(1), h));
594 for (
size_t i = 0; i < 10; ++i) {
596 Vec3s n = Vec3s::Random();
598 shared_ptr<Ellipsoid> o1(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
599 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));
607 for (
size_t i = 0; i < 10; ++i) {
609 Vec3s n = Vec3s::Random();
611 shared_ptr<Ellipsoid> o1(
new Ellipsoid(generateRandomVector<3>(0.05, 1.0)));
612 shared_ptr<Plane> o2(
new Plane(n, offset));
622 #ifndef NDEBUG // if debug mode
628 std::vector<Transform3s> transforms;
640 for (
size_t i = 0; i < n; i++) {
648 BOOST_CHECK(dist <= 0.);
670 BOOST_CHECK(dist >= 0.);
690 Vec3s n = Vec3s::Random();
692 shared_ptr<Halfspace> o2(
new Halfspace(n, offset));