-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c698611
commit c7ca72f
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
constraints/src/main/java/gov/nasa/jpl/aerie/constraints/tree/SpansSelectWhenTrue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gov.nasa.jpl.aerie.constraints.tree; | ||
|
||
import gov.nasa.jpl.aerie.constraints.model.EvaluationEnvironment; | ||
import gov.nasa.jpl.aerie.constraints.model.SimulationResults; | ||
import gov.nasa.jpl.aerie.constraints.time.Interval; | ||
import gov.nasa.jpl.aerie.constraints.time.Spans; | ||
import gov.nasa.jpl.aerie.constraints.time.Windows; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
|
||
public record SpansSelectWhenTrue(Expression<Spans> spans, Expression<Windows> windows) implements Expression<Spans> { | ||
|
||
@Override | ||
public Spans evaluate(SimulationResults results, final Interval bounds, EvaluationEnvironment environment) { | ||
final var spans = this.spans.evaluate(results, bounds, environment); | ||
final var windows = this.windows.evaluate(results, bounds, environment); | ||
final var trueSegments = new ArrayList<Interval>(); | ||
for (final var window: windows.iterateEqualTo(true)) trueSegments.add(window); | ||
return spans.select(trueSegments.toArray(new Interval[] {})); | ||
} | ||
|
||
@Override | ||
public void extractResources(final Set<String> names) { | ||
this.spans.extractResources(names); | ||
this.windows.extractResources(names); | ||
} | ||
|
||
@Override | ||
public String prettyPrint(final String prefix) { | ||
return String.format( | ||
"\n%s(spans-select-when-true %s %s)", | ||
prefix, | ||
this.spans.prettyPrint(prefix + " "), | ||
this.windows.prettyPrint(prefix + " ") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters