{-# LANGUAGE RankNTypes #-}
module Data.Array.Repa.Algorithms.ColorRamp
(rampColorHotToCold)
where
rampColorHotToCold
:: forall a
. (Ord a, Floating a)
=> a
-> a
-> a
-> (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