summaryrefslogtreecommitdiff
path: root/src/mbgl/util/geo.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-05-10 11:47:54 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-05-10 14:50:56 +0200
commitec70125e41e4e9db5f1d0941c0129d80f5792896 (patch)
tree639654a3dfda72cf0c1c1a2a0a353fe0b484e45e /src/mbgl/util/geo.cpp
parentbdcbceff8002d6a0ec2ce6c1d2518b03c007ddf6 (diff)
downloadqtlocation-mapboxgl-ec70125e41e4e9db5f1d0941c0129d80f5792896.tar.gz
[core] move TileData and dependents to new *TileID classes
Diffstat (limited to 'src/mbgl/util/geo.cpp')
-rw-r--r--src/mbgl/util/geo.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/mbgl/util/geo.cpp b/src/mbgl/util/geo.cpp
index eb697f0b02..dd40af882b 100644
--- a/src/mbgl/util/geo.cpp
+++ b/src/mbgl/util/geo.cpp
@@ -1,20 +1,35 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/constants.hpp>
-#include <mbgl/map/tile_id.hpp>
+#include <mbgl/tile/tile_id.hpp>
#include <cmath>
namespace mbgl {
-LatLng::LatLng(const TileID& id) {
- longitude = id.x / std::pow(2.0, id.z) * util::DEGREES_MAX - util::LONGITUDE_MAX;
- const double n = M_PI - 2.0 * M_PI * id.y / std::pow(2.0, id.z);
- latitude = util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
+namespace {
+
+inline double lat(const uint8_t z, const int64_t y) {
+ const double n = M_PI - 2.0 * M_PI * y / std::pow(2.0, z);
+ return util::RAD2DEG * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
+}
+
+inline double lon(const uint8_t z, const int64_t x) {
+ return x / std::pow(2.0, z) * util::DEGREES_MAX - util::LONGITUDE_MAX;
+}
+
+} // end namespace
+
+LatLng::LatLng(const CanonicalTileID& id) : latitude(lat(id.z, id.y)), longitude(lon(id.z, id.x)) {
+}
+
+LatLng::LatLng(const UnwrappedTileID& id)
+ : latitude(lat(id.canonical.z, id.canonical.y)),
+ longitude(lon(id.canonical.z, id.canonical.x) + id.wrap * util::DEGREES_MAX) {
}
-LatLngBounds::LatLngBounds(const TileID& id)
- : sw(TileID{ id.z, id.x, id.y + 1, id.sourceZ }),
- ne(TileID{ id.z, id.x + 1, id.y, id.sourceZ }) {
+LatLngBounds::LatLngBounds(const CanonicalTileID& id)
+ : sw({ lat(id.z, id.y + 1), lon(id.z, id.x) }),
+ ne({ lat(id.z, id.y), lon(id.z, id.x + 1) }) {
}
ScreenCoordinate EdgeInsets::getCenter(uint16_t width, uint16_t height) const {