From b325df880baf6f3a454c51d2e21d69114477c276 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 22 Feb 2016 02:07:11 +0200 Subject: [PATCH] [core] Simplify Screen to Geometry coordinate conversion --- src/mbgl/annotation/point_annotation_impl.cpp | 12 ++++++------ src/mbgl/tile/geometry_tile.hpp | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mbgl/annotation/point_annotation_impl.cpp b/src/mbgl/annotation/point_annotation_impl.cpp index b0bce8c30..b54995bfd 100644 --- a/src/mbgl/annotation/point_annotation_impl.cpp +++ b/src/mbgl/annotation/point_annotation_impl.cpp @@ -12,15 +12,15 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer& std::unordered_map featureProperties; featureProperties.emplace("sprite", point.icon.empty() ? std::string("default_marker") : point.icon); - const mbgl::ScreenCoordinate pp = point.position.project(); - const uint32_t z2 = 1 << tileID.z; - const uint32_t x = pp.x * z2; - const uint32_t y = pp.y * z2; - const GeometryCoordinate coordinate(GeometryTileFeature::defaultExtent * (pp.x * z2 - x), GeometryTileFeature::defaultExtent * (pp.y * z2 - y)); + mbgl::ScreenCoordinate projected = point.position.project(); + projected *= 1 << tileID.z; + projected.x -= int16_t(projected.x); + projected.y -= int16_t(projected.y); + projected *= GeometryTileFeature::defaultExtent; layer.features.emplace_back( std::make_shared(FeatureType::Point, - GeometryCollection {{ {{ coordinate }} }}, + GeometryCollection {{ {{ GeometryCoordinate { projected } }} }}, featureProperties)); } diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 3fcb91037..6236e4e88 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -25,6 +25,8 @@ enum class FeatureType : uint8_t { }; // Normalized vector tile coordinates. +// Each geometry coordinate represents a point in a bidimensional space, +// varying from -V...0...+V, where V is the maximum extent applicable. using GeometryCoordinate = vec2; using GeometryCoordinates = std::vector; using GeometryCollection = std::vector;