module Data.Colour.Chan where
import qualified Data.List (sum)
newtype Chan p a = Chan a deriving (Chan p a -> Chan p a -> Bool
(Chan p a -> Chan p a -> Bool)
-> (Chan p a -> Chan p a -> Bool) -> Eq (Chan p a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall p a. Eq a => Chan p a -> Chan p a -> Bool
$c== :: forall p a. Eq a => Chan p a -> Chan p a -> Bool
== :: Chan p a -> Chan p a -> Bool
$c/= :: forall p a. Eq a => Chan p a -> Chan p a -> Bool
/= :: Chan p a -> Chan p a -> Bool
Eq)
empty :: (Num a) => Chan p a
empty :: forall a p. Num a => Chan p a
empty = a -> Chan p a
forall p a. a -> Chan p a
Chan a
0
full :: (Num a) => Chan p a
full :: forall a p. Num a => Chan p a
full = a -> Chan p a
forall p a. a -> Chan p a
Chan a
1
scale :: (Num a) => a -> Chan p a -> Chan p a
scale :: forall a p. Num a => a -> Chan p a -> Chan p a
scale a
s (Chan a
x) = a -> Chan p a
forall p a. a -> Chan p a
Chan (a
sa -> a -> a
forall a. Num a => a -> a -> a
*a
x)
add :: (Num a) => Chan p a -> Chan p a -> Chan p a
(Chan a
a) add :: forall a p. Num a => Chan p a -> Chan p a -> Chan p a
`add` (Chan a
b) = a -> Chan p a
forall p a. a -> Chan p a
Chan (a
aa -> a -> a
forall a. Num a => a -> a -> a
+a
b)
invert :: (Num a) => Chan p a -> Chan p a
invert :: forall a p. Num a => Chan p a -> Chan p a
invert (Chan a
a) = a -> Chan p a
forall p a. a -> Chan p a
Chan (a
1a -> a -> a
forall a. Num a => a -> a -> a
-a
a)
over :: Chan p a -> a -> Chan p a -> Chan p a
over Chan p a
c0 a
a Chan p a
c1 = Chan p a
c0 Chan p a -> Chan p a -> Chan p a
forall a p. Num a => Chan p a -> Chan p a -> Chan p a
`add` a -> Chan p a -> Chan p a
forall a p. Num a => a -> Chan p a -> Chan p a
scale (a
1a -> a -> a
forall a. Num a => a -> a -> a
-a
a) Chan p a
c1
convert :: (Fractional b, Real a) => Chan p a -> Chan p b
convert :: forall b a p. (Fractional b, Real a) => Chan p a -> Chan p b
convert (Chan a
x) = b -> Chan p b
forall p a. a -> Chan p a
Chan (a -> b
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x)
sum :: (Num a) => [Chan p a] -> Chan p a
sum :: forall a p. Num a => [Chan p a] -> Chan p a
sum [Chan p a]
l = a -> Chan p a
forall p a. a -> Chan p a
Chan ([a] -> a
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Data.List.sum [a
x |Chan a
x <- [Chan p a]
l])