    {-
    Copyright (c) 2008,2009
    Russell O'Connor

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    -}

    module Data.Colour.RGBSpace.HSL
     (RGB
     ,hslView
     ,hue, saturation, lightness
     ,hsl
     )
    where

    import Data.Colour.RGB

    -- |Returns the HSL (hue-saturation-lightness) coordinates of an 'RGB' triple.
    -- See 'hue', 'saturation', and 'lightness'.
    hslView :: (Fractional a, Ord a) => RGB a -> (a,a,a)
    hslView :: RGB a -> (a, a, a)
    hslView rgb :: RGB a
    rgb = (a
    h,a
    s,a
    l)
     where
      (h :: a
    h,s :: a
    s,l :: a
    l,_,_) = RGB a -> (a, a, a, a, a)
    forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
    hslsv RGB a
    rgb

    -- |Returns the saturation coordinate (range [0, 1]) of an 'RGB' triple for the HSL
    -- (hue-saturation-lightness) system.
    -- Note: This is different from 'Data.Colour.RGBSpace.HSV.saturation' for
    -- the "Data.Colour.RGBSpace.HSV"
    saturation :: (Fractional a, Ord a) => RGB a -> a
    saturation :: RGB a -> a
    saturation rgb :: RGB a
    rgb = a
    s
     where
      (_,s :: a
    s,_,_,_) = RGB a -> (a, a, a, a, a)
    forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
    hslsv RGB a
    rgb

    -- |Returns the lightness coordinate (range [0, 1]) of an 'RGB' triple for the HSL
    -- (hue-saturation-lightness) system.
    lightness :: (Fractional a, Ord a) => RGB a -> a
    lightness :: RGB a -> a
    lightness rgb :: RGB a
    rgb = a
    l
     where
      (_,_,l :: a
    l,_,_) = RGB a -> (a, a, a, a, a)
    forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
    hslsv RGB a
    rgb

    -- |Convert HSL (hue-saturation-lightness) coordinates to an 'RGB' value.
    -- Hue is expected to be measured in degrees [0,360], while saturation and
    -- lightness are expected to be in the closed range [0,1].
    hsl :: (RealFrac a, Ord a) => a -> a -> a -> RGB a
    hsl :: a -> a -> a -> RGB a
    hsl h :: a
    h s :: a
    s l :: a
    l = (a -> a) -> RGB a -> RGB a
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> a
    component RGB a
    t
     where
      hk :: a
    hk = a
    ha -> a -> a
    forall a. Fractional a => a -> a -> a
    /360
      tr :: a
    tr = a -> a
    forall p. RealFrac p => p -> p
    mod1 (a
    hk a -> a -> a
    forall a. Num a => a -> a -> a
    + 1a -> a -> a
    forall a. Fractional a => a -> a -> a
    /3)
      tg :: a
    tg = a -> a
    forall p. RealFrac p => p -> p
    mod1 a
    hk
      tb :: a
    tb = a -> a
    forall p. RealFrac p => p -> p
    mod1 (a
    hk a -> a -> a
    forall a. Num a => a -> a -> a
    - 1a -> a -> a
    forall a. Fractional a => a -> a -> a
    /3)
      t :: RGB a
    t = a -> a -> a -> RGB a
    forall a. a -> a -> a -> RGB a
    RGB a
    tr a
    tg a
    tb
      q :: a
    q | a
    l a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    < 0.5 = a
    la -> a -> a
    forall a. Num a => a -> a -> a
    *(1a -> a -> a
    forall a. Num a => a -> a -> a
    +a
    s)
        | Bool
    otherwise = a
    l a -> a -> a
    forall a. Num a => a -> a -> a
    + a
    s a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    la -> a -> a
    forall a. Num a => a -> a -> a
    *a
    s
      p :: a
    p = 2a -> a -> a
    forall a. Num a => a -> a -> a
    *a
    l a -> a -> a
    forall a. Num a => a -> a -> a
    - a
    q
      component :: a -> a
    component t :: a
    t | a
    t a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    < 1a -> a -> a
    forall a. Fractional a => a -> a -> a
    /6 = a
    p a -> a -> a
    forall a. Num a => a -> a -> a
    + ((a
    qa -> a -> a
    forall a. Num a => a -> a -> a
    -a
    p)a -> a -> a
    forall a. Num a => a -> a -> a
    *6a -> a -> a
    forall a. Num a => a -> a -> a
    *a
    t)
                  | a
    t a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    < 1a -> a -> a
    forall a. Fractional a => a -> a -> a
    /2 = a
    q
                  | a
    t a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    < 2a -> a -> a
    forall a. Fractional a => a -> a -> a
    /3 = a
    p a -> a -> a
    forall a. Num a => a -> a -> a
    + ((a
    qa -> a -> a
    forall a. Num a => a -> a -> a
    -a
    p)a -> a -> a
    forall a. Num a => a -> a -> a
    *6a -> a -> a
    forall a. Num a => a -> a -> a
    *(2a -> a -> a
    forall a. Fractional a => a -> a -> a
    /3a -> a -> a
    forall a. Num a => a -> a -> a
    -a
    t))
                  | Bool
    otherwise = a
    p