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: return error when allowance ranges are out of bounds #6093

Merged
Merged
Show file tree
Hide file tree
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 @@ -52,6 +52,11 @@ protected AbstractAllowanceWithRanges(
this.endPos = endPos;
this.capacitySpeedLimit = capacitySpeedLimit;
this.ranges = ranges;
for (AllowanceRange range : ranges) {
if (range.beginPos < beginPos || range.endPos > endPos) {
throw new OSRDError(ErrorType.AllowanceRangeOutOfBounds);
}
}
}

protected abstract Envelope computeCore(Envelope base, EnvelopeSimContext context, double parameter);
Expand Down Expand Up @@ -114,6 +119,10 @@ else if (!search.hasLoweredHighBound())
/** Apply the allowance to a given envelope. */
@Override
public Envelope apply(Envelope base, EnvelopeSimContext context) {
if (base.getBeginPos() > beginPos || base.getEndPos() < endPos) {
throw new OSRDError(ErrorType.AllowanceOutOfBounds);
}

assert base.continuous;

// get only the region on which the allowance applies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ public enum ErrorType {
"the path goes over the same track multiple times",
ErrorCause.USER
),
AllowanceRangeOutOfBounds(
"allowance_range",
"Allowance ranges are out of bounds",
ErrorCause.USER
),
AllowanceOutOfBounds(
"allowance",
"Allowance is out of bounds",
ErrorCause.USER
),
;

public final String type;
Expand Down