[core] Simplify Screen to Geometry coordinate conversion

This commit is contained in:
Bruno de Oliveira Abinader
2016-02-22 02:07:11 +02:00
parent 9771b0e569
commit b325df880b
2 changed files with 8 additions and 6 deletions

View File

@@ -12,15 +12,15 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer&
std::unordered_map<std::string, std::string> 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<const AnnotationTileFeature>(FeatureType::Point,
GeometryCollection {{ {{ coordinate }} }},
GeometryCollection {{ {{ GeometryCoordinate { projected } }} }},
featureProperties));
}

View File

@@ -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<int16_t>;
using GeometryCoordinates = std::vector<GeometryCoordinate>;
using GeometryCollection = std::vector<GeometryCoordinates>;