-
Notifications
You must be signed in to change notification settings - Fork 22
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
a693dcd
commit 1e77abc
Showing
9 changed files
with
105 additions
and
22 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
15 changes: 15 additions & 0 deletions
15
timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/BoundsTransformer.kt
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,15 @@ | ||
package gov.nasa.jpl.aerie.timeline | ||
|
||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration | ||
|
||
fun interface BoundsTransformer { | ||
operator fun invoke(bounds: Interval): Interval | ||
|
||
companion object { | ||
@JvmStatic | ||
val IDENTITY: BoundsTransformer = BoundsTransformer { i -> i } | ||
|
||
@JvmStatic | ||
fun shift(dur: Duration) = BoundsTransformer { i -> i.shiftBy(dur.negate()) } | ||
} | ||
} |
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
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
7 changes: 4 additions & 3 deletions
7
timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SegmentOps.kt
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package gov.nasa.jpl.aerie.timeline.ops | ||
|
||
import gov.nasa.jpl.aerie.timeline.* | ||
import gov.nasa.jpl.aerie.timeline.BoundsTransformer.Companion.IDENTITY | ||
|
||
/** | ||
* Operations mixin for timelines of segments. | ||
*/ | ||
interface SegmentOps<V : Any, P: GeneralOps<Segment<V>, P>>: GeneralOps<Segment<V>, P> { | ||
fun mapValues(f: (Segment<V>) -> V) = map { it.mapValue(f) } | ||
fun <W: Any, TInto: GeneralOps<Segment<W>, TInto>> mapValues(ctor: (TimelineOps<Segment<W>, TInto>) -> TInto, f: (Segment<V>) -> W) = | ||
map(ctor) { it.mapValue(f) } | ||
fun mapValues(f: (Segment<V>) -> V) = map(IDENTITY, false) { it.mapValue(f) } | ||
fun <W: Any, TInto: GeneralOps<Segment<W>, TInto>> mapValues(ctor: (Timeline<Segment<W>, TInto>) -> TInto, f: (Segment<V>) -> W) = | ||
map(ctor, IDENTITY, false) { it.mapValue(f) } | ||
} |
41 changes: 41 additions & 0 deletions
41
timeline/src/main/kotlin/gov/nasa/jpl/aerie/timeline/ops/SerialBooleanOps.kt
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,41 @@ | ||
package gov.nasa.jpl.aerie.timeline.ops | ||
|
||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration | ||
import gov.nasa.jpl.aerie.timeline.BinaryOperation | ||
import gov.nasa.jpl.aerie.timeline.Interval | ||
import gov.nasa.jpl.aerie.timeline.Segment | ||
|
||
/** | ||
* Operations mixin for timelines of booleans. | ||
* | ||
* Currently only used by Windows, but could be used for parallel boolean profiles in the future. | ||
*/ | ||
interface SerialBooleanOps<P: GeneralOps<Segment<Boolean>, P>>: SerialOps<Boolean, P>, BooleanOps<P> { | ||
fun and(other: SerialBooleanOps<P>) = map2Values(other, BinaryOperation.cases( | ||
{ l, _ -> if (l) null else false }, | ||
{ r, _ -> if (r) null else false }, | ||
{ l, r, _ -> l && r } | ||
)) | ||
|
||
fun or(other: SerialBooleanOps<P>) = map2Values(other, BinaryOperation.cases( | ||
{ l, _ -> if (l) true else null }, | ||
{ r, _ -> if (r) true else null }, | ||
{ l, r, _ -> l || r } | ||
)) | ||
|
||
fun shiftEdges(shiftRising: Duration, shiftFalling: Duration = shiftRising) = | ||
mapIntervals( | ||
{ i -> | ||
Interval.between( | ||
Duration.min(i.start.minus(shiftRising), i.start.minus(shiftFalling)), | ||
Duration.max(i.end.minus(shiftRising), i.end.minus(shiftFalling)), | ||
i.startInclusivity, | ||
i.endInclusivity | ||
) | ||
}, | ||
true | ||
) { t -> | ||
if (t.value) t.interval.shiftBy(shiftRising, shiftFalling) | ||
else t.interval.shiftBy(shiftFalling, shiftRising) | ||
} | ||
} |
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