-
Notifications
You must be signed in to change notification settings - Fork 14
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
HansOersted
wants to merge
2
commits into
autowarefoundation:main
Choose a base branch
from
HansOersted:test_projector_change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 " | ||
<< "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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.