Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Use the right types for zoom scale logic
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
brunoabinader committed Jun 28, 2016
1 parent e1be2c4 commit 1d46e83
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/util/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ constexpr float tileSize = 512;
* In practice, all features are converted to this extent before being added.
*
* 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 to support features extending past the extent on the right edge of the tile.
* This leaves us with 2^13 = 8192
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/shape_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
static const double baseTolerance = 4;

if (!shapeTiler) {
const uint64_t maxAmountOfTiles = 1 << maxZoom;
const double tolerance = baseTolerance / (maxAmountOfTiles * util::EXTENT);
const uint64_t maxAmountOfTileFeatures = (1ull << maxZoom) * util::EXTENT;
const double tolerance = baseTolerance / maxAmountOfTileFeatures;

std::vector<geojsonvt::ProjectedFeature> features = {
ShapeAnnotationGeometry::visit(geometry(), ToGeoJSONVT(tolerance))
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewpo
#pragma mark - Matrix

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;

matrix::identity(matrix);
matrix::translate(matrix, matrix,
static_cast<int64_t>(tileID.canonical.x + tileID.wrap * tileScale) * s,
static_cast<int64_t>(tileID.canonical.y) * s, 0);
int64_t(tileID.canonical.x + tileID.wrap * tileScale) * s,
int64_t(tileID.canonical.y) * s, 0);
matrix::scale(matrix, matrix, s / util::EXTENT, s / util::EXTENT, 1);
}

Expand Down

0 comments on commit 1d46e83

Please sign in to comment.