Skip to content

Commit

Permalink
core: improve MRSP code a bit after migration to kotlin
Browse files Browse the repository at this point in the history
after #8599
IDEA suggested a few improvements

Signed-off-by: Pierre-Etienne Bougué <[email protected]>
  • Loading branch information
bougue-pe authored and Khoyo committed Nov 19, 2024
1 parent e0ec0fc commit e00920e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import fr.sncf.osrd.sim_infra.api.RawSignalingInfra
import fr.sncf.osrd.utils.DistanceRangeMap
import fr.sncf.osrd.utils.buildElectrificationMap
import fr.sncf.osrd.utils.units.Distance.Companion.toMeters
import java.util.function.BiFunction

object EnvelopeTrainPath {
/** Create EnvelopePath from a path and a ElectricalProfileMapping */
Expand Down Expand Up @@ -59,13 +58,12 @@ object EnvelopeTrainPath {
val res = mutableMapOf<String, DistanceRangeMap<Electrification>>()
for (entry in profileMap.entries) {
val electrificationMapWithProfiles = electrificationMap.clone()
electrificationMapWithProfiles.updateMap<String>(
entry.value,
BiFunction { obj: Electrification, profile: String ->
obj.withElectricalProfile(profile)
}
)
res.put(entry.key, electrificationMapWithProfiles)
electrificationMapWithProfiles.updateMap(entry.value) {
obj: Electrification,
profile: String ->
obj.withElectricalProfile(profile)
}
res[entry.key] = electrificationMapWithProfiles
}
return res
}
Expand All @@ -76,9 +74,9 @@ object EnvelopeTrainPath {
): ImmutableRangeMap<Double, Electrification> {
val res = TreeRangeMap.create<Double, Electrification>()
for (entry in map.asList()) {
res.put(Range.closed<Double>(toMeters(entry.lower), toMeters(entry.upper)), entry.value)
res.put(Range.closed(toMeters(entry.lower), toMeters(entry.upper)), entry.value)
}
return ImmutableRangeMap.copyOf<Double, Electrification>(res)
return ImmutableRangeMap.copyOf(res)
}

/** Converts an ElectrificationMapByPowerClass as a DistanceRangeMap into a RangeMap */
Expand All @@ -87,7 +85,7 @@ object EnvelopeTrainPath {
): Map<String, ImmutableRangeMap<Double, Electrification>> {
val res = mutableMapOf<String, ImmutableRangeMap<Double, Electrification>>()
for (entry in electrificationMapByPowerClass.entries) {
res.put(entry.key, convertElectrificationMap(entry.value))
res[entry.key] = convertElectrificationMap(entry.value)
}
return res
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/kotlin/fr/sncf/osrd/envelope_sim_infra/MRSP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ fun computeMRSP(
attrs.add(speedLimitProp.source)
}
if (attrs.any { it is UnknownTag }) attrs.add(HasMissingSpeedTag)
if (speed != 0.0) // Add the envelope part corresponding to the restricted speed section
if (speed != 0.0) {
// Add the envelope part corresponding to the restricted speed section
builder.addPart(
EnvelopePart.generateTimes(
attrs,
doubleArrayOf(start, end),
doubleArrayOf(speed, speed)
)
)
}
}

// Add a limit corresponding to the hardware's maximum operational speed
Expand Down

0 comments on commit e00920e

Please sign in to comment.