Skip to content

Commit 6a7ce9f

Browse files
committed
core: stdcm: fix how we access the next stop duration
1 parent 9ef2f11 commit 6a7ce9f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMEdge.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ data class STDCMEdge(
110110
)
111111
} else {
112112
// New edge on the same block, after a stop
113-
val stopDuration = graph.steps[waypointIndex + 1].duration!!
113+
val stopDuration = graph.getFirstStopAfterIndex(waypointIndex)!!.duration!!
114114
STDCMNode(
115115
totalTime + timeStart + stopDuration,
116116
endSpeed,

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMEdgeBuilder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ internal constructor(
224224
getStopOnBlock(graph, infraExplorer.getCurrentBlock(), startOffset, waypointIndex) !=
225225
null
226226
if (!endAtStop) return null
227-
return graph.steps[waypointIndex + 1].duration!!
227+
return graph.getFirstStopAfterIndex(waypointIndex)!!.duration!!
228228
}
229229

230230
/** Creates a single STDCM edge, adding the given amount of delay */

core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt

+8
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,12 @@ class STDCMGraph(
106106
}
107107
return res
108108
}
109+
110+
/** Returns the first step with a stop after the given index, if any. */
111+
fun getFirstStopAfterIndex(i: Int): STDCMStep? {
112+
return steps
113+
.withIndex()
114+
.firstOrNull { it.index > i && it.value.stop }
115+
?.value
116+
}
109117
}

0 commit comments

Comments
 (0)