module Graphics.PS.Pt ( Pt(Pt),
polarToRectangular,
ptMin, ptMax, ptXYs, origin,
ptTransform ) where
import Graphics.PS.Matrix
data Pt = Pt Double Double
deriving (Eq, Show)
instance Num Pt where
negate (Pt x y) = Pt ( x) ( y)
Pt x0 y0 + Pt x1 y1 = Pt (x0 + x1) (y0 + y1)
Pt x0 y0 Pt x1 y1 = Pt (x0 x1) (y0 y1)
Pt x0 y0 * Pt x1 y1 = Pt (x0 * x1) (y0 * y1)
abs (Pt x y) = Pt (abs x) (abs y)
signum _ = 0
fromInteger a = let a' = fromInteger a
in Pt a' a'
instance Ord Pt where
(Pt x0 y0) <= (Pt x1 y1) = x0 <= x1 && y0 <= y1
origin :: Pt
origin = Pt 0 0
ptXYs :: [Pt] -> [Double]
ptXYs [] = []
ptXYs (Pt x y : ps) = x : y : ptXYs ps
ptOp :: (Double -> Double -> Double) -> Pt -> Pt -> Pt
ptOp op (Pt x1 y1) (Pt x2 y2) = Pt (op x1 x2) (op y1 y2)
ptMin :: Pt -> Pt -> Pt
ptMin = ptOp min
ptMax :: Pt -> Pt -> Pt
ptMax = ptOp max
polarToRectangular :: Pt -> Pt
polarToRectangular (Pt r t) = Pt (r * cos t) (r * sin t)
ptTransform :: Matrix -> Pt -> Pt
ptTransform (Matrix a b c d e f) (Pt x y) =
let x' = x * a + y * c + e
y' = x * b + y * d + f
in Pt x' y'