Skip to content

Commit

Permalink
core: stdcm: fix Offset<Path> conversion when route has previous blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <[email protected]>
  • Loading branch information
eckter committed Jan 15, 2025
1 parent cf771fa commit 28c157d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private fun findConflictOffsets(
edges: List<STDCMEdge>,
updatedTimeData: TimeData,
): Offset<TravelledPath>? {
val startOffset = edges[0].envelopeStartOffset
val startOffset = edges[0].fromTravelledOffset(Offset(0.meters))
val endOffset =
startOffset +
Distance(
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMEdge.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.sncf.osrd.stdcm.graph

import fr.sncf.osrd.sim_infra.api.Block
import fr.sncf.osrd.sim_infra.api.Path
import fr.sncf.osrd.sim_infra.api.TravelledPath
import fr.sncf.osrd.stdcm.infra_exploration.InfraExplorerWithEnvelope
import fr.sncf.osrd.utils.units.Length
import fr.sncf.osrd.utils.units.Offset
Expand All @@ -17,6 +19,7 @@ data class STDCMEdge(
// Node located at the start of this edge
val previousNode: STDCMNode,
// Offset of the envelope if it doesn't start at the beginning of the edge
// This can *not* be used to convert Path / TravelledPath (should reference start of 1st route)
val envelopeStartOffset: Offset<Block>,
// Index of the last waypoint passed by this train
val waypointIndex: Int,
Expand Down Expand Up @@ -143,4 +146,20 @@ data class STDCMEdge(
fun blockOffsetFromEdge(edgeOffset: Offset<STDCMEdge>): Offset<Block> {
return envelopeStartOffset + edgeOffset.distance
}

/**
* Converts from Path Offset (references start of first route) to Travelled path offset
* (references train departure point)
*/
fun toTravelledOffset(pathOffset: Offset<Path>): Offset<TravelledPath> {
return infraExplorer.getIncrementalPath().toTravelledPath(pathOffset)
}

/**
* Converts from Travelled path offset (references train departure point) to Path Offset
* (references start of first route)
*/
fun fromTravelledOffset(travelledPathOffset: Offset<TravelledPath>): Offset<Path> {
return infraExplorer.getIncrementalPath().fromTravelledPath(travelledPathOffset)
}
}

0 comments on commit 28c157d

Please sign in to comment.