MCPcopy Create free account
hub / github.com/dartsim/dart / testBoxBox

Function testBoxBox

tests/integration/test_Collision.cpp:566–620  ·  view source on GitHub ↗

==============================================================================

Source from the content-addressed store, hash-verified

564
565//==============================================================================
566void testBoxBox(
567 const std::shared_ptr<CollisionDetector>& cd, double tol = 1e-12)
568{
569 auto simpleFrame1 = SimpleFrame::createShared(Frame::World());
570 auto simpleFrame2 = SimpleFrame::createShared(Frame::World());
571
572 ShapePtr shape1(new BoxShape(Eigen::Vector3d(1.0, 1.0, 1.0)));
573 ShapePtr shape2(new BoxShape(Eigen::Vector3d(0.5, 0.5, 0.5)));
574 simpleFrame1->setShape(shape1);
575 simpleFrame2->setShape(shape2);
576
577 Eigen::Vector3d pos1 = Eigen::Vector3d(0.0, 0.0, -0.5);
578 Eigen::Vector3d pos2 = Eigen::Vector3d(0.0, 0.5, 0.25);
579 simpleFrame1->setTranslation(pos1);
580 simpleFrame2->setTranslation(pos2);
581
582 auto group1 = cd->createCollisionGroup(simpleFrame1.get());
583 auto group2 = cd->createCollisionGroup(simpleFrame2.get());
584 auto groupAll = cd->createCollisionGroup(group1.get(), group2.get());
585
586 EXPECT_EQ(group1->getNumShapeFrames(), 1u);
587 EXPECT_EQ(group2->getNumShapeFrames(), 1u);
588 EXPECT_EQ(
589 groupAll->getNumShapeFrames(),
590 group1->getNumShapeFrames() + group2->getNumShapeFrames());
591
592 collision::CollisionOption option;
593 collision::CollisionResult result;
594
595 result.clear();
596 EXPECT_TRUE(group1->collide(group2.get(), option, &result));
597
598 result.clear();
599 EXPECT_TRUE(groupAll->collide(option, &result));
600
601 Eigen::Vector3d min = Eigen::Vector3d(-0.25, 0.25, 0.0);
602 Eigen::Vector3d max = Eigen::Vector3d(0.25, 0.5, 0.0);
603
604 const auto numContacts = result.getNumContacts();
605
606 const auto checkNumContacts = (numContacts <= 4u);
607 EXPECT_TRUE(checkNumContacts);
608 if (!checkNumContacts)
609 std::cout << "# of contants: " << numContacts << "\n";
610
611 for (const auto& contact : result.getContacts()) {
612 const auto& point = contact.point;
613
614 const auto result = checkBoundingBox(min, max, point, tol);
615 EXPECT_TRUE(result);
616
617 if (!result)
618 std::cout << "point: " << point.transpose() << "\n";
619 }
620}
621
622//==============================================================================
623TEST_F(Collision, BoxBox)

Callers 1

TEST_FFunction · 0.85

Calls 10

checkBoundingBoxFunction · 0.85
setShapeMethod · 0.80
setTranslationMethod · 0.80
getNumShapeFramesMethod · 0.80
WorldClass · 0.50
createCollisionGroupMethod · 0.45
getMethod · 0.45
clearMethod · 0.45
collideMethod · 0.45
getNumContactsMethod · 0.45

Tested by

no test coverage detected