Skip to content

Commit 6769f32

Browse files
committed
core: paths: add tooling for zone ranges
Signed-off-by: Eloi Charpentier <[email protected]>
1 parent 3420aae commit 6769f32

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

core/kt-osrd-path/src/main/kotlin/fr/sncf/osrd/path/implementations/TrainPathImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ data class TrainPathNoBacktrack(
3434

3535
private val cachedEnvelopeSimPath by lazy { computeEnvelopeSimPath() }
3636

37+
private val cachedZonePaths by lazy {
38+
assert(routes!!.isNotEmpty())
39+
mapSubObjects(routes, rawInfra::getRoutePath, rawInfra::getZonePathLength)
40+
}
41+
3742
init {
3843
// The sanity checks here are quite exhaustive and might be expensive to compute.
3944
// Once the path types are stable, we can remove some of the tests.
@@ -86,6 +91,8 @@ data class TrainPathNoBacktrack(
8691

8792
override fun getChunks(): List<DirChunkRange> = chunks
8893

94+
override fun getZonePaths(): List<ZonePathRange> = cachedZonePaths
95+
8996
override val length: Double
9097
get() = pathProperties.getLength().meters
9198

core/kt-osrd-path/src/main/kotlin/fr/sncf/osrd/path/interfaces/PathProperties.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ sealed interface BlockPath
2828
* A marker type for Length and Offset. In TravelledPath, start refers to the real start of the head
2929
* of the train.
3030
*/
31-
sealed interface TravelledPath
31+
// TODO path migration: remove TravelledPath entirely
32+
typealias TravelledPath = TrainPath
3233

3334
@Suppress("INAPPLICABLE_JVM_NAME")
3435
interface PathProperties {

core/kt-osrd-path/src/main/kotlin/fr/sncf/osrd/path/interfaces/TrainPath.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,19 @@ interface TrainPath : PhysicsPath, PathProperties {
4848
fun getRoutes(): List<RouteRange>
4949

5050
fun getChunks(): List<DirChunkRange>
51+
52+
fun getZonePaths(): List<ZonePathRange>
5153
// To be expanded as needed with other linear objects
5254
}
5355

5456
fun concat(vararg paths: TrainPath): TrainPath {
5557
TODO("Required for actual backtracks, not necessary earlier than that")
5658
}
5759

60+
fun TrainPath.getZones(rawInfra: RawInfra): List<ZoneRange> {
61+
return getZonePaths().map { it.mapValue(rawInfra.getZonePathZone(it.value)) }
62+
}
63+
5864
// Extension functions that help with backward compatibility.
5965
// These should only exist during the migration to enable more local changes,
6066
// to allow partial migration while still having a working core.

core/src/test/kotlin/fr/sncf/osrd/utils/PathUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fun pathFromTracks(
2424
start: Distance,
2525
end: Distance,
2626
electricalProfileMapping: ElectricalProfileMapping? = null,
27+
routeNames: List<String>? = null,
2728
): TrainPath {
2829
val chunkList = mutableDirStaticIdxArrayListOf<TrackChunk>()
2930
trackIds
@@ -36,6 +37,7 @@ fun pathFromTracks(
3637
blockInfra,
3738
chunkPath,
3839
electricalProfileMapping = electricalProfileMapping,
40+
routeNames = routeNames,
3941
)
4042
}
4143

@@ -46,6 +48,7 @@ fun pathFromTracks(
4648
start: Distance,
4749
end: Distance,
4850
electricalProfileMapping: ElectricalProfileMapping? = null,
51+
routeNames: List<String>? = null,
4952
): TrainPath {
5053
return pathFromTracks(
5154
infra.rawInfra,
@@ -55,6 +58,7 @@ fun pathFromTracks(
5558
start,
5659
end,
5760
electricalProfileMapping = electricalProfileMapping,
61+
routeNames = routeNames,
5862
)
5963
}
6064

0 commit comments

Comments
 (0)