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

feat: add test with different elevations #35

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
64 changes: 26 additions & 38 deletions autoware_lanelet2_extension/test/src/test_projector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,40 @@ class TestSuite : public ::testing::Test // NOLINT for gtest
TEST(TestSuite, ForwardMGRSProjection) // NOLINT for gtest
{
lanelet::projection::MGRSProjector projector;
// lat/lon in Tokyo
lanelet::GPSPoint gps_point;
gps_point.lat = 35.652832;
gps_point.lon = 139.839478;
gps_point.ele = 12.3456789;
lanelet::BasicPoint3d mgrs_point = projector.forward(gps_point);

// projected z value should not change
ASSERT_DOUBLE_EQ(mgrs_point.z(), gps_point.ele)
<< "Forward projected z value should be " << gps_point.ele;

// https://www.movable-type.co.uk/scripts/latlong-utm-mgrs.html
// round the projected value to mm since the above reference only gives value
// in mm precision
ASSERT_EQ(projector.getProjectedMGRSGrid(), "54SUE") << "Projected grid should be "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is supposed to compare the return value of getProjectedMGRSGrid, which seems to be lost with the fixes in this PR.

<< "54SUE";
double rounded_x_mm = round(mgrs_point.x() * 1000) / 1000.0;
ASSERT_DOUBLE_EQ(rounded_x_mm, 94946.081) << "Forward projected x value should be " << 94946.081;
double rounded_y_mm = round(mgrs_point.y() * 1000) / 1000.0;
ASSERT_DOUBLE_EQ(rounded_y_mm, 46063.748) << "Forward projected y value should be " << 46063.748;
// different elevation values
std::vector<double> elevation_values = {
0.0, -50.0, 1000.0}; // sea level, below sea level, very high
for (const double ele : elevation_values) {
lanelet::GPSPoint gps_point;
gps_point.lat = 35.652832;
gps_point.lon = 139.839478;
gps_point.ele = ele;

lanelet::BasicPoint3d mgrs_point = projector.forward(gps_point);

ASSERT_DOUBLE_EQ(mgrs_point.z(), gps_point.ele)
<< "Forward projected z value should be " << gps_point.ele << " for elevation " << ele;
}
}

TEST(TestSuite, ReverseMGRSProjection) // NOLINT for gtest
{
lanelet::projection::MGRSProjector projector;
lanelet::BasicPoint3d mgrs_point;
mgrs_point.x() = 94946.0;
mgrs_point.y() = 46063.0;
mgrs_point.z() = 12.3456789;
std::vector<double> elevation_values = {
0.0, -50.0, 1000.0}; // sea level, below sea level, very high

projector.setMGRSCode("54SUE");
lanelet::GPSPoint gps_point = projector.reverse(mgrs_point);
for (const double ele : elevation_values) {
lanelet::BasicPoint3d mgrs_point;
mgrs_point.x() = 94946.0;
mgrs_point.y() = 46063.0;
mgrs_point.z() = ele;

// projected z value should not change
ASSERT_DOUBLE_EQ(gps_point.ele, mgrs_point.z())
<< "Reverse projected z value should be " << mgrs_point.z();
projector.setMGRSCode("54SUE");
lanelet::GPSPoint gps_point = projector.reverse(mgrs_point);

// https://www.movable-type.co.uk/scripts/latlong-utm-mgrs.html
// round the projected value since the above reference only gives value up to
// precision of 1e-8
double rounded_lat = round(gps_point.lat * 1e8) / 1e8;
ASSERT_DOUBLE_EQ(rounded_lat, 35.65282525)
<< "Reverse projected latitude value should be " << 35.65282525;
double rounded_lon = round(gps_point.lon * 1e8) / 1e8;
ASSERT_DOUBLE_EQ(rounded_lon, 139.83947721)
<< "Reverse projected longitude value should be " << 139.83947721;
Comment on lines -75 to -80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like the latitude and longitude comparisons to remain as they are.

ASSERT_DOUBLE_EQ(gps_point.ele, mgrs_point.z())
<< "Reverse projected z value should be " << mgrs_point.z() << " for elevation " << ele;
}
}

TEST(TestSuite, ForwardTransverseMercatorProjection) // NOLINT for gtest
Expand Down
Loading