diff options
Diffstat (limited to 'include/mbgl/util/geo.hpp')
-rw-r--r-- | include/mbgl/util/geo.hpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 56d575ceaa..9e2d7a2bb1 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -25,19 +25,17 @@ public: LatLng wrapped() const { return { latitude, longitude, Wrapped }; } void wrap() { - if (longitude < -util::LONGITUDE_MAX) longitude = std::fmod(longitude, util::LONGITUDE_MAX * 2); - if (longitude > util::LONGITUDE_MAX) longitude = -util::LONGITUDE_MAX + std::fmod(longitude, util::LONGITUDE_MAX); - } - - /** If a path crossing the antemeridian would be shorter, extend the final - coordinate so that interpolating between the two endpoints will cross it. */ - void unwrapForShortestPath(const LatLng& start) { - if (std::abs(start.longitude) + std::abs(longitude) > util::LONGITUDE_MAX) { - if (start.longitude > 0 && longitude < 0) { - longitude += util::DEGREES_MAX; - } else if (start.longitude < 0 && longitude > 0) { - longitude -= util::DEGREES_MAX; - } + if (longitude < -util::LONGITUDE_MAX) longitude = util::LONGITUDE_MAX + std::fmod(longitude + util::LONGITUDE_MAX, util::DEGREES_MAX); + if (longitude > util::LONGITUDE_MAX) longitude = -util::LONGITUDE_MAX + std::fmod(longitude + util::LONGITUDE_MAX, util::DEGREES_MAX); + } + + // If we pass through the antimeridian, we update the start coordinate to make sure + // the end coordinate is always wrapped. + void unwrapForShortestPath(const LatLng& end) { + if (end.longitude < -util::LONGITUDE_MAX) { + longitude += util::DEGREES_MAX; + } else if (end.longitude > util::LONGITUDE_MAX) { + longitude -= util::DEGREES_MAX; } } |