Skip to content

Commit 887c261

Browse files
flomonsterErashin
authored andcommitted
fixup! core: add last stop in standalone simulation
Signed-off-by: Erashin <[email protected]>
1 parent 3cb81bd commit 887c261

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

core/src/main/java/fr/sncf/osrd/standalone_sim/EnvelopeStopWrapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ public List<EnvelopePoint> iteratePoints() {
9191
double sumPreviousStopDuration = 0;
9292
int stopIndex = 0;
9393
for (var point : envelope.iteratePoints()) {
94+
var shiftedTime = point.time() + sumPreviousStopDuration;
9495
var shiftedPoint =
95-
new EnvelopePoint(point.time() + sumPreviousStopDuration, point.speed(), point.position());
96+
new EnvelopePoint(shiftedTime, point.speed(), point.position());
9697
res.add(shiftedPoint);
9798
if (stopIndex < stops.size() && point.position() >= stops.get(stopIndex).position) {
9899
var stopDuration = stops.get(stopIndex).duration;
100+
res.add(new EnvelopePoint(shiftedTime + stopDuration, point.speed(), point.position()));
99101
stopIndex++;
100102
sumPreviousStopDuration += stopDuration;
101-
res.add(new EnvelopePoint(point.time() + sumPreviousStopDuration, point.speed(), point.position()));
102103
}
103104
}
104105
return res;

core/src/test/java/fr/sncf/osrd/standalone_sim/EnvelopeStopWrapperTests.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,43 @@ public class EnvelopeStopWrapperTests {
1313
@Test
1414
public void iteratePointsWithoutStops() {
1515
var envelopeFloor = Envelope.make(EnvelopeTestUtils.generateTimes(
16-
new double[] {0, 1, 2, 3, 4, 5, 6}, new double[] {1, 1, 1, 1, 1, 1, 1}));
16+
new double[] {0, 1, 2, 3, 4, 5, 6}, new double[] {1, 1, 1, 1, 1, 1, 1}));
1717
var envelopeStopWrapper = new EnvelopeStopWrapper(envelopeFloor, List.of());
1818
Assertions.assertEquals(
19-
List.of(
20-
new EnvelopeTimeInterpolate.EnvelopePoint(0, 1, 0),
21-
new EnvelopeTimeInterpolate.EnvelopePoint(1, 1, 1),
22-
new EnvelopeTimeInterpolate.EnvelopePoint(2, 1, 2),
23-
new EnvelopeTimeInterpolate.EnvelopePoint(3, 1, 3),
24-
new EnvelopeTimeInterpolate.EnvelopePoint(4, 1, 4),
25-
new EnvelopeTimeInterpolate.EnvelopePoint(5, 1, 5),
26-
new EnvelopeTimeInterpolate.EnvelopePoint(6, 1, 6)),
27-
envelopeStopWrapper.iteratePoints());
19+
List.of(
20+
new EnvelopeTimeInterpolate.EnvelopePoint(0, 1, 0),
21+
new EnvelopeTimeInterpolate.EnvelopePoint(1, 1, 1),
22+
new EnvelopeTimeInterpolate.EnvelopePoint(2, 1, 2),
23+
new EnvelopeTimeInterpolate.EnvelopePoint(3, 1, 3),
24+
new EnvelopeTimeInterpolate.EnvelopePoint(4, 1, 4),
25+
new EnvelopeTimeInterpolate.EnvelopePoint(5, 1, 5),
26+
new EnvelopeTimeInterpolate.EnvelopePoint(6, 1, 6)),
27+
envelopeStopWrapper.iteratePoints());
2828
}
2929

3030
@Test
3131
public void iteratePointsWithStops() {
3232
var envelopeFloor = Envelope.make(EnvelopeTestUtils.generateTimes(
33-
new double[] {0, 1, 2, 3, 4, 5, 6}, new double[] {1, 1, 1, 0, 1, 1, 1}));
33+
new double[] {0, 1, 2, 3, 4, 5, 6}, new double[] {1, 1, 1, 0, 1, 1, 1}));
3434
var envelopeStopWrapper = new EnvelopeStopWrapper(
35-
envelopeFloor,
36-
List.of(
37-
new TrainStop(1.5, 0, RJSReceptionSignal.OPEN),
38-
new TrainStop(3, 10, RJSReceptionSignal.SHORT_SLIP_STOP)));
35+
envelopeFloor,
36+
List.of(
37+
new TrainStop(3, 10, RJSReceptionSignal.SHORT_SLIP_STOP),
38+
new TrainStop(6, 5, RJSReceptionSignal.OPEN)
39+
)
40+
);
3941
Assertions.assertEquals(
40-
List.of(
41-
new EnvelopeTimeInterpolate.EnvelopePoint(0, 1, 0),
42-
new EnvelopeTimeInterpolate.EnvelopePoint(1, 1, 1),
43-
new EnvelopeTimeInterpolate.EnvelopePoint(2, 1, 2),
44-
new EnvelopeTimeInterpolate.EnvelopePoint(4, 0, 3),
45-
new EnvelopeTimeInterpolate.EnvelopePoint(6 + 10, 1, 4),
46-
new EnvelopeTimeInterpolate.EnvelopePoint(7 + 10, 1, 5),
47-
new EnvelopeTimeInterpolate.EnvelopePoint(8 + 10, 1, 6)),
48-
envelopeStopWrapper.iteratePoints());
42+
List.of(
43+
new EnvelopeTimeInterpolate.EnvelopePoint(0, 1, 0),
44+
new EnvelopeTimeInterpolate.EnvelopePoint(1, 1, 1),
45+
new EnvelopeTimeInterpolate.EnvelopePoint(2, 1, 2),
46+
new EnvelopeTimeInterpolate.EnvelopePoint(4, 0, 3),
47+
new EnvelopeTimeInterpolate.EnvelopePoint(4 + 10, 0, 3),
48+
new EnvelopeTimeInterpolate.EnvelopePoint(6 + 10, 1, 4),
49+
new EnvelopeTimeInterpolate.EnvelopePoint(7 + 10, 1, 5),
50+
new EnvelopeTimeInterpolate.EnvelopePoint(8 + 10, 1, 6),
51+
new EnvelopeTimeInterpolate.EnvelopePoint(8 + 10 + 5, 1, 6)),
52+
envelopeStopWrapper.iteratePoints().stream().distinct().toList()
53+
);
4954
}
5055
}

0 commit comments

Comments
 (0)