diff --git a/maps/way.go b/maps/way.go index 3c923b6..ebb55ef 100644 --- a/maps/way.go +++ b/maps/way.go @@ -241,6 +241,16 @@ func (w *Way) MaxSpeedBackward() float64 { return w.maxSpeedBackward.Value(w._maxSpeedBackward) } +func (w *Way) MaxSpeedForDirection(isForward bool) float64 { + maxSpeed := w.MaxSpeed() + if isForward && w.MaxSpeedForward() > 0 { + maxSpeed = w.MaxSpeedForward() + } else if !isForward && w.MaxSpeedBackward() > 0 { + maxSpeed = w.MaxSpeedBackward() + } + return maxSpeed +} + func (w *Way) _maxSpeedConditional() string { msc, err := w.Way.MaxSpeedConditional() if err != nil { diff --git a/speed_limit.go b/speed_limit.go index 71619ca..2a03fd6 100644 --- a/speed_limit.go +++ b/speed_limit.go @@ -149,12 +149,7 @@ func ParseMaxSpeed(maxspeed string) float64 { } func checkWayForSpeedLimitChange(state *State, parent *Upcoming[float32], way maps.NextWayResult) (valid bool, val float32) { - nextMaxSpeed := way.Way.MaxSpeed() - if way.IsForward && way.Way.MaxSpeedForward() > 0 { - nextMaxSpeed = way.Way.MaxSpeedForward() - } else if !way.IsForward && way.Way.MaxSpeedBackward() > 0 { - nextMaxSpeed = way.Way.MaxSpeedBackward() - } + nextMaxSpeed := way.Way.MaxSpeedForDirection(way.IsForward) if ms.Settings.ConditionalSpeedLimitControlEnabled { rules := way.Way.ConditionalSpeedRules(way.IsForward) if conditional := maps.ConditionalSpeedAt(rules, time.Now()); conditional > 0 { diff --git a/way.go b/way.go index 204ab06..c3612d6 100644 --- a/way.go +++ b/way.go @@ -12,7 +12,6 @@ import ( "pfeifer.dev/mapd/maps" m "pfeifer.dev/mapd/math" ms "pfeifer.dev/mapd/settings" - "pfeifer.dev/mapd/utils" ) type WayCandidate struct { @@ -35,21 +34,10 @@ type CurrentWay struct { LastChangeTime time.Time StableDistance float32 SelectionType custom.WaySelectionType - maxSpeed utils.Curry[float64] -} - -func (w *CurrentWay) _maxSpeed() float64 { - maxSpeed := w.Way.MaxSpeed() - if w.OnWay.IsForward && w.Way.MaxSpeedForward() > 0 { - maxSpeed = w.Way.MaxSpeedForward() - } else if !w.OnWay.IsForward && w.Way.MaxSpeedBackward() > 0 { - maxSpeed = w.Way.MaxSpeedBackward() - } - return maxSpeed } func (w *CurrentWay) MaxSpeed() float64 { - return w.maxSpeed.Value(w._maxSpeed) + return w.Way.MaxSpeedForDirection(w.OnWay.IsForward) } // the raw maxspeed:conditional tag for the direction of travel