Skip to content

Commit

Permalink
Add default constructor to RayHit (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored May 30, 2019
1 parent 2e0a11f commit ccfc73d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### [DART 6.9.1 (2019-XX-XX)](https://github.com/dartsim/dart/milestone/59?closed=1)

* Collision

* Added default constructor to RayHit: [#1345](https://github.com/dartsim/dart/pull/1345)

* dartpy

* Updated build scripts for uploading dartpy to PyPI: [#1341](https://github.com/dartsim/dart/pull/1341)
Expand Down
12 changes: 11 additions & 1 deletion dart/collision/RaycastResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ namespace dart {
namespace collision {

//==============================================================================
RaycastResult::RaycastResult()
RayHit::RayHit()
: mCollisionObject(nullptr),
mPoint(Eigen::Vector3d::Zero()),
mFraction(0.0),
mNormal(Eigen::Vector3d::Zero())
{
// Do nothing
}

//==============================================================================
RaycastResult::RaycastResult() : mRayHits(false)
{
// Do nothing
}
Expand Down
17 changes: 9 additions & 8 deletions dart/collision/RaycastResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,31 @@ struct RayHit
/// The collision object the ray hit
const CollisionObject* mCollisionObject;

/// The normal at the hit point in the world coordinates
Eigen::Vector3d mNormal;

/// The hit point in the world coordinates
Eigen::Vector3d mPoint;

/// The fraction from "from" point to "to" point
double mFraction;

/// The normal at the hit point in the world coordinates
Eigen::Vector3d mNormal;

/// Constructor
RayHit();
};

struct RaycastResult
{
/// Constructor
RaycastResult();

/// Clear the result
void clear();

/// Returns true if there is a hit
bool hasHit() const;

bool mHasHit;

std::vector<RayHit> mRayHits;

/// Constructor
RaycastResult();
};

} // namespace collision
Expand Down
21 changes: 19 additions & 2 deletions unittests/comprehensive/test_Raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@

using namespace dart;

//==============================================================================
TEST(Raycast, RayHitDefaultConstructor)
{
RayHit rayHit;
EXPECT_TRUE(equals(rayHit.mNormal, Eigen::Vector3d::Zero().eval()));
EXPECT_TRUE(equals(rayHit.mPoint, Eigen::Vector3d::Zero().eval()));
EXPECT_DOUBLE_EQ(rayHit.mFraction, 0);
}

//==============================================================================
TEST(Raycast, RaycastResultDefaultConstructor)
{
RaycastResult result;
EXPECT_FALSE(result.hasHit());
EXPECT_TRUE(result.mRayHits.empty());
}

//==============================================================================
void testBasicInterface(const std::shared_ptr<CollisionDetector>& cd)
{
Expand Down Expand Up @@ -115,7 +132,7 @@ void testBasicInterface(const std::shared_ptr<CollisionDetector>& cd)
}

//==============================================================================
TEST(Distance, testBasicInterface)
TEST(Raycast, testBasicInterface)
{
auto fcl = FCLCollisionDetector::create();
testBasicInterface(fcl);
Expand Down Expand Up @@ -199,7 +216,7 @@ void testOptions(const std::shared_ptr<CollisionDetector>& cd)
}

//==============================================================================
TEST(Distance, testOptions)
TEST(Raycast, testOptions)
{
auto fcl = FCLCollisionDetector::create();
testOptions(fcl);
Expand Down

0 comments on commit ccfc73d

Please sign in to comment.