From dffb4b0275b4350d65505ac4b5b08b1ef6142081 Mon Sep 17 00:00:00 2001 From: Eloi Charpentier Date: Thu, 24 Oct 2024 15:25:52 +0200 Subject: [PATCH] core: clean up chunk path naming and comments Signed-off-by: Eloi Charpentier 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> --- .../osrd/sim_infra/impl/PathPropertiesImpl.kt | 27 ++++++++++++++----- .../sncf/osrd/standalone_sim/SafetySpeed.kt | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt index de2e3c592b4..96a4af4165e 100644 --- a/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt +++ b/core/kt-osrd-sim-infra/src/main/kotlin/fr/sncf/osrd/sim_infra/impl/PathPropertiesImpl.kt @@ -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, + + /** + * 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, + + /** + * 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 ) { val length: Distance = endOffset.distance - beginOffset.distance @@ -312,22 +327,22 @@ fun buildChunkPath( pathEndOffset: Offset ): ChunkPath { val filteredChunks = mutableDirStaticIdxArrayListOf() - var totalBlocksLength = Offset(0.meters) + var totalChunksLength = Offset(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) } diff --git a/core/src/main/java/fr/sncf/osrd/standalone_sim/SafetySpeed.kt b/core/src/main/java/fr/sncf/osrd/standalone_sim/SafetySpeed.kt index a40b1cadc94..e518d0ac84f 100644 --- a/core/src/main/java/fr/sncf/osrd/standalone_sim/SafetySpeed.kt +++ b/core/src/main/java/fr/sncf/osrd/standalone_sim/SafetySpeed.kt @@ -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