[core] Improve LatLngBounds API

* Use "named constructors": empty, world, hull
* Make the two-argument constructor lenient (i.e., it is a hull operation)
* Add various accessors
* Enforce a single empty representation
This commit is contained in:
John Firebaugh
2016-02-02 15:04:21 -08:00
parent 032c8fba3c
commit 37c27f3a8f
10 changed files with 190 additions and 82 deletions

View File

@@ -142,18 +142,17 @@ TEST(Transform, PerspectiveProjection) {
TEST(Transform, ConstrainHeightOnly) {
MockView view;
LatLng loc;
LatLngBounds bounds;
Transform transform(view, ConstrainMode::HeightOnly);
transform.resize({{ 1000, 1000 }});
transform.setScale(1024);
transform.setLatLng(bounds.sw);
transform.setLatLng(LatLngBounds::world().southwest());
loc = transform.getState().pointToLatLng({ 500, 500 });
ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001);
ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001);
transform.setLatLng(bounds.ne);
transform.setLatLng(LatLngBounds::world().northeast());
loc = transform.getState().pointToLatLng({ 500, 500 });
ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001);
ASSERT_NEAR(180, std::abs(loc.longitude), 0.0001);
@@ -162,18 +161,17 @@ TEST(Transform, ConstrainHeightOnly) {
TEST(Transform, ConstrainWidthAndHeight) {
MockView view;
LatLng loc;
LatLngBounds bounds;
Transform transform(view, ConstrainMode::WidthAndHeight);
transform.resize({{ 1000, 1000 }});
transform.setScale(1024);
transform.setLatLng(bounds.sw);
transform.setLatLng(LatLngBounds::world().southwest());
loc = transform.getState().pointToLatLng({ 500, 500 });
ASSERT_NEAR(-85.021422866378714, loc.latitude, 0.0001);
ASSERT_NEAR(-179.65667724609375, loc.longitude, 0.0001);
transform.setLatLng(bounds.ne);
transform.setLatLng(LatLngBounds::world().northeast());
loc = transform.getState().pointToLatLng({ 500, 500 });
ASSERT_NEAR(85.021422866378742, loc.latitude, 0.0001);
ASSERT_NEAR(179.65667724609358, std::abs(loc.longitude), 0.0001);