Repository navigation
fix(deck.gl-raster): tolerate float error in RasterTileset2D.getParentIndex - #750
Merged
Merged
Conversation
Member
|
I'm pretty sure this is covered by #689... |
Member
|
Actually no, it isn't covered by #689; that fixed a couple precision issues but not in |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
getParentIndex used its own 1e-6 epsilon, the same value as the traversal's TILE_EDGE_TOLERANCE in tile-span.ts. Export that constant and use it, so the two tolerances can't drift apart. The test now loads the OGC example WebMercatorQuad.json, as the other raster-tileset tests do, instead of copying four of its scale denominators. It checks the first and last 8 tiles of all 25 levels, which covers every affected level pair (z4, z7, z8, z9, z14, z17 and z21) and the far edge of each level, where the float error is largest. Checking every tile of every level takes ~765 ms; this takes ~3 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
enabled auto-merge (squash)
October 21, 2026 02:30
kylebarron
disabled auto-merge
October 21, 2026 02:30
kylebarron
added a commit
that referenced
this pull request
Nov 5, 2026
…tParentIndex (#841) ### Problem While a tile loads, `best-available` refinement draws its parent (the coarser tile covering the same area) as a placeholder. For some COGs, `getParentIndex` returns the parent's *neighbour* instead. That tile is drawn somewhere else, so the loading tile's area goes blank until it arrives. | <video src="https://github.com/user-attachments/assets/1b4028d8-e5ca-40e5-85ca-90940fe5da47" controls muted playsinline></video> | <video src="https://github.com/user-attachments/assets/8e96e6e1-2eb5-4d87-bd14-81d97593edc4" controls muted playsinline></video> | |---|---| | Before | After | This happens when a COG's **overview sizes were rounded down**. Each overview halves the level above, but an odd size can't be halved exactly. For example, the Umbra Port of Rotterdam COG in `cog-basic` goes 22859 → 11429 px. Every level still covers the same extent, so the decimation between levels is slightly above 2 (here 22859 / 11429 ≈ 2.00009). `getParentIndex` maps a child to a parent with `floor(x / decimation + TILE_EDGE_TOLERANCE)`. With decimation slightly above 2, an even `x` lands just under a whole number, and the floor picks the tile before the right one: ``` decimation = 2857 / 1428 = 2.0007 child x = 2 → floor(2 / 2.0007 + 1e-6) = floor(0.99965) = 0 // expected 1 ``` The `1e-6` tolerance from #750 (for #738) absorbs floating-point noise like `2.000000000000004`, but not an error of ~10⁻⁴. A COG is affected when twice an overview's size is less than the size of the level above. Umbra's `2 × 11429 = 22858 < 22859` is one example. ### Fix Map the child tile's **centre** instead of its left/top edge: ```ts return { x: Math.floor((index.x + 0.5) / decimationX), y: Math.floor((index.y + 0.5) / decimationY), z: index.z - 1, }; ``` Tile `x` spans `[x, x + 1)` in child-tile units, so `x + 0.5` is its centre. Dividing by `decimation` converts that to parent-tile units, and `floor` gives the parent containing the centre, which is the one covering most of the child. When decimation is a whole number, including 1:1 (Sentinel-2's last overview), the result is unchanged. The centre is half a tile from any edge, so `getParentIndex` no longer needs `TILE_EDGE_TOLERANCE`. ### Testing New cases in `tests/raster-tileset/get-parent-index.test.ts`, using the overview widths of the Umbra COG from `cog-basic` (357 → 22859 px, 512 px tiles), fail on `main`: ``` AssertionError: expected { x: +0, y: +0, z: 2 } to deeply equal { x: 1, y: 1, z: 2 } ``` With this change, all 257 tests in `packages/deck.gl-raster` pass, including the #750 tests. **To see it in [`cog-basic`](https://developmentseed.org/deck.gl-raster/examples/cog-basic/):** pick **Umbra Port of Rotterdam (rotated COG)** and tick **Debug overlay**. Then zoom quickly from the four `z=1` tiles into the right-hand side of the image (I recommend setting network throttle to "Fast 4G" in devtools). On `main`, part of the screen drops to bare basemap while tiles load. With this change, the coarse tile stays visible until the fine tiles arrive. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Kyle Barron <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getParentIndexdivides a child tile's column and row by the footprint ratio between two levels, then floors the result. WithTileMatrixSetAdaptor, each footprint comes fromscaleDenominator * 0.00028. When a TileMatrixSet rounds its scale denominators, as the OGC example WebMercatorQuad does, that ratio can land just above 2. Between z7 and z8 it's2.0000000000000044. ThenMath.floor(2 / 2.0000000000000044)is 0, so an even column or row maps to the parent before its real one. For example,9/2/1mapped to8/0/0instead of8/1/0.The fix adds a tolerance of
1e-6to the quotient before flooring. This only changes the result when the quotient is within 1e-6 below a whole number, which in practice means the ratio is a whole number with float error in it. Non-integer ratios, such as COG overviews that don't halve exactly, give the same parents as before.I added
tests/raster-tileset/get-parent-index.test.ts. It builds a tileset from the OGC example's z6 to z9 scale denominators. It checks that9/2/1maps to8/1/0, and that every column and row at those levels maps tofloor(i / 2). Both tests failed before the change. They pass now, along with the existingtests/raster-tilesetandtileset-refinementtests. Biome check is clean.🤖 Generated with Claude Code
Fixes #738
This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.