Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions maps/way.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 1 addition & 6 deletions speed_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 1 addition & 13 deletions way.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Loading