[core] Use the right types for zoom scale logic

32 bit integers should be enough for zoom scale logic. In shape
annotation logic, 'maxAmountOfTileFeatures' requires 64 bits because we
are multiplying the zoom scale with the extent, which might give a
number higher than std::numeric_limits<uint32_t>::max().
This commit is contained in:
Bruno de Oliveira Abinader
2016-06-28 10:23:48 +03:00
parent e1be2c45c1
commit 1d46e83e30
3 changed files with 6 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ constexpr float tileSize = 512;
* In practice, all features are converted to this extent before being added. * In practice, all features are converted to this extent before being added.
* *
* Positions are stored as signed 16bit integers. * Positions are stored as signed 16bit integers.
* One bit is lost for signedness to support featuers extending past the left edge of the tile. * One bit is lost for signedness to support features extending past the left edge of the tile.
* One bit is lost because the line vertex buffer packs 1 bit of other data into the int. * One bit is lost because the line vertex buffer packs 1 bit of other data into the int.
* One bit is lost to support features extending past the extent on the right edge of the tile. * One bit is lost to support features extending past the extent on the right edge of the tile.
* This leaves us with 2^13 = 8192 * This leaves us with 2^13 = 8192

View File

@@ -90,8 +90,8 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
static const double baseTolerance = 4; static const double baseTolerance = 4;
if (!shapeTiler) { if (!shapeTiler) {
const uint64_t maxAmountOfTiles = 1 << maxZoom; const uint64_t maxAmountOfTileFeatures = (1ull << maxZoom) * util::EXTENT;
const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT); const double tolerance = baseTolerance / maxAmountOfTileFeatures;
std::vector<geojsonvt::ProjectedFeature> features = { std::vector<geojsonvt::ProjectedFeature> features = {
ShapeAnnotationGeometry::visit(geometry(), ToGeoJSONVT(tolerance)) ShapeAnnotationGeometry::visit(geometry(), ToGeoJSONVT(tolerance))

View File

@@ -16,13 +16,13 @@ TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewpo
#pragma mark - Matrix #pragma mark - Matrix
void TransformState::matrixFor(mat4& matrix, const UnwrappedTileID& tileID) const { void TransformState::matrixFor(mat4& matrix, const UnwrappedTileID& tileID) const {
const uint64_t tileScale = 1ull << tileID.canonical.z; const uint32_t tileScale = 1u << tileID.canonical.z;
const double s = worldSize() / tileScale; const double s = worldSize() / tileScale;
matrix::identity(matrix); matrix::identity(matrix);
matrix::translate(matrix, matrix, matrix::translate(matrix, matrix,
static_cast<int64_t>(tileID.canonical.x + tileID.wrap * tileScale) * s, int64_t(tileID.canonical.x + tileID.wrap * tileScale) * s,
static_cast<int64_t>(tileID.canonical.y) * s, 0); int64_t(tileID.canonical.y) * s, 0);
matrix::scale(matrix, matrix, s / util::EXTENT, s / util::EXTENT, 1); matrix::scale(matrix, matrix, s / util::EXTENT, s / util::EXTENT, 1);
} }