summaryrefslogtreecommitdiff
path: root/src/mbgl/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-12 12:38:12 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-17 13:20:25 -0700
commit7e5d0ff49e2b5a6a3caa45464d8056e93431d780 (patch)
tree665519111b6877ccab34d02831dc66d09b4e75ac /src/mbgl/util
parent3e21e3887aa08ea32e4370b8c6e990d9f8c4333f (diff)
downloadqtlocation-mapboxgl-7e5d0ff49e2b5a6a3caa45464d8056e93431d780.tar.gz
[core] Rewrite TileCoordinate in terms of geometry.hpp point
Diffstat (limited to 'src/mbgl/util')
-rw-r--r--src/mbgl/util/tile_coordinate.hpp22
-rw-r--r--src/mbgl/util/tile_cover.cpp39
2 files changed, 23 insertions, 38 deletions
diff --git a/src/mbgl/util/tile_coordinate.hpp b/src/mbgl/util/tile_coordinate.hpp
index 9962c35b18..df240a50e0 100644
--- a/src/mbgl/util/tile_coordinate.hpp
+++ b/src/mbgl/util/tile_coordinate.hpp
@@ -1,27 +1,20 @@
-#ifndef MBGL_UTIL_TILE_COORDINATE
-#define MBGL_UTIL_TILE_COORDINATE
+#pragma once
-#include <mbgl/style/types.hpp>
+#include <mbgl/util/geometry.hpp>
#include <mbgl/map/transform_state.hpp>
-
namespace mbgl {
-class TransformState;
-
// Has floating point x/y coordinates.
// Used for computing the tiles that need to be visible in the viewport.
class TileCoordinate {
public:
- double x, y, z;
+ Point<double> p;
+ double z;
static TileCoordinate fromLatLng(const TransformState& state, double zoom, const LatLng& latLng) {
const double scale = std::pow(2, zoom - state.getZoom());
- return {
- state.lngX(latLng.longitude) * scale / util::tileSize,
- state.latY(latLng.latitude) * scale / util::tileSize,
- zoom
- };
+ return { state.project(latLng) * scale / double(util::tileSize), zoom };
}
static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& point) {
@@ -29,11 +22,8 @@ public:
}
TileCoordinate zoomTo(double zoom) const {
- double scale = std::pow(2, zoom - z);
- return { x * scale, y * scale, zoom };
+ return { p * std::pow(2, zoom - z), zoom };
}
};
} // namespace mbgl
-
-#endif
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index 739528a8b8..5487fb269c 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -16,7 +16,7 @@ struct edge {
double x1 = 0, y1 = 0;
double dx = 0, dy = 0;
- edge(TileCoordinate a, TileCoordinate b) {
+ edge(Point<double> a, Point<double> b) {
if (a.y > b.y) std::swap(a, b);
x0 = a.x;
y0 = a.y;
@@ -54,7 +54,7 @@ static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine sca
}
// scan-line conversion
-static void scanTriangle(const TileCoordinate& a, const TileCoordinate& b, const TileCoordinate& c, int32_t ymin, int32_t ymax, ScanLine& scanLine) {
+static void scanTriangle(const Point<double>& a, const Point<double>& b, const Point<double>& c, int32_t ymin, int32_t ymax, ScanLine& scanLine) {
edge ab = edge(a, b);
edge bc = edge(b, c);
edge ca = edge(c, a);
@@ -75,17 +75,12 @@ namespace util {
namespace {
-std::vector<UnwrappedTileID> tileCover(const TileCoordinate& tl,
- const TileCoordinate& tr,
- const TileCoordinate& br,
- const TileCoordinate& bl,
- const TileCoordinate& c,
+std::vector<UnwrappedTileID> tileCover(const Point<double>& tl,
+ const Point<double>& tr,
+ const Point<double>& br,
+ const Point<double>& bl,
+ const Point<double>& c,
int32_t z) {
- assert(tl.z == z);
- assert(tr.z == z);
- assert(br.z == z);
- assert(bl.z == z);
- assert(c.z == z);
const int32_t tiles = 1 << z;
struct ID {
@@ -154,11 +149,11 @@ std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, int32_t z) {
const TransformState state;
return tileCover(
- TileCoordinate::fromLatLng(state, z, bounds.northwest()),
- TileCoordinate::fromLatLng(state, z, bounds.northeast()),
- TileCoordinate::fromLatLng(state, z, bounds.southeast()),
- TileCoordinate::fromLatLng(state, z, bounds.southwest()),
- TileCoordinate::fromLatLng(state, z, bounds.center()),
+ 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,
z);
}
@@ -166,11 +161,11 @@ std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) {
const double w = state.getWidth();
const double h = state.getHeight();
return tileCover(
- TileCoordinate::fromScreenCoordinate(state, z, { 0, 0 }),
- TileCoordinate::fromScreenCoordinate(state, z, { w, 0 }),
- TileCoordinate::fromScreenCoordinate(state, z, { w, h }),
- TileCoordinate::fromScreenCoordinate(state, z, { 0, h }),
- TileCoordinate::fromScreenCoordinate(state, z, { w/2, h/2 }),
+ TileCoordinate::fromScreenCoordinate(state, z, { 0, 0 }).p,
+ TileCoordinate::fromScreenCoordinate(state, z, { w, 0 }).p,
+ TileCoordinate::fromScreenCoordinate(state, z, { w, h }).p,
+ TileCoordinate::fromScreenCoordinate(state, z, { 0, h }).p,
+ TileCoordinate::fromScreenCoordinate(state, z, { w/2, h/2 }).p,
z);
}