Skip to content

Commit

Permalink
Fix bug in grouping function
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmab committed Aug 21, 2024
1 parent 8949699 commit 9bd9caf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ third_party/whisper.cpp

# Local dev scripts ignored by default
scripts/
dev/

# ACMI files
*.txt.acmi
*.acmi.zip

# Defaults for VSCode
.vscode/settings.json
.vscode/settings.json
15 changes: 5 additions & 10 deletions pkg/radar/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

func (s *scope) enumerateGroups(coalition coalitions.Coalition) []*group {
visited := make(map[uint32]bool)
visited := make(map[uint32]struct{})
groups := make([]*group, 0)
for trackfile := range s.contacts.values() {
if _, ok := visited[trackfile.Contact.UnitID]; ok {
continue
}
visited[trackfile.Contact.UnitID] = true
visited[trackfile.Contact.UnitID] = struct{}{}

if trackfile.Contact.Coalition != coalition {
continue
Expand All @@ -31,8 +31,8 @@ func (s *scope) enumerateGroups(coalition coalitions.Coalition) []*group {
if grp == nil {
continue
}
for _, contact := range grp.contacts {
visited[contact.Contact.UnitID] = true
for _, unitID := range grp.UnitIDs() {
visited[unitID] = struct{}{}
}
groups = append(groups, grp)
}
Expand Down Expand Up @@ -74,12 +74,7 @@ func (s *scope) addNearbyAircraftToGroup(this *trackfiles.Trackfile, group *grou
spreadInterval := 5 * unit.NauticalMile
for other := range s.contacts.values() {
// Skip if this one is already in the group
if slices.ContainsFunc(group.contacts, func(t *trackfiles.Trackfile) bool {
if t == nil {
return false
}
return t.Contact.UnitID == other.Contact.UnitID
}) {
if slices.Contains(group.UnitIDs(), other.Contact.UnitID) {
continue
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/radar/nearby.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/paulmach/orb/geo"
)

func (s *scope) findNearbyGroups(interest orb.Point, minAltitude, maxAltitude, radius unit.Length, coalition coalitions.Coalition, filter brevity.ContactCategory) []*group {
circle := geo.NewBoundAroundPoint(interest, float64(radius.Meters()))
func (s *scope) findNearbyGroups(pointOfInterest orb.Point, minAltitude, maxAltitude, radius unit.Length, coalition coalitions.Coalition, filter brevity.ContactCategory) []*group {
circle := geo.NewBoundAroundPoint(pointOfInterest, radius.Meters())
groups := make([]*group, 0)
visited := make(map[uint32]struct{})
for trackfile := range s.contacts.values() {
Expand All @@ -22,8 +22,8 @@ func (s *scope) findNearbyGroups(interest orb.Point, minAltitude, maxAltitude, r
inStack := minAltitude <= trackfile.LastKnown().Altitude && trackfile.LastKnown().Altitude <= maxAltitude
if isMatch && inCircle && inStack {
grp := s.findGroupForAircraft(trackfile)
for id := range grp.UnitIDs() {
visited[uint32(id)] = struct{}{}
for _, id := range grp.UnitIDs() {
visited[id] = struct{}{}
}
groups = append(groups, grp)
}
Expand Down

0 comments on commit 9bd9caf

Please sign in to comment.