module Graphics.PDF.Coordinates
( module Data.Complex
, Angle(..)
, Point
, Matrix(..)
, toRadian
, dot, scalePt
, project, projectX, projectY
, pointMatrix
, transform
, identity, rotate, translate, scale, spiral
)
where
import Data.Complex
import Graphics.PDF.LowLevel.Types(PDFFloat)
data Angle = Degree !PDFFloat
| Radian !PDFFloat
toRadian :: Angle -> PDFFloat
toRadian :: Angle -> PDFFloat
toRadian (Degree PDFFloat
x) = (forall a. Floating a => a
pi forall a. Fractional a => a -> a -> a
/ PDFFloat
180) forall a. Num a => a -> a -> a
* PDFFloat
x
toRadian (Radian PDFFloat
x) = PDFFloat
x
type Point = Complex PDFFloat
dot :: (RealFloat t) => Complex t -> Complex t -> t
dot :: forall t. RealFloat t => Complex t -> Complex t -> t
dot (t
x0 :+ t
y0) (t
x1 :+ t
y1) = t
x0 forall a. Num a => a -> a -> a
* t
x1 forall a. Num a => a -> a -> a
+ t
y0 forall a. Num a => a -> a -> a
* t
y1
scalePt :: (RealFloat t) => t -> Complex t -> Complex t
scalePt :: forall t. RealFloat t => t -> Complex t -> Complex t
scalePt t
a (t
x :+ t
y) = t
aforall a. Num a => a -> a -> a
*t
x forall a. a -> a -> Complex a
:+ t
aforall a. Num a => a -> a -> a
*t
y
project :: (RealFloat t) => Complex t -> Complex t -> Complex t
project :: forall t. RealFloat t => Complex t -> Complex t -> Complex t
project Complex t
z Complex t
w = forall t. RealFloat t => t -> Complex t -> Complex t
scalePt (forall t. RealFloat t => Complex t -> Complex t -> t
dot Complex t
z Complex t
w forall a. Fractional a => a -> a -> a
/ forall t. RealFloat t => Complex t -> Complex t -> t
dot Complex t
w Complex t
w) Complex t
w
projectX :: (RealFloat t) => Complex t -> Complex t
projectX :: forall t. RealFloat t => Complex t -> Complex t
projectX (t
x :+ t
_) = (t
x forall a. a -> a -> Complex a
:+ t
0)
projectY :: (RealFloat t) => Complex t -> Complex t
projectY :: forall t. RealFloat t => Complex t -> Complex t
projectY (t
_ :+ t
y) = (t
0 forall a. a -> a -> Complex a
:+ t
y)
data Matrix
= Matrix !PDFFloat !PDFFloat !PDFFloat !PDFFloat !PDFFloat !PDFFloat
deriving (Matrix -> Matrix -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Matrix -> Matrix -> Bool
$c/= :: Matrix -> Matrix -> Bool
== :: Matrix -> Matrix -> Bool
$c== :: Matrix -> Matrix -> Bool
Eq, Int -> Matrix -> ShowS
[Matrix] -> ShowS
Matrix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Matrix] -> ShowS
$cshowList :: [Matrix] -> ShowS
show :: Matrix -> String
$cshow :: Matrix -> String
showsPrec :: Int -> Matrix -> ShowS
$cshowsPrec :: Int -> Matrix -> ShowS
Show)
instance Num Matrix where
+ :: Matrix -> Matrix -> Matrix
(+) (Matrix PDFFloat
ma PDFFloat
mb PDFFloat
mc PDFFloat
md PDFFloat
me PDFFloat
mf ) (Matrix PDFFloat
na PDFFloat
nb PDFFloat
nc PDFFloat
nd PDFFloat
ne PDFFloat
nf) =
PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix (PDFFloat
maforall a. Num a => a -> a -> a
+PDFFloat
na) (PDFFloat
mbforall a. Num a => a -> a -> a
+PDFFloat
nb) (PDFFloat
mcforall a. Num a => a -> a -> a
+PDFFloat
nc) (PDFFloat
mdforall a. Num a => a -> a -> a
+PDFFloat
nd) (PDFFloat
meforall a. Num a => a -> a -> a
+PDFFloat
ne) (PDFFloat
mfforall a. Num a => a -> a -> a
+PDFFloat
nf)
* :: Matrix -> Matrix -> Matrix
(*) (Matrix PDFFloat
ma PDFFloat
mb PDFFloat
mc PDFFloat
md PDFFloat
me PDFFloat
mf) (Matrix PDFFloat
na PDFFloat
nb PDFFloat
nc PDFFloat
nd PDFFloat
ne PDFFloat
nf) =
PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix (PDFFloat
maforall a. Num a => a -> a -> a
*PDFFloat
naforall a. Num a => a -> a -> a
+PDFFloat
mbforall a. Num a => a -> a -> a
*PDFFloat
nc) (PDFFloat
maforall a. Num a => a -> a -> a
*PDFFloat
nbforall a. Num a => a -> a -> a
+PDFFloat
mbforall a. Num a => a -> a -> a
*PDFFloat
nd) (PDFFloat
mcforall a. Num a => a -> a -> a
*PDFFloat
naforall a. Num a => a -> a -> a
+PDFFloat
mdforall a. Num a => a -> a -> a
*PDFFloat
nc) (PDFFloat
mcforall a. Num a => a -> a -> a
*PDFFloat
nb forall a. Num a => a -> a -> a
+PDFFloat
mdforall a. Num a => a -> a -> a
*PDFFloat
nd) (PDFFloat
meforall a. Num a => a -> a -> a
*PDFFloat
naforall a. Num a => a -> a -> a
+PDFFloat
mfforall a. Num a => a -> a -> a
*PDFFloat
ncforall a. Num a => a -> a -> a
+PDFFloat
ne) (PDFFloat
meforall a. Num a => a -> a -> a
*PDFFloat
nbforall a. Num a => a -> a -> a
+PDFFloat
mfforall a. Num a => a -> a -> a
*PDFFloat
ndforall a. Num a => a -> a -> a
+PDFFloat
nf)
negate :: Matrix -> Matrix
negate (Matrix PDFFloat
ma PDFFloat
mb PDFFloat
mc PDFFloat
md PDFFloat
me PDFFloat
mf ) =
PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix (-PDFFloat
ma) (-PDFFloat
mb) (-PDFFloat
mc) (-PDFFloat
md) (-PDFFloat
me) (-PDFFloat
mf)
abs :: Matrix -> Matrix
abs Matrix
m = Matrix
m
signum :: Matrix -> Matrix
signum Matrix
_ = Matrix
identity
fromInteger :: Integer -> Matrix
fromInteger Integer
i = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
r PDFFloat
0 PDFFloat
0 PDFFloat
r PDFFloat
0 PDFFloat
0
where
r :: PDFFloat
r = forall a. Num a => Integer -> a
fromInteger Integer
i
identity :: Matrix
identity :: Matrix
identity = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
1 PDFFloat
0 PDFFloat
0 PDFFloat
1 PDFFloat
0 PDFFloat
0
pointMatrix :: Point
-> Point
-> Point
-> Matrix
pointMatrix :: Point -> Point -> Point -> Matrix
pointMatrix (PDFFloat
x0 :+ PDFFloat
y0) (PDFFloat
x1 :+ PDFFloat
y1) (PDFFloat
x2 :+ PDFFloat
y2) = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
x0 PDFFloat
y0 PDFFloat
x1 PDFFloat
y1 PDFFloat
x2 PDFFloat
y2
transform :: Matrix -> Point -> Point
transform :: Matrix -> Point -> Point
transform (Matrix PDFFloat
x0 PDFFloat
y0 PDFFloat
x1 PDFFloat
y1 PDFFloat
x2 PDFFloat
y2) (PDFFloat
x :+ PDFFloat
y) = (PDFFloat
xforall a. Num a => a -> a -> a
*PDFFloat
x0 forall a. Num a => a -> a -> a
+ PDFFloat
yforall a. Num a => a -> a -> a
*PDFFloat
x1 forall a. Num a => a -> a -> a
+ PDFFloat
x2) forall a. a -> a -> Complex a
:+ (PDFFloat
xforall a. Num a => a -> a -> a
*PDFFloat
y0 forall a. Num a => a -> a -> a
+ PDFFloat
yforall a. Num a => a -> a -> a
*PDFFloat
y1 forall a. Num a => a -> a -> a
+ PDFFloat
y2)
rotate :: Angle
-> Matrix
rotate :: Angle -> Matrix
rotate Angle
r = Point -> Matrix
spiral (forall a. Floating a => a -> Complex a
cis (Angle -> PDFFloat
toRadian Angle
r))
translate :: Point
-> Matrix
translate :: Point -> Matrix
translate (PDFFloat
tx :+ PDFFloat
ty) = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
1 PDFFloat
0 PDFFloat
0 PDFFloat
1 PDFFloat
tx PDFFloat
ty
spiral :: Point
-> Matrix
spiral :: Point -> Matrix
spiral (PDFFloat
x :+ PDFFloat
y) = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
x PDFFloat
y (-PDFFloat
y) PDFFloat
x PDFFloat
0 PDFFloat
0
scale :: PDFFloat
-> PDFFloat
-> Matrix
scale :: PDFFloat -> PDFFloat -> Matrix
scale PDFFloat
sx PDFFloat
sy = PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> PDFFloat
-> Matrix
Matrix PDFFloat
sx PDFFloat
0 PDFFloat
0 PDFFloat
sy PDFFloat
0 PDFFloat
0