Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix small-radius clusters not always forming on higher zooms #173

Merged
merged 1 commit into from
Jan 19, 2021

Conversation

mourner
Copy link
Member

@mourner mourner commented Jan 18, 2021

Fixes mapbox/mapbox-gl-js#2898. Turned out to be a very tricky bug!

Basically, if you set a small cluster radius, same-location points would sometimes fail to cluster on higher zooms, because the point KD-tree index for querying uses Float32Array internally for smaller memory footprint, and that's generally enough precision for location data, except in case where we do small radius queries — in this case the query point was float64, while stored coordinates were float32, leading to the query returning zero results.

The fix is to round the internal stored coordinates to float32 outside the index as well, so that the values are consistent. Math.fround is the fast way to do that, but I'm still including a fallback for IE11 so that non-GL-JS consumers could benefit from the fix.

Doesn't need C++ port because supercluster.hpp uses double precision for the index.

@mourner mourner added the bug label Jan 18, 2021
@mourner mourner self-assigned this Jan 18, 2021
@mourner mourner merged commit 592d066 into main Jan 19, 2021
@mourner mourner deleted the fix-small-radius branch January 19, 2021 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix bug causing clusters to disappear when "clusterRadius" is very small
1 participant