fix(clusters-dbscan): honor non-kilometer units in neighbor distance check#3073
Open
monad98 wants to merge 1 commit into
Open
fix(clusters-dbscan): honor non-kilometer units in neighbor distance check#3073monad98 wants to merge 1 commit into
monad98 wants to merge 1 commit into
Conversation
…check The neighbor distance was computed in kilometers and compared directly against maxDistance, while the bbox pre-filter used options.units. With a non-kilometer unit (e.g. meters) the comparison was effectively always true, so the neighborhood collapsed to the square bounding box instead of a maxDistance-radius circle. Measure the neighbor distance in options.units so both checks agree.
Collaborator
|
Oof, we definitely imply that it should work this way in the docs, but I'm afraid to merge this change without marking it as a breaking change. I've got a bunch of prep work for v8 staged, but haven't merged any of it quite yet. I added this to the v8 milestone though so that I should be able to include it there. Thanks! |
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.
Issue
clustersDbscanignores a non-kilometerunitsoption. The bbox pre-filter honorsoptions.unitsvialengthToDegrees(maxDistance, options.units), but the final neighbor predicate computes the distance in kilometers and compares it directly againstmaxDistance:So
maxDistanceis treated as kilometers in the predicate regardless ofoptions.units. For any unit smaller than a kilometer this makes the check effectively always true, and the neighborhood is no longer clipped to amaxDistance-radius circle — it collapses to the square bounding box, clustering points that are farther apart thanmaxDistance.Example: with
{ units: "meters" }andmaxDistance: 400, two points ~566 m apart (400 m east + 400 m north) are clustered even though they are well beyond 400 m.Fix
Measure the neighbor distance in
options.unitsso it matches the unit used by bothmaxDistanceand the bbox pre-filter. Whenunitsis omitted, both still default to kilometers, so existing behavior is unchanged.Tests
Added a regression test covering a non-kilometer unit. All existing fixture tests still pass.