Skip to content

Commit 3e7c548

Browse files
committed
front: drop last step auto 0ms stop on reverse
Signed-off-by: Alice Khoudli <alice.khoudli@polytechnique.org>
1 parent 1d21d09 commit 3e7c548

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

front/src/modules/pathfinding/helpers/__tests__/reversePathSteps.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('reversePathSteps', () => {
101101
},
102102
name: 'Carantilly-Marigny',
103103
arrival: null,
104-
stopFor: new Duration({ milliseconds: 0 }),
104+
stopFor: null,
105105
locked: false,
106106
receptionSignal: 'OPEN',
107107
theoreticalMargin: '2min/100km',
@@ -178,13 +178,14 @@ describe('reversePathSteps', () => {
178178
...pathStep,
179179
arrival: null,
180180
}));
181+
expectedTwiceReversedPathSteps[pathSteps.length - 1].stopFor = null; // The 0ms stop on the last step will get add back later by another function
181182

182183
it('should reverse path steps with times and margins correctly', () => {
183184
const reversedPathSteps = reversePathSteps(pathSteps);
184185
expect(reversedPathSteps).toEqual(expectedReversedPathSteps);
185186
});
186187

187-
it('should equal itself with arrival times removed when reversed twice', () => {
188+
it('should equal itself with arrival times removed and last step 0ms stop missing when reversed twice', () => {
188189
const twiceReversedPathSteps = reversePathSteps(reversePathSteps(pathSteps));
189190
expect(twiceReversedPathSteps).toEqual(expectedTwiceReversedPathSteps);
190191
});

front/src/modules/pathfinding/helpers/reversePathSteps.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ function reversePathSteps(pathSteps: PathStep[]): PathStep[] {
2222
});
2323

2424
return pathSteps
25-
.map((pathStep, index) => ({
26-
...pathStep,
27-
arrival: null, // Remove arrival times set as they may become incoherent when reversing
28-
theoreticalMargin: newMargins[index],
29-
}))
25+
.map((pathStep, index) => {
26+
const isLastStepZeroStop = index === pathSteps.length - 1 && pathStep.stopFor?.ms === 0;
27+
return {
28+
...pathStep,
29+
arrival: null, // Remove arrival times set as they may become incoherent when reversing
30+
stopFor: isLastStepZeroStop ? null : pathStep.stopFor, // We automatically insert a 0ms stop on the last step, which should be dropped before reversing
31+
theoreticalMargin: newMargins[index],
32+
};
33+
})
3034
.reverse();
3135
}
3236

0 commit comments

Comments
 (0)