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

Commit 1d46e83

Browse files
committed
[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().
1 parent e1be2c4 commit 1d46e83

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

include/mbgl/util/constants.hpp

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

src/mbgl/annotation/shape_annotation_impl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
9090
static const double baseTolerance = 4;
9191

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

9696
std::vector<geojsonvt::ProjectedFeature> features = {
9797
ShapeAnnotationGeometry::visit(geometry(), ToGeoJSONVT(tolerance))

src/mbgl/map/transform_state.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewpo
1616
#pragma mark - Matrix
1717

1818
void TransformState::matrixFor(mat4& matrix, const UnwrappedTileID& tileID) const {
19-
const uint64_t tileScale = 1ull << tileID.canonical.z;
19+
const uint32_t tileScale = 1u << tileID.canonical.z;
2020
const double s = worldSize() / tileScale;
2121

2222
matrix::identity(matrix);
2323
matrix::translate(matrix, matrix,
24-
static_cast<int64_t>(tileID.canonical.x + tileID.wrap * tileScale) * s,
25-
static_cast<int64_t>(tileID.canonical.y) * s, 0);
24+
int64_t(tileID.canonical.x + tileID.wrap * tileScale) * s,
25+
int64_t(tileID.canonical.y) * s, 0);
2626
matrix::scale(matrix, matrix, s / util::EXTENT, s / util::EXTENT, 1);
2727
}
2828

0 commit comments

Comments
 (0)