summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-12-21 14:02:42 -0800
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2017-12-21 14:02:42 -0800
commitdb60275e9c69b1ec768591df876f69e3b445c23a (patch)
tree9c24cdb09ca325b9ed7666e772255138d906fbf9
parentc2250e6e53fcd7eda06250394bbda72c580e0c09 (diff)
downloadqtlocation-mapboxgl-upstream/latlng-wrap-inclusive.tar.gz
[core] Wrapped LatLng should be inclusive of min and max longitude.upstream/latlng-wrap-inclusive
-rw-r--r--include/mbgl/util/geo.hpp10
-rw-r--r--platform/darwin/src/MGLMapSnapshotter.mm1
-rw-r--r--src/mbgl/map/transform.cpp1
-rw-r--r--test/util/geo.test.cpp4
4 files changed, 14 insertions, 2 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp
index 60043ee156..cccbac3afb 100644
--- a/include/mbgl/util/geo.hpp
+++ b/include/mbgl/util/geo.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/math/clamp.hpp>
-#include <mbgl/math/wrap.hpp>
#include <mbgl/util/constants.hpp>
#include <mapbox/geometry/point.hpp>
@@ -53,8 +52,15 @@ public:
LatLng wrapped() const { return { lat, lon, Wrapped }; }
+ double wrap (double value, double min, double max) {
+ const double d = max - min;
+ const double f = std::fmod(value - min, d);
+ const double s = std::fmod(f + d, d);
+ return value >= max && s == 0 ? max : s + min;
+ }
+
void wrap() {
- lon = util::wrap(lon, -util::LONGITUDE_MAX, util::LONGITUDE_MAX);
+ lon = wrap(lon, -util::LONGITUDE_MAX, util::LONGITUDE_MAX);
}
// If the distance from start to end longitudes is between half and full
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm
index 346666cf80..df889ee230 100644
--- a/platform/darwin/src/MGLMapSnapshotter.mm
+++ b/platform/darwin/src/MGLMapSnapshotter.mm
@@ -9,6 +9,7 @@
#import <mbgl/util/default_thread_pool.hpp>
#import <mbgl/util/string.hpp>
#import <mbgl/util/shared_thread_pool.hpp>
+#import <mbgl/math/wrap.hpp>
#import "MGLOfflineStorage_Private.h"
#import "MGLGeometry_Private.h"
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 105adf0400..78693eabac 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -8,6 +8,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/math/clamp.hpp>
+#include <mbgl/math/wrap.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
diff --git a/test/util/geo.test.cpp b/test/util/geo.test.cpp
index 6832ba3486..af8e815670 100644
--- a/test/util/geo.test.cpp
+++ b/test/util/geo.test.cpp
@@ -170,6 +170,10 @@ TEST(LatLng, Boundaries) {
coordinate.wrap();
ASSERT_DOUBLE_EQ(179.90000000000001, coordinate.longitude()); // 1E-14
+ coordinate = LatLng(0, 180);
+ coordinate.wrap();
+ ASSERT_DOUBLE_EQ(180.0, coordinate.longitude());
+
coordinate = LatLng(0, 180.9);
coordinate.wrap();
ASSERT_DOUBLE_EQ(-179.09999999999999, coordinate.longitude());