{-# LANGUAGE TypeSynonymInstances, FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, RecursiveDo, TypeFamilies, OverloadedStrings, RecordWildCards,UndecidableInstances, PackageImports, TemplateHaskell, RankNTypes #-}
module Graphics.Diagrams.Point where
import Graphics.Diagrams.Core
import Data.Foldable
import Data.List (transpose)
import Prelude hiding (sum,mapM_,mapM,concatMap,maximum,minimum,Num(..),(/))
import Algebra.Classes
infix 4 .=.
type Point = Point' Expr
orthonorm :: Point -> Expr
orthonorm (Point x y) = absE x + absE y
rotate90 :: forall a. Group a => Point' a -> Point' a
rotate90 (Point x y) = Point (negate y) x
rotate180 :: forall a. Group a => Point' a -> Point' a
rotate180 = rotate90 . rotate90
xdiff,ydiff :: Point -> Point -> Expr
xdiff p q = xpart (q - p)
ydiff p q = ypart (q - p)
(.=.),northOf,southOf,westOf,eastOf :: Monad m => Point -> Point -> Diagram lab m ()
Point x1 y1 .=. Point x2 y2 = do
x1 === x2
y1 === y2
northOf (Point _ y1) (Point _ y2) = y2 <== y1
southOf = flip northOf
westOf (Point x1 _) (Point x2 _) = x1 <== x2
eastOf = flip westOf
alignHoriz,alignVert :: Monad m => [Point] -> Diagram lab m ()
alignHoriz = align ypart
alignVert = align xpart
align :: Monad m => (a -> Expr) -> [a] -> Diagram lab m ()
align _ [] = return ()
align f (p:ps) = forM_ ps $ \p' -> f p === f p'
alignMatrix :: Monad m => [[Point]] -> Diagram lab m ()
alignMatrix ls = do
forM_ ls alignHoriz
forM_ (transpose ls) alignVert