Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add World::hasSkeleton() #1050

Merged
merged 3 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Added FOV API to OSG viewer: [#1048](https://github.com/dartsim/dart/pull/1048)

* Simulation

* Added World::hasSkeleton(): [#1050](https://github.com/dartsim/dart/pull/1050)

### [DART 6.4.0 (2018-03-26)](https://github.com/dartsim/dart/milestone/39?closed=1)

* Common
Expand Down
7 changes: 7 additions & 0 deletions dart/simulation/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ std::set<dynamics::SkeletonPtr> World::removeAllSkeletons()
return ptrs;
}

//==============================================================================
bool World::hasSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const
{
return std::find(mSkeletons.begin(), mSkeletons.end(), skeleton)
!= mSkeletons.end();
}

//==============================================================================
int World::getIndex(int _index) const
{
Expand Down
3 changes: 3 additions & 0 deletions dart/simulation/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class World : public virtual common::Subject
/// pointers to them, in case you want to recycle them
std::set<dynamics::SkeletonPtr> removeAllSkeletons();

/// Returns wether this World contains a Skeleton.
bool hasSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const;

/// Get the dof index for the indexed skeleton
int getIndex(int _index) const;

Expand Down
9 changes: 9 additions & 0 deletions unittests/comprehensive/test_World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ TEST(World, AddingAndRemovingSkeletons)
for (int i = 0; i < nSteps; ++i)
world->step();

EXPECT_FALSE(world->hasSkeleton(skeleton1));
EXPECT_FALSE(world->hasSkeleton(skeleton2));
EXPECT_FALSE(world->hasSkeleton(skeleton3));
EXPECT_FALSE(world->hasSkeleton(skeleton4));

// Add skeleton1, skeleton2
world->addSkeleton(skeleton1);
EXPECT_TRUE(world->hasSkeleton(skeleton1));
world->addSkeleton(skeleton2);
EXPECT_TRUE(world->hasSkeleton(skeleton2));
EXPECT_TRUE(world->getNumSkeletons() == 2);
for (int i = 0; i < nSteps; ++i)
world->step();
Expand All @@ -119,7 +126,9 @@ TEST(World, AddingAndRemovingSkeletons)

// Add skeleton3, skeleton4
world->addSkeleton(skeleton3);
EXPECT_TRUE(world->hasSkeleton(skeleton3));
world->addSkeleton(skeleton4);
EXPECT_TRUE(world->hasSkeleton(skeleton4));
EXPECT_TRUE(world->getNumSkeletons() == 3);
for (int i = 0; i < nSteps; ++i)
world->step();
Expand Down