Motion-curve quality assurance and deterministic timeline compilation for MoonBit
let smoothstep = fn(t : Double) -> Double { t * t * (3.0 - 2.0 * t) }
let policy = @motion.CurvePolicy::strict()
let result = @motion.check(smoothstep, 120, policy)
let timeline = @motion.MotionTimeline::new()
timeline.append(0.0, 100.0, 0.6, smoothstep)
timeline.append(100.0, 160.0, 0.4, smoothstep)
let frames = timeline.frames(60)let selected_curve = fn(t : Double) -> Double { /* invoke an external easing function */ t }
let report = @motion.profile(selected_curve, 120)moon fmt --check
moon check
moon test
moon build
moon run ./examples/basictype MotionFn = (Double) -> Doublepub struct CurveCheck {
report : CurveReport
overshoot : Double
endpoints_ok : Bool
monotonic_ok : Bool
overshoot_ok : Bool
speed_ok : Bool
passed : Bool
}pub struct CurvePolicy {
endpoint_tolerance : Double
require_monotonic : Bool
max_overshoot : Double
max_speed : Double
}pub struct CurveReport {
min_value : Double
max_value : Double
max_speed : Double
time_of_max_speed : Double
monotonic : Bool
endpoint_error : Double
}pub struct MotionSegment {
start : Double
end : Double
duration : Double
motion : (Double) -> Double
}fn MotionTimeline::append(self : MotionTimeline, start : Double, end : Double, duration : Double, motion : (Double) -> Double) -> Unitfn clamp01(value : Double) -> Doublefn interpolate(start : Double, end : Double, t : Double, motion : (Double) -> Double) -> Doublefn is_monotonic(motion : (Double) -> Double, samples : Int) -> Boolfn max_overshoot(motion : (Double) -> Double, samples : Int) -> Doublefn stitch(first : (Double) -> Double, second : (Double) -> Double, split : Double) -> ((Double) -> Double)fn velocity(motion : (Double) -> Double, t : Double, epsilon : Double) -> DoubleInstall
Download zipMotion-curve quality assurance and deterministic timeline compilation for MoonBit