scoop:scoop.surface:0.1.0
src/shared/animation/segment.scoop
Selected production source · src/shared/animation/segment.scoop
1
package scoop.surface3
import scoop.platform.time.MonotonicInstant4
import scoop.math.ceil5
import scoop.time.*7
/** A fixed origin and optional finite end; hiding never changes either. */8
internal class AnimationSegment(val run: MotionRun, val start: MonotonicInstant) {9
val deadline: MonotonicInstant? =10
when (run.duration) {11
case Some(val seconds) -> Some(start + animationDuration(seconds))12
case None -> None13
}14
}16
private fun animationDuration(seconds: Double): Duration {17
requireAnimation(18
seconds.isFinite() && seconds >= 0.0 && seconds < 9223372036854775808.0,19
"animation deadline overflow"20
)21
val whole = seconds.toLong()22
val nanos = ceil((seconds - whole.toDouble()) * 1000000000.0).toLong()23
val result = Duration.seconds(whole, nanos)24
return if (durationSeconds(result) < seconds)25
result + Duration.nanoseconds(1L)26
else27
result28
}