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

Commit

Permalink
[core] Fix MapSnapshotter build failure on Windows
Browse files Browse the repository at this point in the history
MSVC implementation of std::promise is buggy and only works with types
that can be default-constructed. To avoid a compilation failure in the
instantiation of ask() inside MapSnapshotter::getRegion(), which creates
a std::promise<LanLngBounds>, make LatLngBounds' default constructor
public.
  • Loading branch information
anderco committed Nov 13, 2019
1 parent 089ff8e commit 4c1d03c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
Binary file modified benchmark/fixtures/api/cache.db
Binary file not shown.
9 changes: 2 additions & 7 deletions include/mbgl/util/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ class LatLngBounds {
return bounds;
}

/// Returns an infinite bound, a bound for which the constrain method returns its
/// Construct an infinite bound, a bound for which the constrain method returns its
/// input unmodified.
///
/// Note: this is different than LatLngBounds::world() since arbitrary unwrapped
/// coordinates are also inside the bounds.
static LatLngBounds unbounded() {
return {};
}
LatLngBounds() : sw({-90, -180}), ne({90, 180}), bounded(false) {}

// Constructs a LatLngBounds object with the tile's exact boundaries.
LatLngBounds(const CanonicalTileID&);
Expand Down Expand Up @@ -172,9 +170,6 @@ class LatLngBounds {

LatLngBounds(LatLng sw_, LatLng ne_) : sw(sw_), ne(ne_) {}

LatLngBounds()
: sw({-90, -180}), ne({90, 180}), bounded(false) {}

bool containsLatitude(double latitude) const;
bool containsLongitude(double longitude, LatLng::WrapMode wrap) const;

Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void NativeMapView::setLatLngBounds(jni::JNIEnv& env, const jni::Object<mbgl::an
if (jBounds) {
bounds.withLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds));
} else {
bounds.withLatLngBounds(mbgl::LatLngBounds::unbounded());
bounds.withLatLngBounds(mbgl::LatLngBounds());
}
map->setBounds(bounds);
}
Expand Down
11 changes: 5 additions & 6 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
break;
case GLFW_KEY_D: {
static const std::vector<mbgl::LatLngBounds> bounds = {
mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, -170.0 }, mbgl::LatLng { 45.0, 170.0 }), // inside
mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, -200.0 }, mbgl::LatLng { 45.0, -160.0 }), // left IDL
mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, 160.0 }, mbgl::LatLng { 45.0, 200.0 }), // right IDL
mbgl::LatLngBounds::unbounded()
};
mbgl::LatLngBounds::hull(mbgl::LatLng{-45.0, -170.0}, mbgl::LatLng{45.0, 170.0}), // inside
mbgl::LatLngBounds::hull(mbgl::LatLng{-45.0, -200.0}, mbgl::LatLng{45.0, -160.0}), // left IDL
mbgl::LatLngBounds::hull(mbgl::LatLng{-45.0, 160.0}, mbgl::LatLng{45.0, 200.0}), // right IDL
mbgl::LatLngBounds()};
static size_t nextBound = 0u;
static mbgl::AnnotationID boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();

Expand All @@ -301,7 +300,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,

view->map->setBounds(mbgl::BoundOptions().withLatLngBounds(bound));

if (bound == mbgl::LatLngBounds::unbounded()) {
if (bound == mbgl::LatLngBounds()) {
view->map->removeAnnotation(boundAnnotationID);
boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ void Transform::jumpTo(const CameraOptions& camera) {
*/
void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& animation) {
Duration duration = animation.duration.value_or(Duration::zero());
if (state.bounds == LatLngBounds::unbounded() && !isGestureInProgress() && duration != Duration::zero()) {
if (state.bounds == LatLngBounds() && !isGestureInProgress() && duration != Duration::zero()) {
// reuse flyTo, without exaggerated animation, to achieve constant ground speed.
return flyTo(camera, animation, true);
}
const EdgeInsets& padding = camera.padding.value_or(state.edgeInsets);
LatLng startLatLng = getLatLng(LatLng::Unwrapped);
const LatLng& unwrappedLatLng = camera.center.value_or(startLatLng);
const LatLng& latLng = state.bounds != LatLngBounds::unbounded() ? unwrappedLatLng : unwrappedLatLng.wrapped();
const LatLng& latLng = state.bounds != LatLngBounds() ? unwrappedLatLng : unwrappedLatLng.wrapped();
double zoom = camera.zoom.value_or(getZoom());
double bearing = camera.bearing ? -*camera.bearing * util::DEG2RAD : getBearing();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch();
Expand All @@ -102,7 +102,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
return;
}

if (state.bounds == LatLngBounds::unbounded()) {
if (state.bounds == LatLngBounds()) {
if (isGestureInProgress()) {
// If gesture in progress, we transfer the wrap rounds from the end longitude into
// start, so the "scroll effect" of rounding the world is the same while assuring the
Expand Down
6 changes: 1 addition & 5 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
namespace mbgl {

TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewportMode_)
: bounds(LatLngBounds::unbounded())
, constrainMode(constrainMode_)
, viewportMode(viewportMode_)
{
}
: bounds(LatLngBounds()), constrainMode(constrainMode_), viewportMode(viewportMode_) {}

#pragma mark - Matrix

Expand Down
4 changes: 2 additions & 2 deletions test/map/map.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TEST(Map, DefaultBoundOptions) {

EXPECT_EQ(*bounds.minZoom, util::MIN_ZOOM);
EXPECT_EQ(*bounds.maxZoom, util::DEFAULT_MAX_ZOOM);
EXPECT_EQ(*bounds.bounds, LatLngBounds::unbounded());
EXPECT_EQ(*bounds.bounds, LatLngBounds());
}

TEST(Map, MapOptions) {
Expand Down Expand Up @@ -1053,4 +1053,4 @@ TEST(Map, NoHangOnMissingImage) {
test.map.jumpTo(test.map.getStyle().getDefaultCamera());
// The test passes if the following call does not hang.
test.frontend.render(test.map);
}
}
4 changes: 2 additions & 2 deletions test/map/transform.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ TEST(Transform, LatLngBounds) {
transform.jumpTo(CameraOptions().withCenter(LatLng()).withZoom(transform.getState().getMaxZoom()));

// Default bounds.
ASSERT_EQ(transform.getState().getLatLngBounds(), LatLngBounds::unbounded());
ASSERT_EQ(transform.getState().getLatLngBounds(), LatLngBounds());
ASSERT_EQ(transform.getLatLng(), nullIsland);

// Invalid bounds.
try {
transform.setLatLngBounds(LatLngBounds::empty());
ASSERT_TRUE(false) << "Should throw";
} catch (...) {
ASSERT_EQ(transform.getState().getLatLngBounds(), LatLngBounds::unbounded());
ASSERT_EQ(transform.getState().getLatLngBounds(), LatLngBounds());
}

transform.jumpTo(CameraOptions().withCenter(sanFrancisco));
Expand Down

0 comments on commit 4c1d03c

Please sign in to comment.