From 01405abb5fe7059d0f8934d31df903c49f84935e Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 9 Aug 2026 01:57:24 -0700 Subject: [PATCH 1/3] Bucket offline way assignment by area group --- maps/generate_offline.go | 95 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/maps/generate_offline.go b/maps/generate_offline.go index 0a38a76..3319e71 100644 --- a/maps/generate_offline.go +++ b/maps/generate_offline.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + stdmath "math" "os" "runtime" "strconv" @@ -106,6 +107,66 @@ func generateAreas() []Area { return areas } +func canBucketWay(way TmpWay) bool { + return !stdmath.IsNaN(way.Box.MinPos.Lat()) && !stdmath.IsNaN(way.Box.MinPos.Lon()) && + !stdmath.IsNaN(way.Box.MaxPos.Lat()) && !stdmath.IsNaN(way.Box.MaxPos.Lon()) && + !stdmath.IsInf(way.Box.MinPos.Lat(), 0) && !stdmath.IsInf(way.Box.MinPos.Lon(), 0) && + !stdmath.IsInf(way.Box.MaxPos.Lat(), 0) && !stdmath.IsInf(way.Box.MaxPos.Lon(), 0) && + way.Box.MinPos.Lat() <= way.Box.MaxPos.Lat() && way.Box.MinPos.Lon() <= way.Box.MaxPos.Lon() +} + +func bucketWaysByAreaGroup(scannedWays []TmpWay, areas []Area, s OfflineSettings) (map[m.Position][]int, []int, bool) { + if s.Overlap < 0 || stdmath.IsNaN(s.Overlap) || stdmath.IsInf(s.Overlap, 0) { + return nil, nil, false + } + for _, way := range scannedWays { + if !canBucketWay(way) { + return nil, nil, false + } + } + + selectedBounds := s.Box.Overlap(s.Overlap) + groupBoxes := map[m.Position]m.Box{} + for _, area := range areas { + if !selectedBounds.Contains(area.Box) { + continue + } + groupPos := area.Box.GroupPos() + groupBox := m.Box{ + MinPos: groupPos, + MaxPos: m.NewPosition( + groupPos.Lat()+float64(ms.GROUP_AREA_BOX_DEGREES), + groupPos.Lon()+float64(ms.GROUP_AREA_BOX_DEGREES), + ), + } + groupBoxes[groupPos] = groupBox.Overlap(s.Overlap) + } + + groupWays := make(map[m.Position][]int, len(groupBoxes)) + sharedWays := []int{} + for wayIndex, way := range scannedWays { + var matchedGroup m.Position + matched := false + shared := false + for groupPos, groupBox := range groupBoxes { + if way.Box.Overlapping(groupBox) { + if matched { + shared = true + break + } + matchedGroup = groupPos + matched = true + } + } + if shared { + sharedWays = append(sharedWays, wayIndex) + } else if matched { + groupWays[matchedGroup] = append(groupWays[matchedGroup], wayIndex) + } + } + return groupWays, sharedWays, true +} + func GenerateOffline(s OfflineSettings) { slog.Info("Generating Offline Map") EnsureOfflineMapsDirectories(s) @@ -199,9 +260,10 @@ func GenerateOffline(s OfflineSettings) { } } + overlapBox := s.Box.Overlap(s.Overlap) + groupWays, sharedWays, bucketed := bucketWaysByAreaGroup(scannedWays, areas, s) slog.Info("Finding Bounds") for _, area := range areas { - overlapBox := s.Box.Overlap(s.Overlap) if !overlapBox.Contains(area.Box) { continue } @@ -223,11 +285,32 @@ func GenerateOffline(s OfflineSettings) { panic("unexpected capnp error, exiting") } - for _, way := range scannedWays { - - overlaps := way.Box.Overlapping(area.OverlapBox(s.Overlap)) - if overlaps { - area.Ways = append(area.Ways, way) + areaOverlapBox := area.OverlapBox(s.Overlap) + if bucketed { + groupCandidates := groupWays[area.Box.GroupPos()] + groupIndex := 0 + sharedIndex := 0 + for groupIndex < len(groupCandidates) || sharedIndex < len(sharedWays) { + wayIndex := 0 + if sharedIndex >= len(sharedWays) || (groupIndex < len(groupCandidates) && groupCandidates[groupIndex] < sharedWays[sharedIndex]) { + wayIndex = groupCandidates[groupIndex] + groupIndex++ + } else { + wayIndex = sharedWays[sharedIndex] + sharedIndex++ + } + way := scannedWays[wayIndex] + overlaps := way.Box.Overlapping(areaOverlapBox) + if overlaps { + area.Ways = append(area.Ways, way) + } + } + } else { + for _, way := range scannedWays { + overlaps := way.Box.Overlapping(areaOverlapBox) + if overlaps { + area.Ways = append(area.Ways, way) + } } } From ee050cd9ef87b61969f29cb519d00bb4f554799b Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:24:33 -0700 Subject: [PATCH 2/3] Use plain math import in offline generation --- maps/generate_offline.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/maps/generate_offline.go b/maps/generate_offline.go index 3319e71..42ab529 100644 --- a/maps/generate_offline.go +++ b/maps/generate_offline.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "log/slog" - stdmath "math" + "math" "os" "runtime" "strconv" @@ -108,15 +108,15 @@ func generateAreas() []Area { } func canBucketWay(way TmpWay) bool { - return !stdmath.IsNaN(way.Box.MinPos.Lat()) && !stdmath.IsNaN(way.Box.MinPos.Lon()) && - !stdmath.IsNaN(way.Box.MaxPos.Lat()) && !stdmath.IsNaN(way.Box.MaxPos.Lon()) && - !stdmath.IsInf(way.Box.MinPos.Lat(), 0) && !stdmath.IsInf(way.Box.MinPos.Lon(), 0) && - !stdmath.IsInf(way.Box.MaxPos.Lat(), 0) && !stdmath.IsInf(way.Box.MaxPos.Lon(), 0) && + return !math.IsNaN(way.Box.MinPos.Lat()) && !math.IsNaN(way.Box.MinPos.Lon()) && + !math.IsNaN(way.Box.MaxPos.Lat()) && !math.IsNaN(way.Box.MaxPos.Lon()) && + !math.IsInf(way.Box.MinPos.Lat(), 0) && !math.IsInf(way.Box.MinPos.Lon(), 0) && + !math.IsInf(way.Box.MaxPos.Lat(), 0) && !math.IsInf(way.Box.MaxPos.Lon(), 0) && way.Box.MinPos.Lat() <= way.Box.MaxPos.Lat() && way.Box.MinPos.Lon() <= way.Box.MaxPos.Lon() } func bucketWaysByAreaGroup(scannedWays []TmpWay, areas []Area, s OfflineSettings) (map[m.Position][]int, []int, bool) { - if s.Overlap < 0 || stdmath.IsNaN(s.Overlap) || stdmath.IsInf(s.Overlap, 0) { + if s.Overlap < 0 || math.IsNaN(s.Overlap) || math.IsInf(s.Overlap, 0) { return nil, nil, false } for _, way := range scannedWays { From e45faaa1b2fe4cd82160340670962aa44e9ae4bd Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sun, 9 Aug 2026 07:24:58 -0700 Subject: [PATCH 3/3] Declare merged way index without a redundant initializer --- maps/generate_offline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps/generate_offline.go b/maps/generate_offline.go index 42ab529..502ced9 100644 --- a/maps/generate_offline.go +++ b/maps/generate_offline.go @@ -291,7 +291,7 @@ func GenerateOffline(s OfflineSettings) { groupIndex := 0 sharedIndex := 0 for groupIndex < len(groupCandidates) || sharedIndex < len(sharedWays) { - wayIndex := 0 + var wayIndex int if sharedIndex >= len(sharedWays) || (groupIndex < len(groupCandidates) && groupCandidates[groupIndex] < sharedWays[sharedIndex]) { wayIndex = groupCandidates[groupIndex] groupIndex++