summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-18 14:21:59 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-10-19 08:11:41 +0300
commitef62b78fce06ad93de87e9a6a6775ae33fff214d (patch)
tree19f655f4389fad40ec520d9f7a8af0d8cb5144ec /src
parent2188d68b6c09dec676c294223aa7d1a4c24c85f0 (diff)
downloadqtlocation-mapboxgl-ef62b78fce06ad93de87e9a6a6775ae33fff214d.tar.gz
[core] TileCoordinate::fromLatLng no longer depens on TransformState
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/tile_coordinate.hpp14
-rw-r--r--src/mbgl/util/tile_cover.cpp11
2 files changed, 13 insertions, 12 deletions
diff --git a/src/mbgl/util/tile_coordinate.hpp b/src/mbgl/util/tile_coordinate.hpp
index 46073c0dc9..bcd1c8444f 100644
--- a/src/mbgl/util/tile_coordinate.hpp
+++ b/src/mbgl/util/tile_coordinate.hpp
@@ -18,23 +18,25 @@ public:
TileCoordinatePoint p;
double z;
- static TileCoordinate fromLatLng(const TransformState& state, double zoom, const LatLng& latLng) {
- const double scale = std::pow(2, zoom - state.getZoom());
- return { Projection::project(latLng, state.getScale()) * scale / double(util::tileSize), zoom };
+ static TileCoordinate fromLatLng(double zoom, const LatLng& latLng) {
+ const double scale = std::pow(2.0, zoom);
+ return { Projection::project(latLng, scale) / double(util::tileSize), zoom };
}
static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& screenCoordinate) {
- return fromLatLng(state, zoom, state.screenCoordinateToLatLng(screenCoordinate));
+ return fromLatLng(zoom, state.screenCoordinateToLatLng(screenCoordinate));
}
TileCoordinate zoomTo(double zoom) const {
- return { p * std::pow(2, zoom - z), zoom };
+ const double scaleDiff = std::pow(2.0, zoom - z);
+ return { p * scaleDiff, zoom };
}
static GeometryCoordinate toGeometryCoordinate(const UnwrappedTileID& tileID, const TileCoordinatePoint& point) {
+ const double scale = std::pow(2.0, tileID.canonical.z);
auto zoomed = TileCoordinate { point, 0 }.zoomTo(tileID.canonical.z);
return {
- int16_t(util::clamp<int64_t>((zoomed.p.x - tileID.canonical.x - tileID.wrap * std::pow(2.0, tileID.canonical.z)) * util::EXTENT,
+ int16_t(util::clamp<int64_t>((zoomed.p.x - tileID.canonical.x - tileID.wrap * scale) * util::EXTENT,
std::numeric_limits<int16_t>::min(),
std::numeric_limits<int16_t>::max())),
int16_t(util::clamp<int64_t>((zoomed.p.y - tileID.canonical.y) * util::EXTENT,
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index 5487fb269c..c6bf7d362a 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -147,13 +147,12 @@ std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, int32_t z) {
{ std::max(bounds_.south(), -util::LATITUDE_MAX), bounds_.west() },
{ std::min(bounds_.north(), util::LATITUDE_MAX), bounds_.east() });
- const TransformState state;
return tileCover(
- TileCoordinate::fromLatLng(state, z, bounds.northwest()).p,
- TileCoordinate::fromLatLng(state, z, bounds.northeast()).p,
- TileCoordinate::fromLatLng(state, z, bounds.southeast()).p,
- TileCoordinate::fromLatLng(state, z, bounds.southwest()).p,
- TileCoordinate::fromLatLng(state, z, bounds.center()).p,
+ TileCoordinate::fromLatLng(z, bounds.northwest()).p,
+ TileCoordinate::fromLatLng(z, bounds.northeast()).p,
+ TileCoordinate::fromLatLng(z, bounds.southeast()).p,
+ TileCoordinate::fromLatLng(z, bounds.southwest()).p,
+ TileCoordinate::fromLatLng(z, bounds.center()).p,
z);
}