Fix getClusters dropping points exactly on the query bbox edge#261
Closed
spokodev wants to merge 1 commit into
Closed
Fix getClusters dropping points exactly on the query bbox edge#261spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
Points are stored as Float32 (fround), but the getClusters range query was built from full-precision Float64 bounds. fround can round a stored coordinate slightly outside its exact value, so a point whose lng/lat equals a bbox edge fell just outside the inclusive range and was dropped. Project the query bounds through the same fround so the edge comparison is exact. Fixes mapbox#234.
Member
|
Thanks for the fix! This is superceded by #258 though (no |
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.
Fixes #234.
getClusters(bbox, zoom)silently drops a point whose longitude or latitude falls exactly on an edge of the query bbox, even though the documented bbox[westLng, southLat, eastLng, northLat]is inclusive.This hits the common pattern of computing the bbox as the extent of the points and then querying with it, which is the scenario in #234.
Cause
Points are stored projected and rounded to Float32 (
fround(lngX(lng))), but thegetClustersrange query is built from full-precision Float64 bounds (lngX(minLng), ...).froundcan round a stored coordinate slightly outside its exact double, so a point that should sit on the edge ends up just beyond the inclusiverangebound and is excluded.Fix
Project the query bounds through the same
froundthe stored coordinates use, so an on-edge point compares equal.froundis already defined in the module. The fix is scoped togetClusters.Testing
Added a test using the coordinates from #234, where the SW-corner point lies exactly on the bbox edge. On the current code that point is dropped (
['a','c','d']); with the fix all four are returned. The rest of the suite stays green (16 tests).