Conversation
Rounding in pointToTileFraction can land a point that is just past a tile edge exactly on the edge, so Math.floor assigns the tile on the wrong side. Verify the floored tile actually contains the point and step back one tile when it does not.
|
OX Security reviewed this pull request — nothing to fix.
Branch |
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.
pointToTilereturns the wrong tile for points sitting on or very near a tile boundary. Thecoordinates come back from
pointToTileFractionas floats, and flooring them is exact only when thedivision was: a longitude a hair west of an edge can compute to a fraction a hair above the integer,
so the point lands in the tile east of the one it belongs to. The reverse happens on the north edge.
This re-checks the floored tile against the edge it claims, in
src/index.ts. If the longitude iswest of
tile2lonfor the chosen column, the column is decremented; the same for latitude againsttile2latfor the row. The comparison is done in degrees against the same functions that define theedges, rather than by nudging the fraction, so the tile the point ends in is the one whose bounds
actually contain it.
The convention is preserved: an edge belongs to the tile east and south of it. The longitude guard is
bounded to
[-180, 180)and the latitude guard to rows above 0, so the antimeridian and the top roware left alone rather than wrapping to a tile that does not exist.
Tests cover a point just west of an edge, a point exactly on one, and the reported case.
Fixes #45