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

BugFix: Van der Corput - consider span for resolution check #552

Merged
merged 4 commits into from
Oct 8, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Cleaned up doxygen errors: [#357](https://github.com/personalrobotics/aikido/pull/357)
* Fixed bug in compiling with Boost 1.58 on Kinetic + Xenial: [#490](https://github.com/personalrobotics/aikido/pull/490)
* Fixed bug in Interpolated::addWaypoint(): [#483](https://github.com/personalrobotics/aikido/pull/483)
* Fixed bug in VanDerCorput sequence generator to handle non-unit span: [#552](https://github.com/personalrobotics/aikido/pull/552)

* Distance

Expand Down
9 changes: 5 additions & 4 deletions src/common/VanDerCorput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ pair<double, double> VanDerCorput::operator[](int n) const
if (n == 0)
{
val_res.first = 0.0;
val_res.second = mSpan;
val_res.second = 1.0;
}
else if (n == 1)
{
val_res.first = 1.0;
val_res.second = mSpan;
val_res.second = 1.0;
}
else
{
Expand All @@ -60,12 +60,12 @@ pair<double, double> VanDerCorput::operator[](int n) const
else if (mIncludeStartpoint && n == 0)
{
val_res.first = 0.0;
val_res.second = mSpan;
val_res.second = 1.0;
}
else if (mIncludeEndpoint && n == 0)
{
val_res.first = 1.0;
val_res.second = mSpan;
val_res.second = 1.0;
}
else
{
Expand All @@ -80,6 +80,7 @@ pair<double, double> VanDerCorput::operator[](int n) const
}

val_res.first *= mSpan;
val_res.second *= mSpan;
return val_res;
}

Expand Down
34 changes: 34 additions & 0 deletions tests/common/test_VanDerCorput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,37 @@ TEST(VanDerCorput, IterationEndsWhenMinimumResolutionReached)
EXPECT_EQ(7, iterations);
EXPECT_EQ(7, vdc_0_125.getLength());
}

TEST(VanDerCorput, ScaleAndIterateProperlyOverSpanWithResolution)
{
// Check that with a non-unit span, iteration stops appropriately.
VanDerCorput vdc{2, false, false, 0.25};
int iterations = 0;
EXPECT_NO_THROW({
for (VanDerCorput::const_iterator itr = vdc.begin(); itr != vdc.end();
++itr)
{
++iterations;
}
});
EXPECT_EQ(7, iterations);
EXPECT_EQ(7, vdc.getLength());

// Check that with a non-unit span, the vdc values are correct.
EXPECT_DOUBLE_EQ(1.00, vdc[0].first);
EXPECT_DOUBLE_EQ(0.50, vdc[1].first);
EXPECT_DOUBLE_EQ(1.50, vdc[2].first);
EXPECT_DOUBLE_EQ(0.25, vdc[3].first);
EXPECT_DOUBLE_EQ(1.25, vdc[4].first);
brianhou marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_DOUBLE_EQ(0.75, vdc[5].first);
EXPECT_DOUBLE_EQ(1.75, vdc[6].first);

// Check that with a non-unit span, the resolution is computed correctly.
EXPECT_DOUBLE_EQ(1.00, vdc[0].second);
EXPECT_DOUBLE_EQ(1.00, vdc[1].second);
EXPECT_DOUBLE_EQ(0.50, vdc[2].second);
EXPECT_DOUBLE_EQ(0.50, vdc[3].second);
EXPECT_DOUBLE_EQ(0.50, vdc[4].second);
EXPECT_DOUBLE_EQ(0.50, vdc[5].second);
EXPECT_DOUBLE_EQ(0.25, vdc[6].second);
}