{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE TypeFamilies #-}
module Diagrams.Transform.Matrix where
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.Matrix
import Linear.Vector
mkMat :: (HasBasis v, Num n) => Transformation v n -> v (v n)
mkMat :: forall (v :: * -> *) n.
(HasBasis v, Num n) =>
Transformation v n -> v (v n)
mkMat Transformation v n
t = forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
tabulate forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) n. Transformation v n -> v n -> v n
apply Transformation v n
t forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a.
(Additive t, Num a) =>
ASetter' (t a) a -> t a
unit forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\E v
x -> forall (t :: * -> *). E t -> forall x. Lens' (t x) x
el E v
x)
mkMatHomo :: Num n => Transformation V3 n -> M44 n
mkMatHomo :: forall n. Num n => Transformation V3 n -> M44 n
mkMatHomo Transformation V3 n
t = forall a. Num a => M33 a -> V3 a -> M44 a
mkTransformationMat (forall (v :: * -> *) n.
(HasBasis v, Num n) =>
Transformation v n -> v (v n)
mkMat Transformation V3 n
t) (forall (v :: * -> *) n. Transformation v n -> v n
transl Transformation V3 n
t)
fromMat22 :: Floating n => M22 n -> V2 n -> T2 n
fromMat22 :: forall n. Floating n => M22 n -> V2 n -> T2 n
fromMat22 M22 n
m V2 n
v = forall (v :: * -> *) n.
(Additive v, Distributive v, Foldable v, Num n) =>
v (v n) -> v (v n) -> v n -> Transformation v n
fromMatWithInv M22 n
m (forall a. Fractional a => M22 a -> M22 a
inv22 M22 n
m) V2 n
v
fromMat33 :: Floating n => M33 n -> V3 n -> T3 n
fromMat33 :: forall n. Floating n => M33 n -> V3 n -> T3 n
fromMat33 M33 n
m V3 n
v = forall (v :: * -> *) n.
(Additive v, Distributive v, Foldable v, Num n) =>
v (v n) -> v (v n) -> v n -> Transformation v n
fromMatWithInv M33 n
m (forall a. Fractional a => M33 a -> M33 a
inv33 M33 n
m) V3 n
v
fromMatWithInv :: (Additive v, Distributive v, F.Foldable v, Num n)
=> v (v n)
-> v (v n)
-> v n
-> Transformation v n
fromMatWithInv :: forall (v :: * -> *) n.
(Additive v, Distributive v, Foldable v, Num n) =>
v (v n) -> v (v n) -> v n -> Transformation v n
fromMatWithInv v (v n)
m v (v n)
m_ v n
v =
forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation ((v (v n)
m forall (m :: * -> *) (r :: * -> *) a.
(Functor m, Foldable r, Additive r, Num a) =>
m (r a) -> r a -> m a
!*) forall u v. (u -> v) -> (v -> u) -> u :-: v
<-> (v (v n)
m_ forall (m :: * -> *) (r :: * -> *) a.
(Functor m, Foldable r, Additive r, Num a) =>
m (r a) -> r a -> m a
!*))
((forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute v (v n)
m forall (m :: * -> *) (r :: * -> *) a.
(Functor m, Foldable r, Additive r, Num a) =>
m (r a) -> r a -> m a
!*) forall u v. (u -> v) -> (v -> u) -> u :-: v
<-> (forall (g :: * -> *) (f :: * -> *) a.
(Distributive g, Functor f) =>
f (g a) -> g (f a)
distribute v (v n)
m_ forall (m :: * -> *) (r :: * -> *) a.
(Functor m, Foldable r, Additive r, Num a) =>
m (r a) -> r a -> m a
!*))
v n
v
mat22 :: Floating n => Iso' (M22 n, V2 n) (T2 n)
mat22 :: forall n. Floating n => Iso' (M22 n, V2 n) (T2 n)
mat22 = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall n. Floating n => M22 n -> V2 n -> T2 n
fromMat22) (forall (v :: * -> *) n.
(HasBasis v, Num n) =>
Transformation v n -> v (v n)
mkMat forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall (v :: * -> *) n. Transformation v n -> v n
transl)
mat33 :: Floating n => Iso' (M33 n, V3 n) (T3 n)
mat33 :: forall n. Floating n => Iso' (M33 n, V3 n) (T3 n)
mat33 = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall n. Floating n => M33 n -> V3 n -> T3 n
fromMat33) (forall (v :: * -> *) n.
(HasBasis v, Num n) =>
Transformation v n -> v (v n)
mkMat forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall (v :: * -> *) n. Transformation v n -> v n
transl)