Skip to content

Fix nearby-group sorting by removing float-to-int comparator truncation#670

Merged
dharmab merged 3 commits into
mainfrom
copilot/fix-unstable-sort-ordering
May 5, 2026
Merged

Fix nearby-group sorting by removing float-to-int comparator truncation#670
dharmab merged 3 commits into
mainfrom
copilot/fix-unstable-sort-ordering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

findNearbyGroups was sorting by int(distanceToA - distanceToB), which collapses sub-unit distance differences to 0 and can treat distinct groups as equal. That can produce unstable/incorrect ordering for close contacts.

  • Comparator correctness
    • Replaced truncating subtraction-based comparator with a float-safe comparison in pkg/radar/nearby.go.
    • This preserves strict ordering for small distance deltas and avoids accidental ties.
slices.SortFunc(groups, func(a, b *group) int {
    distanceToA := spatial.Distance(pointOfInterest, a.point(), r.withProjection())
    distanceToB := spatial.Distance(pointOfInterest, b.point(), r.withProjection())
    return cmp.Compare(distanceToA, distanceToB)
})

> [!WARNING]
>
>

Copilot AI changed the title [WIP] Fix float-to-int truncation in sort comparator Fix nearby-group sorting by removing float-to-int comparator truncation Apr 22, 2026
Copilot AI requested a review from dharmab April 22, 2026 18:28
Comment thread pkg/radar/nearby_test.go Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excessive testing, remove tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed pkg/radar/nearby_test.go as requested in commit 1e6ef2b.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 22, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https -D_FORTIFY_SOURCE=3 -quiet -dumpdir /tmp/go-build3192736678/b329/ 0319084013-9386f2394010 _cgo_8.c -dumpbase-ext .c -m64 -mtune=generic -march=x86-64 -f /internal/analys-c=4 /internal/analys-nolocalimports 0.1-go1.26.0.lin-importcfg work/skyeye/skyeas t/v2/pkg/goforma-W ux-amd64/pkg/too-I 0.1-go1.26.0.lin/tmp/go-build3192736678/b329/ (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from dharmab April 22, 2026 19:13
@dharmab dharmab marked this pull request as ready for review May 5, 2026 02:07
@dharmab dharmab enabled auto-merge (squash) May 5, 2026 02:08
@dharmab dharmab merged commit 4746f60 into main May 5, 2026
11 checks passed
@dharmab dharmab deleted the copilot/fix-unstable-sort-ordering branch May 5, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Float-to-int truncation in sort comparator produces unstable ordering

2 participants