diff --git a/constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/RollingThreshold.java b/constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/RollingThreshold.java index 4dfe965cce..2c01d07d68 100644 --- a/constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/RollingThreshold.java +++ b/constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/RollingThreshold.java @@ -88,12 +88,10 @@ public ConstraintResult evaluate(SimulationResults results, final Interval bound } } if (this.algorithm == RollingThresholdAlgorithm.ExcessHull || this.algorithm == RollingThresholdAlgorithm.DeficitHull) { - final var hull = Interval.between( - violationIntervals.get(0).start, - violationIntervals.get(0).startInclusivity, - violationIntervals.get(violationIntervals.size() - 1).end, - violationIntervals.get(violationIntervals.size() - 1).endInclusivity - ); + var hull = violationIntervals.get(0); + for (final var interval: violationIntervals.subList(1, violationIntervals.size())) { + hull = Interval.unify(hull, interval); + } violationIntervals.clear(); violationIntervals.add(hull); } diff --git a/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java b/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java index e5a49edba2..c6ac01d3cf 100644 --- a/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java +++ b/constraints/src/test/java/gov/nasa/jpl/aerie/constraints/tree/ASTTests.java @@ -1137,9 +1137,10 @@ public void testRollingThresholdExcess() { ); final var spans = new Spans( + // These two are out of order to make sure RollingThreshold's hull operation correctly handles unsorted spans. + Interval.between(4, 5, SECONDS), Interval.between(0, 1, SECONDS), Interval.between(2, 3, SECONDS), - Interval.between(4, 5, SECONDS), Interval.between(14, 15, SECONDS), Interval.between(16, 17, SECONDS), @@ -1174,9 +1175,9 @@ public void testRollingThresholdExcess() { List.of( new Violation( List.of( + Interval.between(4, 5, SECONDS), Interval.between(0, 1, SECONDS), - Interval.between(2, 3, SECONDS), - Interval.between(4, 5, SECONDS) + Interval.between(2, 3, SECONDS) ), List.of() ), new Violation(