hps-0.14: Graphics/PS/Transform.hs
{-# Language FlexibleInstances #-}
-- | Class and associated functions for 'Matrix' transformations.
module Graphics.PS.Transform (Transformable
,translate, scale, rotate) where
import Data.CG.Minus {- hcg-minus -}
import qualified Graphics.PS.Path as P
import qualified Graphics.PS.Image as I
-- | Values that can be transformed in relation to a 'Matrix'.
class Transformable a where
transform :: Matrix Double -> a -> a
-- | Translation in /x/ and /y/.
translate :: (Transformable a) => Double -> Double -> a -> a
translate x = transform . mx_translation x
-- | Scaling in /x/ and /y/.
scale :: (Transformable a) => Double -> Double -> a -> a
scale x = transform . mx_scaling x
-- | Rotation, in radians.
rotate :: (Transformable a) => Double -> a -> a
rotate = transform . mx_rotation
instance Transformable I.Image where
transform = I.ITransform
instance Transformable P.Path where
transform = P.PTransform
instance Transformable (Pt Double) where
transform = pt_transform
{--
import Graphics.PS.Pt
-- | Polar variant.
pTranslate :: (Transform a) => Double -> Double -> a -> a
pTranslate r t = translate x y
where (Pt x y) = polarToRectangular (Pt r t)
--}