summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-04-10 14:47:36 -0700
committerAsheem Mamoowala <asheem.mamoowala@mapbox.com>2018-04-10 15:23:04 -0700
commit8c6534b51c890d49d4f0f8245d32eb5025c14dd3 (patch)
treea2fcb5d2af0befa83051e9f1977fba16cb5d4dff
parent1a147fe15e08787a86d4e25841cd27d4c535f825 (diff)
downloadqtlocation-mapboxgl-8c6534b51c890d49d4f0f8245d32eb5025c14dd3.tar.gz
Ue smart pointer and remove unnecessary headers
-rw-r--r--src/mbgl/renderer/layers/render_background_layer.cpp1
-rw-r--r--src/mbgl/util/tile_cover.cpp9
-rw-r--r--src/mbgl/util/tile_cover.hpp6
-rw-r--r--src/mbgl/util/tile_cover_impl.cpp14
-rw-r--r--src/mbgl/util/tile_cover_impl.hpp25
5 files changed, 32 insertions, 23 deletions
diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp
index aebc4cc9aa..44c3fffb6c 100644
--- a/src/mbgl/renderer/layers/render_background_layer.cpp
+++ b/src/mbgl/renderer/layers/render_background_layer.cpp
@@ -7,6 +7,7 @@
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/background_program.hpp>
#include <mbgl/util/tile_cover.hpp>
+#include <mbgl/map/transform_state.hpp>
namespace mbgl {
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index 9c7e453192..d15257a3f1 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -3,6 +3,7 @@
#include <mbgl/util/interpolate.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/tile_cover_impl.hpp>
+#include <mbgl/util/tile_coordinate.hpp>
#include <functional>
#include <list>
@@ -246,15 +247,15 @@ TileCover::TileCover(const LatLngBounds&bounds_, int32_t z) {
auto nw = Projection::project(bounds.northwest(), z);
Polygon<double> p({ {sw, nw, ne, se, sw} });
- impl = new TileCoverImpl(z, p, false);
+ impl = std::make_unique<TileCover::Impl>(z, p, false);
}
-TileCover::TileCover(const Geometry<double>& geom, int32_t z, bool project/* = true*/) {
- impl = new TileCoverImpl(z, geom, project);
+TileCover::TileCover(const Geometry<double>& geom, int32_t z, bool project/* = true*/)
+ : impl( std::make_unique<TileCover::Impl>(z, geom, project)) {
}
TileCover::~TileCover() {
- delete impl;
+
}
bool TileCover::next() {
diff --git a/src/mbgl/util/tile_cover.hpp b/src/mbgl/util/tile_cover.hpp
index baeecd0c2c..f851096dd3 100644
--- a/src/mbgl/util/tile_cover.hpp
+++ b/src/mbgl/util/tile_cover.hpp
@@ -2,10 +2,10 @@
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/style/types.hpp>
-#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/util/geometry.hpp>
#include <vector>
+#include <memory>
namespace mbgl {
@@ -14,7 +14,6 @@ class LatLngBounds;
namespace util {
-class TileCoverImpl;
using ScanLine = const std::function<void(int32_t x0, int32_t x1, int32_t y)>;
// Helper class to stream tile-cover results per row
@@ -32,7 +31,8 @@ public:
bool getTiles(ScanLine&);
private:
- TileCoverImpl* impl;
+ class Impl;
+ std::unique_ptr<Impl> impl;
};
int32_t coveringZoomLevel(double z, style::SourceType type, uint16_t tileSize);
diff --git a/src/mbgl/util/tile_cover_impl.cpp b/src/mbgl/util/tile_cover_impl.cpp
index bfd4e6f314..01580aeb7d 100644
--- a/src/mbgl/util/tile_cover_impl.cpp
+++ b/src/mbgl/util/tile_cover_impl.cpp
@@ -105,12 +105,10 @@ void build_edge_table(point_list& points, uint32_t maxTile, edge_table& et, bool
if (to_max.points.size() > 0) {
// Projections may result in values beyond the bounds due to double precision
const auto y = static_cast<uint32_t>(std::floor(clamp(to_max.points.front().y, 0.0, (double)maxTile)));
- to_max.interpolate(y);
et[y].push_back(std::move(to_max));
}
if (to_min.points.size() > 0) {
const auto y = static_cast<uint32_t>(std::floor(clamp(to_min.points.front().y, 0.0, (double)maxTile)));
- to_min.interpolate(y);
et[y].push_back(std::move(to_min));
}
}
@@ -231,7 +229,7 @@ struct ToEdgeTable {
}
};
-TileCoverImpl::TileCoverImpl(int32_t z, const Geometry<double>& geom, bool project): maxY(1 << z) {
+TileCover::Impl::Impl(int32_t z, const Geometry<double>& geom, bool project): maxY(1 << z) {
ToFeatureType toFeatureType;
isClosed = apply_visitor(toFeatureType, geom) == FeatureType::Polygon;
@@ -240,16 +238,18 @@ TileCoverImpl::TileCoverImpl(int32_t z, const Geometry<double>& geom, bool proje
reset();
}
-void TileCoverImpl::reset() {
+void TileCover::Impl::reset() {
+ if (edgeTable.size() == 0) return;
+
activeEdgeTable = edgeTable.begin()->second;
currentRow = edgeTable.begin()->first;
}
-bool TileCoverImpl::next() {
+bool TileCover::Impl::next() {
return activeEdgeTable.size() != 0 && currentRow < maxY;
}
-bool TileCoverImpl::scanRow(ScanLine& scanCover) {
+bool TileCover::Impl::scanRow(ScanLine& scanCover) {
if (!next()) { return false; }
auto xps = util::scan_row(currentRow, activeEdgeTable);
@@ -257,7 +257,7 @@ bool TileCoverImpl::scanRow(ScanLine& scanCover) {
auto x_min = xps[0].x0;
auto x_max = xps[0].x1;
- int8_t nzRule = xps[0].winding ? 1 : -1;
+ int32_t nzRule = xps[0].winding ? 1 : -1;
for (size_t i = 1; i < xps.size(); i++) {
auto xp = xps[i];
if (!(isClosed && nzRule != 0)) {
diff --git a/src/mbgl/util/tile_cover_impl.hpp b/src/mbgl/util/tile_cover_impl.hpp
index e886d21f66..b485cfff19 100644
--- a/src/mbgl/util/tile_cover_impl.hpp
+++ b/src/mbgl/util/tile_cover_impl.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/util/tile_cover.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/util/geometry.hpp>
@@ -28,8 +29,13 @@ struct x_range {
struct bound {
point_list points;
size_t currentPointIndex = 0;
- double currentX;
- bool winding;
+ bool winding = false;
+ bound() = default;
+ bound(const bound& rhs) {
+ points = rhs.points;
+ currentPointIndex = rhs.currentPointIndex;
+ winding = rhs.winding;
+ }
double interpolate(uint32_t y) {
const auto& p0 = points[currentPointIndex];
@@ -37,25 +43,26 @@ struct bound {
const auto dx = p1.x - p0.x;
const auto dy = p1.y - p0.y;
- currentX = p0.x;
+ auto x = p0.x;
if (dx == 0) {
- return currentX;
+ return x;
} else if (dy == 0){
return y <= p0.y ? p0.x : p1.x;
}
- if (y < p0.y) return currentX;
+ if (y < p0.y) return x;
if (y > p1.y) return p1.x;
- currentX = (dx / dy) * (y - p0.y) + p0.x;
- return currentX;
+ x = (dx / dy) * (y - p0.y) + p0.x;
+ return x;
}
};
using ScanLine = const std::function<void(int32_t x0, int32_t x1, int32_t y)>;
-class TileCoverImpl {
+class TileCover::Impl {
public:
- TileCoverImpl(int32_t z, const Geometry<double>& geom, bool project = true);
+ Impl(int32_t z, const Geometry<double>& geom, bool project = true);
+ ~Impl() = default;
bool scanRow(ScanLine& );
bool next();
void reset();