Skip to content

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

@dharmab

Description

@dharmab

Summary

In `pkg/radar/nearby.go`, the sort comparator converts a float64 distance difference to int:

```go
return int(distanceToA - distanceToB)
```

`unit.Length` is `float64`. When two groups are within 1 unit of distance from each other, the subtraction result truncates to 0, making the sort consider them equal. This produces unstable sort results and potentially incorrect ordering of nearby groups.

Location

`pkg/radar/nearby.go:40`

Suggested Fix

Use `cmp.Compare(distanceToA, distanceToB)` which handles float64 comparison correctly.

🤖 Generated with Claude Code

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions