Skip to content

Commit

Permalink
core: clean up chunk path naming and comments
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi Charpentier <eloi.charpentier.42@gmail.com>

Update core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt

Co-authored-by: Alwenn Charpentier <104149586+Erashin@users.noreply.github.com>

Update core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt

Co-authored-by: Alwenn Charpentier <104149586+Erashin@users.noreply.github.com>

Update core/src/main/java/fr/sncf/osrd/standalone_sim/SafetySpeed.kt

Co-authored-by: Alwenn Charpentier <104149586+Erashin@users.noreply.github.com>
  • Loading branch information
eckter and Erashin committed Oct 24, 2024
1 parent 2c78a8e commit dffb4b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@ import fr.sncf.osrd.utils.units.meters
* offset on the first chunk, and endOffset on the last chunk. *
*/
data class ChunkPath(
/**
* Ordered list of chunks on the path. Chunks that are fully outside the path are trimmed. Note:
* when the path starts or ends precisely at the border between two chunks, the extra bordering
* chunks are included. But code that uses this class should ideally work with either version.
*/
val chunks: DirStaticIdxList<TrackChunk>,

/**
* Offset of the head of the train when it starts its path, compared to the start of the first
* element in `chunks`.
*/
val beginOffset: Offset<Path>,

/**
* Offset of the head of the train when it ends its path, compared to the start of the first
* element in `chunks`.
*/
val endOffset: Offset<Path>
) {
val length: Distance = endOffset.distance - beginOffset.distance
Expand Down Expand Up @@ -312,22 +327,22 @@ fun buildChunkPath(
pathEndOffset: Offset<Path>
): ChunkPath {
val filteredChunks = mutableDirStaticIdxArrayListOf<TrackChunk>()
var totalBlocksLength = Offset<Path>(0.meters)
var totalChunksLength = Offset<Path>(0.meters)
var mutBeginOffset = pathBeginOffset
var mutEndOffset = pathEndOffset
for (dirChunkId in chunks) {
if (totalBlocksLength > pathEndOffset) break
if (totalChunksLength > pathEndOffset) break
val length = infra.getTrackChunkLength(dirChunkId.value)
val blockEndOffset = totalBlocksLength + length.distance
val chunkEndOffset = totalChunksLength + length.distance

// if the block ends before the path starts, it can be safely skipped
if (pathBeginOffset > blockEndOffset) {
// if the chunk ends before the path starts, it can be safely skipped
if (pathBeginOffset > chunkEndOffset) {
mutBeginOffset -= length.distance
mutEndOffset -= length.distance
} else {
filteredChunks.add(dirChunkId)
}
totalBlocksLength += length.distance
totalChunksLength += length.distance
}
return ChunkPath(filteredChunks, mutBeginOffset, mutEndOffset)
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fun getRoutePathStartOffset(
var firstChunk = chunkPath.chunks[0]
var firstChunkLength = infra.getTrackChunkLength(firstChunk.value)
if (firstChunkLength == chunkPath.beginOffset && chunkPath.chunks.size > 1) {
// If the path start precisely at the end of the first chunk, it may not be present in the
// If the path starts precisely at the end of the first chunk, it may not be present in the
// route path. We can look for the next chunk instead.
firstChunk = chunkPath.chunks[1]
prevChunksLength += firstChunkLength.distance
Expand Down

0 comments on commit dffb4b0

Please sign in to comment.