module Pdf.Toolbox.Content.Transform
(
Transform(..),
Vector(..),
identity,
translation,
scale,
transform,
translate,
multiply
)
where
data Transform a = Transform a a a a a a
deriving Show
data Vector a = Vector a a
deriving Show
identity :: Num a => Transform a
identity = Transform 1 0 0 1 0 0
translation :: Num a => a -> a -> Transform a
translation tx ty = Transform 1 0 0 1 tx ty
scale :: Num a => a -> a -> Transform a
scale sx sy = Transform sx 0 0 sy 0 0
transform :: Num a => Transform a -> Vector a -> Vector a
transform (Transform a b c d e f) (Vector x y) = Vector (a * x + c * y + e) (b * x + d * y + f)
translate :: Num a => a -> a -> Transform a -> Transform a
translate tx ty t = translation tx ty `multiply` t
multiply :: Num a => Transform a -> Transform a -> Transform a
multiply (Transform a1 b1 c1 d1 e1 f1) (Transform a2 b2 c2 d2 e2 f2) = Transform a b c d e f
where
a = a1 * a2 + b1 * c2
b = a1 * b2 + b1 * d2
c = c1 * a2 + d1 * c2
d = c1 * b2 + d1 * d2
e = e1 * a2 + f1 * c2 + e2
f = e1 * b2 + f1 * d2 + f2