packages feed

mandulia-0.4: src/Utils.hs

{-
Mandulia -- Mandelbrot/Julia explorer
Copyright (C) 2010  Claude Heiland-Allen <claudiusmaximus@goto10.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}

module Utils (phi, phi', clamp) where

{-
import Data.List (sortBy)
import Data.Ord (comparing)

first :: (a -> c) -> (a, b) -> (c, b)
first f ~(x,y) = (f x, y)

second :: (b -> c) -> (a, b) -> (a, c)
second f ~(x,y) = (x, f y)

second' :: (b -> c) -> (a, b) -> (a, c)
second' f ~(x,y) = let fy = f y in fy `seq` (x, fy)

sortOn :: Ord o => (a -> o) -> [a] -> [a]
sortOn p = map fst . sortBy (comparing snd) . map (\x -> let px = p x in px `seq` (x, px))
-}

phi  :: Double
phi  = (sqrt 5 + 1) / 2

phi' :: Double
phi' = (sqrt 5 - 1) / 2

clamp :: Ord r => r -> r -> r -> r
clamp mi ma x = ma `min` x `max` mi