1
1
package fr.sncf.osrd.sim_infra.impl
2
2
3
3
import fr.sncf.osrd.geom.LineString
4
- import fr.sncf.osrd.sim_infra.api.*
4
+ import fr.sncf.osrd.sim_infra.api.DirTrackChunkId
5
+ import fr.sncf.osrd.sim_infra.api.IdxWithOffset
6
+ import fr.sncf.osrd.sim_infra.api.LoadingGaugeConstraint
7
+ import fr.sncf.osrd.sim_infra.api.OperationalPointPart
8
+ import fr.sncf.osrd.sim_infra.api.PathProperties
9
+ import fr.sncf.osrd.sim_infra.api.TrackChunk
10
+ import fr.sncf.osrd.sim_infra.api.TrackChunkId
11
+ import fr.sncf.osrd.sim_infra.api.TrackLocation
12
+ import fr.sncf.osrd.sim_infra.api.TrackProperties
5
13
import fr.sncf.osrd.utils.Direction
6
14
import fr.sncf.osrd.utils.DistanceRangeMap
7
15
import fr.sncf.osrd.utils.distanceRangeMapOf
8
16
import fr.sncf.osrd.utils.indexing.DirStaticIdxList
9
17
import fr.sncf.osrd.utils.units.Distance
18
+ import fr.sncf.osrd.utils.units.Offset
19
+ import fr.sncf.osrd.utils.units.Speed
10
20
import fr.sncf.osrd.utils.units.meters
11
- import java.lang.RuntimeException
12
21
13
22
data class PathPropertiesImpl (
14
23
val infra : TrackProperties ,
15
- val chunks : DirStaticIdxList <TrackChunk >,
24
+ override val chunks : DirStaticIdxList <TrackChunk >,
16
25
@get:JvmName("getBeginOffset")
17
- val beginOffset : Distance ,
26
+ override val beginOffset : Distance ,
18
27
@get:JvmName("getEndOffset")
19
28
val endOffset : Distance ,
20
29
) : PathProperties {
@@ -53,6 +62,10 @@ data class PathPropertiesImpl(
53
62
return getRangeMap { dirChunkId -> infra.getTrackChunkNeutralSections(dirChunkId) }
54
63
}
55
64
65
+ override fun getSpeedLimits (trainTag : String? ): DistanceRangeMap <Speed > {
66
+ return getRangeMap { dirChunkId -> infra.getTrackChunkSpeedSections(dirChunkId, trainTag) }
67
+ }
68
+
56
69
override fun getLength (): Distance {
57
70
return endOffset - beginOffset
58
71
}
@@ -67,15 +80,26 @@ data class PathPropertiesImpl(
67
80
val startChunkOffset = infra.getTrackChunkOffset(chunk.value).distance
68
81
val offsetOnChunk = offset - lengthPrevChunks
69
82
return if (chunk.direction == Direction .INCREASING )
70
- TrackLocation (trackId, offsetOnChunk + startChunkOffset)
83
+ TrackLocation (trackId, Offset ( offsetOnChunk + startChunkOffset) )
71
84
else
72
- TrackLocation (trackId, startChunkOffset + chunkLength - offsetOnChunk)
85
+ TrackLocation (trackId, Offset ( startChunkOffset + chunkLength - offsetOnChunk) )
73
86
}
74
87
lengthPrevChunks + = chunkLength
75
88
}
76
89
throw RuntimeException (" The given path offset is larger than the path length" )
77
90
}
78
91
92
+ override fun getElectricalProfiles (mapping : HashMap <String , DistanceRangeMap <String >>): DistanceRangeMap <String > {
93
+ return getRangeMapFromUndirected { chunkId -> infra.getTrackChunkElectricalProfile(chunkId, mapping) }
94
+ }
95
+
96
+ override fun getTrackLocationOffset (location : TrackLocation ): Distance ? {
97
+ val offset = getOffsetOfTrackLocationOnChunks(infra, location, chunks) ? : return null
98
+ if (offset < beginOffset || offset > endOffset)
99
+ return null
100
+ return offset - beginOffset
101
+ }
102
+
79
103
private fun projectLineString (getData : (chunkId: TrackChunkId ) -> LineString ): LineString {
80
104
fun getDirData (dirChunkId : DirTrackChunkId ): LineString {
81
105
val data = getData(dirChunkId.value)
@@ -201,3 +225,37 @@ data class PathPropertiesImpl(
201
225
return res
202
226
}
203
227
}
228
+
229
+ /* * Returns the offset of a location on a given list of chunks */
230
+ fun getOffsetOfTrackLocationOnChunks (
231
+ infra : TrackProperties ,
232
+ location : TrackLocation ,
233
+ chunks : DirStaticIdxList <TrackChunk >,
234
+ ): Distance ? {
235
+ var offsetAfterFirstChunk = 0 .meters
236
+ for (dirChunk in chunks) {
237
+ val chunkLength = infra.getTrackChunkLength(dirChunk.value)
238
+ if (location.trackId == infra.getTrackFromChunk(dirChunk.value)) {
239
+ val chunkOffset = infra.getTrackChunkOffset(dirChunk.value)
240
+ if (chunkOffset <= location.offset && location.offset <= (chunkOffset + chunkLength.distance)) {
241
+ val distanceToChunkStart = if (dirChunk.direction == Direction .INCREASING )
242
+ location.offset - chunkOffset
243
+ else
244
+ (chunkOffset + chunkLength.distance) - location.offset
245
+ return offsetAfterFirstChunk + distanceToChunkStart
246
+ }
247
+ }
248
+ offsetAfterFirstChunk + = chunkLength.distance
249
+ }
250
+ return null
251
+ }
252
+
253
+ /* * Returns the offset of a location on a given list of chunks, throws if not found */
254
+ @JvmName(" getOffsetOfTrackLocationOnChunksOrThrow" )
255
+ fun getOffsetOfTrackLocationOnChunksOrThrow (
256
+ infra : TrackProperties ,
257
+ location : TrackLocation ,
258
+ chunks : DirStaticIdxList <TrackChunk >,
259
+ ): Distance {
260
+ return getOffsetOfTrackLocationOnChunks(infra, location, chunks) ? : throw RuntimeException ()
261
+ }
0 commit comments