module Diagrams.Transform.Matrix where
#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif
import Control.Arrow ((&&&))
import Control.Lens
import Data.Distributive
import qualified Data.Foldable as F
import Data.Functor.Rep
import Diagrams.Core.Transform as D
import Diagrams.ThreeD.Types
import Diagrams.TwoD.Types
import Linear.Epsilon
import Linear.Matrix
import Linear.Vector
mkMat :: (HasBasis v, Num n) => Transformation v n -> v (v n)
mkMat t = distribute . tabulate $ apply t . unit . el
mkMatHomo :: Num n => Transformation V3 n -> M44 n
mkMatHomo t = mkTransformationMat (mkMat t) (transl t)
fromMat22 :: (Epsilon n, Floating n) => M22 n -> V2 n -> Maybe (T2 n)
fromMat22 m v = flip (fromMatWithInv m) v <$> inv22 m
fromMat33 :: (Epsilon n, Floating n) => M33 n -> V3 n -> Maybe (T3 n)
fromMat33 m v = flip (fromMatWithInv m) v <$> inv33 m
fromMatWithInv :: (Additive v, Distributive v, F.Foldable v, Num n)
=> v (v n)
-> v (v n)
-> v n
-> Transformation v n
fromMatWithInv m m_ v =
Transformation ((*! m) <-> (*! m_))
((*! distribute m) <-> (*! distribute m_))
v
mat22 :: (Epsilon n, Floating n) => Prism' (M22 n, V2 n) (T2 n)
mat22 = prism' (mkMat &&& transl) (uncurry fromMat22)
mat33 :: (Epsilon n, Floating n) => Prism' (M33 n, V3 n) (T3 n)
mat33 = prism' (mkMat &&& transl) (uncurry fromMat33)