module Reactive.Duration (Duration, updateOnDelay, updateOnVariable
, durationFromID, durationFromConst
, isZeroDuration, maybeConstDur,toConstDur,constDur) where
import Duration.MinMaxAffine
import Duration.Lattice
newtype Duration d i = Duration {fromDuration :: (MinMaxAffine d i)} deriving (Show, Ord, Eq, Fractional, Num, POrd,Lattice)
isZeroDuration :: (Num d, POrd d) => d -> Bool
isZeroDuration d = case (partialCompare 0 d) of
Just EQ -> True
_ -> False
updateOnDelay :: (Num d, Ord d, Ord i) =>
d -> Duration d i -> Duration d i
updateOnDelay d = Duration . updateMinMaxOnDelay d . fromDuration
updateOnVariable :: (Num d, Ord d, Ord i) =>
[i] -> Duration d i -> Duration d i
updateOnVariable l = Duration . updateMinMaxOnVariable l . fromDuration
durationFromID :: (Num d) => i -> Duration d i
durationFromID i = Duration $ varDur i
durationFromConst :: (Num d) => d -> Duration d i
durationFromConst d = Duration $ constDur d
maybeConstDur :: (Num d, Ord d, Ord i) => Duration d i -> Maybe d
maybeConstDur = getConstDurMaybe . fromDuration
toConstDur :: (Num d, Ord d, Ord i) => Duration d i -> d
toConstDur d = case getConstDurMaybe $ fromDuration d of
Just d -> d
Nothing -> 0