diff --git a/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/GeneralOps.kt b/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/GeneralOps.kt index 011f82c356..c11f65f251 100644 --- a/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/GeneralOps.kt +++ b/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/GeneralOps.kt @@ -37,6 +37,14 @@ interface GeneralOps, T: GeneralOps>: Timeline { fun mapIntervals(boundsTransformer: BoundsTransformer, truncate: Boolean, f: (V) -> Interval) = map(boundsTransformer, truncate) { v -> v.changeInterval(f(v)) } fun filter(f: (V) -> Boolean) = BaseTimeline(ctor) { bounds -> collect(bounds).filter(f) }.specialize() + + fun filterByDuration(min: Duration = Duration.MIN_VALUE, max: Duration = Duration.MAX_VALUE) = + filter { v -> + val duration = v.interval.duration() + duration.longerThan(min) && duration.shorterThan(max) + } + fun filterShorterThan(dur: Duration) = filter { v -> v.interval.duration().shorterThan(dur) } + fun filterLongerThan(dur: Duration) = filter { v -> v.interval.duration().longerThan(dur) } fun shiftBy(dur: Duration) = map(BoundsTransformer.shift(dur), false) { v -> v.changeInterval(v.interval.shiftBy(dur)) } diff --git a/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SerialBooleanOps.kt b/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SerialBooleanOps.kt index 067698a225..7f1a7fa028 100644 --- a/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SerialBooleanOps.kt +++ b/timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SerialBooleanOps.kt @@ -38,4 +38,17 @@ interface SerialBooleanOps, P>>: SerialOps + if (s.value) { + val duration = s.interval.duration() + duration.longerThan(min) && duration.shorterThan(max) + } else { + false + } + } + + fun falsifyShorterThan(dur: Duration) = falsifyByDuration(min = dur) + fun falsifyLongerThan(dur: Duration) = falsifyByDuration(max = dur) }