From 5d3a2fc9aadef7aa2d3a66f7ba954a8ea1f4767b Mon Sep 17 00:00:00 2001 From: Eloi Charpentier Date: Fri, 22 Nov 2024 15:37:49 +0100 Subject: [PATCH] core: avoid recomputing unnecessary coastings, which sometimes crashed The forward coasting would sometimes not intersect with the base curve, which causes some weirdness and 0-length steps. That coasting would only happen if there's no intersection with min speed limit. In that case, it's not actually necessary to compute it (it's supposed to give the same result as the backwards one). Signed-off-by: Eloi Charpentier --- .../allowances/mareco_impl/CoastingGenerator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/mareco_impl/CoastingGenerator.java b/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/mareco_impl/CoastingGenerator.java index 4972f587f24..abea924164e 100644 --- a/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/mareco_impl/CoastingGenerator.java +++ b/core/envelope-sim/src/main/java/fr/sncf/osrd/envelope_sim/allowances/mareco_impl/CoastingGenerator.java @@ -67,8 +67,11 @@ public static EnvelopePart coastFromEnd( assert constrainedBuilder.getLastPos() < endPos; - if (!reachedLowLimit && constrainedBuilder.getLastPos() != envelope.getBeginPos()) + if (!reachedLowLimit) { return backwardPartBuilder.build(); + // We only need to recompute a coasting going forward if the low speed limit has been reached, + // as we'd need to add accelerations in places where we've clipped the speed + } var resultCoast = coastFromBeginning( envelope, context, constrainedBuilder.getLastPos(), constrainedBuilder.getLastSpeed());