Fix small-radius clusters not always forming on higher zooms #173
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 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.