[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.
This commit is contained in:
John Firebaugh
2016-05-11 13:54:05 -07:00
parent 5f1144f05a
commit 1a030e7c33
12 changed files with 9 additions and 54 deletions

View File

@@ -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,

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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_)) {
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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