From def58485c319e3c5b68ad29e2ad2bb6ff3293294 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Sat, 8 Aug 2026 16:36:30 -0700 Subject: [PATCH] Preserve OSM one-way direction during generation --- maps/generate_offline.go | 19 ++++++++++++++++++- maps/way.go | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/maps/generate_offline.go b/maps/generate_offline.go index 19d37a3..4fad079 100644 --- a/maps/generate_offline.go +++ b/maps/generate_offline.go @@ -7,6 +7,7 @@ import ( "math" "os" "runtime" + "slices" "strconv" "strings" @@ -115,6 +116,22 @@ func generateAreas() []Area { return areas } +func normalizeWayDirection(tags map[string]string, way *TmpWay) { + switch tags["oneway"] { + case "yes", "1": + way.OneWay = true + case "-1": + way.OneWay = true + slices.Reverse(way.Nodes) + way.MaxSpeedForward, way.MaxSpeedBackward = way.MaxSpeedBackward, way.MaxSpeedForward + way.MaxSpeedForwardConditional, way.MaxSpeedBackwardConditional = way.MaxSpeedBackwardConditional, way.MaxSpeedForwardConditional + case "": + way.OneWay = tags["junction"] == "roundabout" || tags["highway"] == "motorway" + default: + way.OneWay = false + } +} + func GenerateOffline(s OfflineSettings) { slog.Info("Generating Offline Map") EnsureOfflineMapsDirectories(s) @@ -160,7 +177,6 @@ func GenerateOffline(s OfflineSettings) { MaxSpeedBackward: ParseMaxSpeed(tags["maxspeed:backward"]), MaxSpeedAdvisory: ParseMaxSpeed(tags["maxspeed:advisory"]), Lanes: uint8(lanes), - OneWay: tags["oneway"] == "yes", Id: int64(way.ID), HighwayClass: HighwayClassFromTag(tags["highway"]), @@ -190,6 +206,7 @@ func GenerateOffline(s OfflineSettings) { tmpWay.Nodes[i].Latitude = n.Lat tmpWay.Nodes[i].Longitude = n.Lon } + normalizeWayDirection(tags, &tmpWay) tmpWay.Box.MinPos = m.NewPosition(minLat, minLon) tmpWay.Box.MaxPos = m.NewPosition(maxLat, maxLon) if minLat < allMinLat { diff --git a/maps/way.go b/maps/way.go index 62c2b11..f44cdcc 100644 --- a/maps/way.go +++ b/maps/way.go @@ -140,6 +140,9 @@ func (w *Way) IsForwardFrom(matchNode m.Position) bool { } lastNode := nodes[len(nodes)-1] + if nodes[0].Equals(lastNode) && lastNode.Equals(matchNode) && w.OneWay() { + return true + } return !lastNode.Equals(matchNode) }