diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-05-11 13:54:05 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-05-11 13:54:05 -0700 |
commit | 1a030e7c3347f08329d2787cde37cfa0958baad4 (patch) | |
tree | e9ec309eda3de6edc411824e76df632730d41064 | |
parent | 5f1144f05a8391cf2c01dc7a67312a27ef32805b (diff) | |
download | qtlocation-mapboxgl-1a030e7c3347f08329d2787cde37cfa0958baad4.tar.gz |
[core] Normalize tile coordinates in VectorTile (#4966)
Previously, vector tile coordinates were being normalized to util::EXTENT in each place they were used, and for annotation and GeoJSON sources that don't require normalization.
-rw-r--r-- | src/mbgl/annotation/point_annotation_impl.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/annotation/shape_annotation_impl.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/layer/circle_layer.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/layer/fill_layer.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/layer/line_layer.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/util/get_geometries.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/util/get_geometries.hpp | 12 |
12 files changed, 9 insertions, 54 deletions
diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/point_annotation_impl.cpp index 2be8a29432..a1367f3901 100644 --- a/src/mbgl/annotation/point_annotation_impl.cpp +++ b/src/mbgl/annotation/point_annotation_impl.cpp @@ -25,7 +25,7 @@ void PointAnnotationImpl::updateLayer(const CanonicalTileID& tileID, AnnotationT projected *= std::pow(2, tileID.z); projected.x = std::fmod(projected.x, 1); projected.y = std::fmod(projected.y, 1); - projected *= double(GeometryTileFeature::defaultExtent); + projected *= double(util::EXTENT); layer.features.emplace_back( std::make_shared<const AnnotationTileFeature>(FeatureType::Point, diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index 4ed06a5540..9b9ea3bf26 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -85,7 +85,7 @@ void ShapeAnnotationImpl::updateTile(const CanonicalTileID& tileID, AnnotationTi if (!shapeTiler) { const uint64_t maxAmountOfTiles = 1 << maxZoom; - const double tolerance = baseTolerance / (maxAmountOfTiles * GeometryTileFeature::defaultExtent); + const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT); geojsonvt::ProjectedRings rings; std::vector<geojsonvt::LonLat> points; diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index b7ec99803d..aeedea3a74 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -3,7 +3,6 @@ #include <mbgl/style/style_layer.hpp> #include <mbgl/layer/symbol_layer.hpp> #include <mbgl/text/collision_tile.hpp> -#include <mbgl/util/get_geometries.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/math.hpp> #include <mbgl/math/minmax.hpp> @@ -141,7 +140,7 @@ void FeatureIndex::addFeature( if (!styleLayer) continue; if (!styleLayer->is<SymbolLayer>()) { - auto geometries = getGeometries(*geometryTileFeature); + auto geometries = geometryTileFeature->getGeometries(); if (!styleLayer->queryIntersectsGeometry(queryGeometry, geometries, bearing, pixelsToTileUnits)) continue; } diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index 1cdc3fa057..839d1282a9 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -1,7 +1,6 @@ #include <mbgl/layer/circle_layer.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/circle_bucket.hpp> -#include <mbgl/util/get_geometries.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/util/math.hpp> #include <mbgl/util/intersection_tests.hpp> @@ -51,7 +50,7 @@ std::unique_ptr<Bucket> CircleLayer::createBucket(StyleBucketParameters& paramet auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = getGeometries(feature); + auto geometries = feature.getGeometries(); bucket->addGeometry(geometries); parameters.featureIndex.insert(geometries, index, layerName, name); }); diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index eff80fb6d5..850bac4ab4 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -1,7 +1,6 @@ #include <mbgl/layer/fill_layer.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/fill_bucket.hpp> -#include <mbgl/util/get_geometries.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/util/math.hpp> #include <mbgl/util/intersection_tests.hpp> @@ -63,7 +62,7 @@ std::unique_ptr<Bucket> FillLayer::createBucket(StyleBucketParameters& parameter auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = getGeometries(feature); + auto geometries = feature.getGeometries(); bucket->addGeometry(geometries); parameters.featureIndex.insert(geometries, index, layerName, name); }); diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index d26638b0c4..d1d377462a 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -1,7 +1,6 @@ #include <mbgl/layer/line_layer.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/line_bucket.hpp> -#include <mbgl/util/get_geometries.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/util/math.hpp> #include <mbgl/util/intersection_tests.hpp> @@ -84,7 +83,7 @@ std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameter auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = getGeometries(feature); + auto geometries = feature.getGeometries(); bucket->addGeometry(geometries); parameters.featureIndex.insert(geometries, index, layerName, name); }); diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index a183032761..3588b2ed51 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -25,7 +25,6 @@ #include <mbgl/util/merge_lines.hpp> #include <mbgl/util/clip_lines.hpp> #include <mbgl/util/std.hpp> -#include <mbgl/util/get_geometries.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/string.hpp> #include <mbgl/math/minmax.hpp> @@ -170,7 +169,7 @@ void SymbolBucket::parseFeatures(const GeometryTileLayer& layer, const Filter& f auto &multiline = ft.geometry; - GeometryCollection geometryCollection = getGeometries(*feature); + GeometryCollection geometryCollection = feature->getGeometries(); for (auto& line : geometryCollection) { multiline.emplace_back(); for (auto& point : line) { diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 923585028c..676c18e4c9 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -34,15 +34,12 @@ using GeometryCollection = std::vector<GeometryCoordinates>; class GeometryTileFeature : private util::noncopyable { public: - static const uint32_t defaultExtent = util::EXTENT; - virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; virtual optional<Value> getValue(const std::string& key) const = 0; virtual Feature::property_map getProperties() const { return Feature::property_map(); } virtual optional<uint64_t> getID() const { return {}; } virtual GeometryCollection getGeometries() const = 0; - virtual uint32_t getExtent() const { return defaultExtent; } }; class GeometryTileLayer : private util::noncopyable { diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp index 27edd85324..343224052a 100644 --- a/src/mbgl/tile/vector_tile.cpp +++ b/src/mbgl/tile/vector_tile.cpp @@ -114,6 +114,7 @@ GeometryCollection VectorTileFeature::getGeometries() const { uint32_t length = 0; int32_t x = 0; int32_t y = 0; + const float scale = float(util::EXTENT) / layer.extent; GeometryCollection lines; @@ -139,7 +140,7 @@ GeometryCollection VectorTileFeature::getGeometries() const { line = &lines.back(); } - line->emplace_back(x, y); + line->emplace_back(::round(x * scale), ::round(y * scale)); } else if (cmd == 7) { // closePolygon if (!line->empty()) { @@ -154,10 +155,6 @@ GeometryCollection VectorTileFeature::getGeometries() const { return lines; } -uint32_t VectorTileFeature::getExtent() const { - return layer.extent; -} - VectorTile::VectorTile(std::shared_ptr<const std::string> data_) : data(std::move(data_)) { } diff --git a/src/mbgl/tile/vector_tile.hpp b/src/mbgl/tile/vector_tile.hpp index c0892cd243..d41d4f4f34 100644 --- a/src/mbgl/tile/vector_tile.hpp +++ b/src/mbgl/tile/vector_tile.hpp @@ -25,7 +25,6 @@ public: std::unordered_map<std::string,Value> getProperties() const override; optional<uint64_t> getID() const override; GeometryCollection getGeometries() const override; - uint32_t getExtent() const override; private: const VectorTileLayer& layer; diff --git a/src/mbgl/util/get_geometries.cpp b/src/mbgl/util/get_geometries.cpp deleted file mode 100644 index 5961af2150..0000000000 --- a/src/mbgl/util/get_geometries.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include <mbgl/util/get_geometries.hpp> -#include <mbgl/util/constants.hpp> - -#include <cmath> - -namespace mbgl { - -GeometryCollection getGeometries(const GeometryTileFeature& feature) { - const float scale = float(util::EXTENT) / feature.getExtent(); - GeometryCollection geometryCollection = feature.getGeometries(); - for (auto& line : geometryCollection) { - for (auto& point : line) { - point.x = ::round(point.x * scale); - point.y = ::round(point.y * scale); - } - } - return geometryCollection; -} - -} // namespace mbgl - diff --git a/src/mbgl/util/get_geometries.hpp b/src/mbgl/util/get_geometries.hpp deleted file mode 100644 index 013a7e5b9f..0000000000 --- a/src/mbgl/util/get_geometries.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MBGL_UTIL_GET_GEOMETRIES -#define MBGL_UTIL_GET_GEOMETRIES - -#include <mbgl/tile/geometry_tile.hpp> - -namespace mbgl { - -GeometryCollection getGeometries(const GeometryTileFeature& feature); - -} // namespace mbgl - -#endif |