Skip to content

Commit

Permalink
Make sure overscaledZ is at least as big as tile Z (#4988)
Browse files Browse the repository at this point in the history
* make sure overscaledZ is at least as big as tile Z

* add unit test

* fix lint
  • Loading branch information
NathanMOlson authored Nov 4, 2024
1 parent 03b69f0 commit c77395a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/geo/projection/covering_tiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export function coveringTiles(transform: IReadonlyTransform, options: CoveringTi
const dz = nominalZ - it.zoom;
const dx = cameraPoint[0] - 0.5 - (x << dz);
const dy = cameraPoint[1] - 0.5 - (y << dz);
const overscaledZ = options.reparseOverscaled ? thisTileDesiredZ : it.zoom;
const overscaledZ = options.reparseOverscaled ? Math.max(it.zoom, thisTileDesiredZ) : it.zoom;
result.push({
tileID: new OverscaledTileID(it.zoom === maxZoom ? overscaledZ : it.zoom, it.wrap, it.zoom, x, y),
distanceSq: vec2.sqrLen([centerPoint[0] - 0.5 - x, centerPoint[1] - 0.5 - y]),
Expand Down
22 changes: 22 additions & 0 deletions src/geo/projection/mercator_transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,28 @@ describe('transform', () => {

});

test('coveringTiles: overscaledZ', () => {
const options = {
minzoom: 1,
maxzoom: 10,
tileSize: 256,
reparseOverscaled: true
};

const transform = new MercatorTransform(0, 10, 0, 85, true);
transform.resize(10, 400);
// make slightly off center so that sort order is not subject to precision issues
transform.setCenter(new LngLat(-0.01, 0.01));
transform.setPitch(85);
transform.setFov(10);

transform.setZoom(10);
const tiles = coveringTiles(transform, options);
for (const tile of tiles) {
expect(tile.overscaledZ).toBeGreaterThanOrEqual(tile.canonical.z);
}
});

test('maxzoom-0', () => {
const options = {
minzoom: 0,
Expand Down

0 comments on commit c77395a

Please sign in to comment.