Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
add Point <--> LatLng conversion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Aug 27, 2015
1 parent 53c2102 commit d703e58
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/miscellaneous/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,35 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(2, transform.getScale());
ASSERT_DOUBLE_EQ(2, transform.getAngle());
}

TEST(Transform, PerspectiveProjection) {
MockView view;
Transform transform(view);

transform.resize({{ 1000, 1000 }});
transform.setScale(1024);
transform.setPitch(0.9);
transform.setLatLng(LatLng(38, -77));

// expected values are from mapbox-gl-js

LatLng loc = transform.getState().pointToLatLng({ 500, 500 });
ASSERT_NEAR(-77, loc.longitude, 0.0001);
ASSERT_NEAR(38, loc.latitude, 0.0001);

loc = transform.getState().pointToLatLng({ 0, 1000 });
ASSERT_NEAR(-77.59198961199148, loc.longitude, 0.0002);
ASSERT_NEAR(38.74661326302018, loc.latitude, 0.0001);

loc = transform.getState().pointToLatLng({ 1000, 0 });
ASSERT_NEAR(-76.75823239205641, loc.longitude, 0.0001);
ASSERT_NEAR(37.692872969426375, loc.latitude, 0.0001);

vec2<double> point = transform.getState().latLngToPoint({38.74661326302018, -77.59198961199148});
ASSERT_NEAR(point.x, 0, 0.01);
ASSERT_NEAR(point.y, 1000, 0.01);

point = transform.getState().latLngToPoint({37.692872969426375, -76.75823239205641});
ASSERT_NEAR(point.x, 1000, 0.02);
ASSERT_NEAR(point.y, 0, 0.02);
}

0 comments on commit d703e58

Please sign in to comment.