Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix identical positions when shifting envelope parts #5432

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static fr.sncf.osrd.envelope.EnvelopePhysics.intersectStepWithSpeed;

import com.carrotsearch.hppc.DoubleArrayList;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import fr.sncf.osrd.envelope.EnvelopeAttr;
import fr.sncf.osrd.envelope.EnvelopePhysics;
Expand Down Expand Up @@ -638,10 +639,26 @@ public EnvelopePart slice(

/** Returns a new EnvelopePart, where all positions are shifted by positionDelta */
public EnvelopePart copyAndShift(double positionDelta) {
var newPositions = new double[positions.length];
for (int i = 0; i < positions.length; i++)
newPositions[i] = positions[i] + positionDelta;
return new EnvelopePart(new HashMap<>(attrs), newPositions, speeds, timeDeltas);
var newPositions = new DoubleArrayList();
var newSpeeds = new DoubleArrayList();
var newTimeDeltas = new DoubleArrayList();
newPositions.add(positions[0] + positionDelta);
newSpeeds.add(speeds[0]);
for (int i = 1; i < positions.length; i++) {
var p = positions[i] + positionDelta;
if (newPositions.get(newPositions.size() - 1) != p) {
// Positions that are an epsilon away may be overlapping after the shift, we only add the distinct ones
newPositions.add(p);
newSpeeds.add(speeds[i]);
newTimeDeltas.add(timeDeltas[i - 1]);
}
}
return new EnvelopePart(
new HashMap<>(attrs),
newPositions.toArray(),
newSpeeds.toArray(),
newTimeDeltas.toArray()
);
}

// endregion
Expand Down