{-# LANGUAGE RankNTypes #-}

-- | Hyprometric color ramps, for making pretty images from scalar data.
module  Data.Array.Repa.Algorithms.ColorRamp
        (rampColorHotToCold)
where


-- | Standard Hot to Cold hypsometric color ramp.
--      Color sequence is red, yellow, green, cyan, blue.
rampColorHotToCold 
        :: forall a
        .  (Ord a, Floating a) 
        => a    -- ^ Minimum value of range.
        -> a    -- ^ Maximum value of range.
        -> a    -- ^ Data value.
        -> (a, a, a)
        
{-# INLINE rampColorHotToCold #-}
rampColorHotToCold :: a -> a -> a -> (a, a, a)
rampColorHotToCold a
vmin a
vmax a
vNotNorm
 = let  
        v :: a
v       | a
vNotNorm a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
vmin       = a
vmin
                | a
vNotNorm a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
vmax       = a
vmax
                | Bool
otherwise             = a
vNotNorm
        
        dv :: a
dv      = a
vmax a -> a -> a
forall a. Num a => a -> a -> a
- a
vmin   

        result :: (a, a, a)
result  | a
v a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
vmin a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.25 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv
                = ( a
0
                  , a
4 a -> a -> a
forall a. Num a => a -> a -> a
* (a
v a -> a -> a
forall a. Num a => a -> a -> a
- a
vmin) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dv
                  , a
1.0)
                
                | a
v a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
vmin a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.5 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv
                = ( a
0
                  , a
1.0
                  , a
1 a -> a -> a
forall a. Num a => a -> a -> a
+ a
4 a -> a -> a
forall a. Num a => a -> a -> a
* (a
vmin a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.25 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv a -> a -> a
forall a. Num a => a -> a -> a
- a
v) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dv)
                
                | a
v a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
vmin a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.75 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv
                = ( a
4 a -> a -> a
forall a. Num a => a -> a -> a
* (a
v a -> a -> a
forall a. Num a => a -> a -> a
- a
vmin a -> a -> a
forall a. Num a => a -> a -> a
- a
0.5 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dv
                  , a
1.0
                  , a
0.0)
                
                | Bool
otherwise
                = ( a
1.0
                  , a
1 a -> a -> a
forall a. Num a => a -> a -> a
+ a
4 a -> a -> a
forall a. Num a => a -> a -> a
* (a
vmin a -> a -> a
forall a. Num a => a -> a -> a
+ a
0.75 a -> a -> a
forall a. Num a => a -> a -> a
* a
dv a -> a -> a
forall a. Num a => a -> a -> a
- a
v) a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
dv
                  , a
0)
                
  in    (a, a, a)
result