{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Diagrams.Core.Transform
(
(:-:)(..), (<->), linv, lapp
, Transformation(..)
, inv, transp, transl
, dropTransl
, apply
, papply
, fromLinear
, fromOrthogonal
, fromSymmetric
, basis
, dimension
, onBasis
, listRep
, matrixRep
, matrixHomRep
, determinant
, isReflection
, avgScale
, eye
, HasLinearMap
, HasBasis
, Transformable(..)
, TransInv(TransInv)
, translation, translate
, scaling, scale
) where
import Control.Lens (Rewrapped, Traversable, Wrapped (..),
iso, (&), (.~))
import qualified Data.Map as M
import Data.Semigroup
import qualified Data.Set as S
import Data.Monoid.Action
import Data.Monoid.Deletable
import Linear.Affine
import Linear.Vector
import Data.Foldable (Foldable, toList)
import Data.Functor.Rep
import Diagrams.Core.HasOrigin
import Diagrams.Core.Measure
import Diagrams.Core.Points ()
import Diagrams.Core.V
data (:-:) u v = (u -> v) :-: (v -> u)
infixr 7 :-:
(<->) :: (u -> v) -> (v -> u) -> (u :-: v)
u -> v
f <-> :: forall u v. (u -> v) -> (v -> u) -> u :-: v
<-> v -> u
g = u -> v
f forall u v. (u -> v) -> (v -> u) -> u :-: v
:-: v -> u
g
instance Semigroup (a :-: a) where
(a -> a
f :-: a -> a
f') <> :: (a :-: a) -> (a :-: a) -> a :-: a
<> (a -> a
g :-: a -> a
g') = a -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
g forall u v. (u -> v) -> (v -> u) -> u :-: v
:-: a -> a
g' forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f'
instance Monoid (v :-: v) where
mempty :: v :-: v
mempty = forall a. a -> a
id forall u v. (u -> v) -> (v -> u) -> u :-: v
:-: forall a. a -> a
id
mappend :: (v :-: v) -> (v :-: v) -> v :-: v
mappend = forall a. Semigroup a => a -> a -> a
(<>)
linv :: (u :-: v) -> (v :-: u)
linv :: forall u v. (u :-: v) -> v :-: u
linv (u -> v
f :-: v -> u
g) = v -> u
g forall u v. (u -> v) -> (v -> u) -> u :-: v
:-: u -> v
f
lapp :: (u :-: v) -> u -> v
lapp :: forall u v. (u :-: v) -> u -> v
lapp (u -> v
f :-: v -> u
_) = u -> v
f
data Transformation v n = Transformation (v n :-: v n) (v n :-: v n) (v n)
type instance V (Transformation v n) = v
type instance N (Transformation v n) = n
eye :: (HasBasis v, Num n) => v (v n)
eye :: forall (v :: * -> *) n. (HasBasis v, Num n) => v (v n)
eye = forall (f :: * -> *) a. Representable f => (Rep f -> a) -> f a
tabulate forall a b. (a -> b) -> a -> b
$ \(E forall x. Lens' (v x) x
e) -> forall (f :: * -> *) a. (Additive f, Num a) => f a
zero forall a b. a -> (a -> b) -> b
& forall x. Lens' (v x) x
e forall s t a b. ASetter s t a b -> b -> s -> t
.~ n
1
inv :: (Functor v, Num n) => Transformation v n -> Transformation v n
inv :: forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv (Transformation v n :-: v n
t v n :-: v n
t' v n
v) = forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation (forall u v. (u :-: v) -> v :-: u
linv v n :-: v n
t) (forall u v. (u :-: v) -> v :-: u
linv v n :-: v n
t')
(forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated (forall u v. (u :-: v) -> u -> v
lapp (forall u v. (u :-: v) -> v :-: u
linv v n :-: v n
t) v n
v))
transp :: Transformation v n -> (v n :-: v n)
transp :: forall (v :: * -> *) n. Transformation v n -> v n :-: v n
transp (Transformation v n :-: v n
_ v n :-: v n
t' v n
_) = v n :-: v n
t'
transl :: Transformation v n -> v n
transl :: forall (v :: * -> *) n. Transformation v n -> v n
transl (Transformation v n :-: v n
_ v n :-: v n
_ v n
v) = v n
v
dropTransl :: (Additive v, Num n) => Transformation v n -> Transformation v n
dropTransl :: forall (v :: * -> *) n.
(Additive v, Num n) =>
Transformation v n -> Transformation v n
dropTransl (Transformation v n :-: v n
a v n :-: v n
a' v n
_) = forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation v n :-: v n
a v n :-: v n
a' forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
instance (Additive v, Num n) => Semigroup (Transformation v n) where
Transformation v n :-: v n
t1 v n :-: v n
t1' v n
v1 <> :: Transformation v n -> Transformation v n -> Transformation v n
<> Transformation v n :-: v n
t2 v n :-: v n
t2' v n
v2
= forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation (v n :-: v n
t1 forall a. Semigroup a => a -> a -> a
<> v n :-: v n
t2) (v n :-: v n
t2' forall a. Semigroup a => a -> a -> a
<> v n :-: v n
t1') (v n
v1 forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^+^ forall u v. (u :-: v) -> u -> v
lapp v n :-: v n
t1 v n
v2)
instance (Additive v, Num n) => Monoid (Transformation v n) where
mempty :: Transformation v n
mempty = forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
mappend :: Transformation v n -> Transformation v n -> Transformation v n
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance (Transformable a, V a ~ v, N a ~ n) => Action (Transformation v n) a where
act :: Transformation v n -> a -> a
act = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
apply :: Transformation v n -> v n -> v n
apply :: forall (v :: * -> *) n. Transformation v n -> v n -> v n
apply (Transformation (v n -> v n
t :-: v n -> v n
_) v n :-: v n
_ v n
_) = v n -> v n
t
papply :: (Additive v, Num n) => Transformation v n -> Point v n -> Point v n
papply :: forall (v :: * -> *) n.
(Additive v, Num n) =>
Transformation v n -> Point v n -> Point v n
papply (Transformation v n :-: v n
t v n :-: v n
_ v n
v) (P v n
p) = forall (f :: * -> *) a. f a -> Point f a
P forall a b. (a -> b) -> a -> b
$ forall u v. (u :-: v) -> u -> v
lapp v n :-: v n
t v n
p forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^+^ v n
v
fromLinear :: (Additive v, Num n) => (v n :-: v n) -> (v n :-: v n) -> Transformation v n
fromLinear :: forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> (v n :-: v n) -> Transformation v n
fromLinear v n :-: v n
l1 v n :-: v n
l2 = forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation v n :-: v n
l1 v n :-: v n
l2 forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
fromOrthogonal :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n
fromOrthogonal :: forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> Transformation v n
fromOrthogonal v n :-: v n
t = forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> (v n :-: v n) -> Transformation v n
fromLinear v n :-: v n
t (forall u v. (u :-: v) -> v :-: u
linv v n :-: v n
t)
fromSymmetric :: (Additive v, Num n) => (v n :-: v n) -> Transformation v n
fromSymmetric :: forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> Transformation v n
fromSymmetric v n :-: v n
t = forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> (v n :-: v n) -> Transformation v n
fromLinear v n :-: v n
t v n :-: v n
t
dimension :: forall a. (Additive (V a), Traversable (V a)) => a -> Int
dimension :: forall a. (Additive (V a), Traversable (V a)) => a -> Int
dimension a
_ = forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall (t :: * -> *) a. (Additive t, Traversable t, Num a) => [t a]
basis :: [V a Int])
onBasis :: (Additive v, Traversable v, Num n) => Transformation v n -> ([v n], v n)
onBasis :: forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> ([v n], v n)
onBasis (Transformation (v n -> v n
f :-: v n -> v n
_) v n :-: v n
_ v n
t) = (forall a b. (a -> b) -> [a] -> [b]
map v n -> v n
f forall (t :: * -> *) a. (Additive t, Traversable t, Num a) => [t a]
basis, v n
t)
remove :: Int -> [a] -> [a]
remove :: forall a. Int -> [a] -> [a]
remove Int
n [a]
xs = [a]
ys forall a. [a] -> [a] -> [a]
++ [a]
zs
where
([a]
ys, a
_ : [a]
zs) = forall a. Int -> [a] -> ([a], [a])
splitAt Int
n [a]
xs
minor :: Int -> Int -> [[a]] -> [[a]]
minor :: forall a. Int -> Int -> [[a]] -> [[a]]
minor Int
i Int
j [[a]]
xs = forall a. Int -> [a] -> [a]
remove Int
j forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. Int -> [a] -> [a]
remove Int
i) [[a]]
xs
det :: Num a => [[a]] -> a
det :: forall a. Num a => [[a]] -> a
det [a
a : [a]
_] = a
a
det m :: [[a]]
m@([a]
c1 : [[a]]
_) = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [(-a
1) forall a b. (Num a, Integral b) => a -> b -> a
^ Int
i forall a. Num a => a -> a -> a
* ([a]
c1 forall a. [a] -> Int -> a
!! Int
i) forall a. Num a => a -> a -> a
* forall a. Num a => [[a]] -> a
det (forall a. Int -> Int -> [[a]] -> [[a]]
minor Int
i Int
0 [[a]]
m) | Int
i <- [Int
0 .. (Int
n forall a. Num a => a -> a -> a
- Int
1)]]
where
n :: Int
n = forall (t :: * -> *) a. Foldable t => t a -> Int
length [[a]]
m
listRep :: Foldable v => v n -> [n]
listRep :: forall (v :: * -> *) n. Foldable v => v n -> [n]
listRep = forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
matrixRep :: (Additive v, Traversable v, Num n) => Transformation v n -> [[n]]
matrixRep :: forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> [[n]]
matrixRep (Transformation (v n -> v n
f :-: v n -> v n
_) v n :-: v n
_ v n
_) = forall a b. (a -> b) -> [a] -> [b]
map (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. v n -> v n
f) forall (t :: * -> *) a. (Additive t, Traversable t, Num a) => [t a]
basis
matrixHomRep :: (Additive v, Traversable v, Num n) => Transformation v n -> [[n]]
matrixHomRep :: forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> [[n]]
matrixHomRep Transformation v n
t = [[n]]
mr forall a. [a] -> [a] -> [a]
++ [forall (t :: * -> *) a. Foldable t => t a -> [a]
toList v n
tl]
where
mr :: [[n]]
mr = forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> [[n]]
matrixRep Transformation v n
t
tl :: v n
tl = forall (v :: * -> *) n. Transformation v n -> v n
transl Transformation v n
t
determinant :: (Additive v, Traversable v, Num n) => Transformation v n -> n
determinant :: forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> n
determinant = forall a. Num a => [[a]] -> a
det forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> [[n]]
matrixRep
isReflection :: (Additive v, Traversable v, Num n, Ord n) => Transformation v n -> Bool
isReflection :: forall (v :: * -> *) n.
(Additive v, Traversable v, Num n, Ord n) =>
Transformation v n -> Bool
isReflection = (forall a. Ord a => a -> a -> Bool
<n
0) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> n
determinant
avgScale :: (Additive v, Traversable v, Floating n) => Transformation v n -> n
avgScale :: forall (v :: * -> *) n.
(Additive v, Traversable v, Floating n) =>
Transformation v n -> n
avgScale Transformation v n
t = (forall a. Num a => a -> a
abs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Additive v, Traversable v, Num n) =>
Transformation v n -> n
determinant) Transformation v n
t forall a. Floating a => a -> a -> a
** (forall a. Fractional a => a -> a
recip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (Additive (V a), Traversable (V a)) => a -> Int
dimension) Transformation v n
t
type HasLinearMap v = (HasBasis v, Traversable v)
type HasBasis v = (Additive v, Representable v, Rep v ~ E v)
class Transformable t where
transform :: Transformation (V t) (N t) -> t -> t
instance (Additive v, Num n) => Transformable (Transformation v n) where
transform :: Transformation (V (Transformation v n)) (N (Transformation v n))
-> Transformation v n -> Transformation v n
transform Transformation (V (Transformation v n)) (N (Transformation v n))
t1 Transformation v n
t2 = Transformation (V (Transformation v n)) (N (Transformation v n))
t1 forall a. Semigroup a => a -> a -> a
<> Transformation v n
t2
instance (Additive v, Num n) => HasOrigin (Transformation v n) where
moveOriginTo :: Point (V (Transformation v n)) (N (Transformation v n))
-> Transformation v n -> Transformation v n
moveOriginTo Point (V (Transformation v n)) (N (Transformation v n))
p = forall t. Transformable t => Vn t -> t -> t
translate (forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Point (V (Transformation v n)) (N (Transformation v n))
p)
instance (Transformable t, Transformable s, V t ~ V s, N t ~ N s)
=> Transformable (t, s) where
transform :: Transformation (V (t, s)) (N (t, s)) -> (t, s) -> (t, s)
transform Transformation (V (t, s)) (N (t, s))
t (t
x,s
y) = ( forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (t, s)) (N (t, s))
t t
x
, forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (t, s)) (N (t, s))
t s
y
)
instance (Transformable t, Transformable s, Transformable u, V s ~ V t, N s ~ N t, V s ~ V u, N s ~ N u)
=> Transformable (t,s,u) where
transform :: Transformation (V (t, s, u)) (N (t, s, u))
-> (t, s, u) -> (t, s, u)
transform Transformation (V (t, s, u)) (N (t, s, u))
t (t
x,s
y,u
z) = ( forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (t, s, u)) (N (t, s, u))
t t
x
, forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (t, s, u)) (N (t, s, u))
t s
y
, forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (t, s, u)) (N (t, s, u))
t u
z
)
instance ( V t ~ v, N t ~ n, V t ~ V s, N t ~ N s, Functor v, Num n
, Transformable t, Transformable s)
=> Transformable (s -> t) where
transform :: Transformation (V (s -> t)) (N (s -> t)) -> (s -> t) -> s -> t
transform Transformation (V (s -> t)) (N (s -> t))
tr s -> t
f = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (s -> t)) (N (s -> t))
tr forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> t
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform (forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv Transformation (V (s -> t)) (N (s -> t))
tr)
instance Transformable t => Transformable [t] where
transform :: Transformation (V [t]) (N [t]) -> [t] -> [t]
transform = forall a b. (a -> b) -> [a] -> [b]
map forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
instance (Transformable t, Ord t) => Transformable (S.Set t) where
transform :: Transformation (V (Set t)) (N (Set t)) -> Set t -> Set t
transform = forall b a. Ord b => (a -> b) -> Set a -> Set b
S.map forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
instance Transformable t => Transformable (M.Map k t) where
transform :: Transformation (V (Map k t)) (N (Map k t)) -> Map k t -> Map k t
transform = forall a b k. (a -> b) -> Map k a -> Map k b
M.map forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
instance (Additive v, Num n) => Transformable (Point v n) where
transform :: Transformation (V (Point v n)) (N (Point v n))
-> Point v n -> Point v n
transform = forall (v :: * -> *) n.
(Additive v, Num n) =>
Transformation v n -> Point v n -> Point v n
papply
instance Transformable m => Transformable (Deletable m) where
transform :: Transformation (V (Deletable m)) (N (Deletable m))
-> Deletable m -> Deletable m
transform = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
newtype TransInv t = TransInv t
deriving (TransInv t -> TransInv t -> Bool
forall t. Eq t => TransInv t -> TransInv t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransInv t -> TransInv t -> Bool
$c/= :: forall t. Eq t => TransInv t -> TransInv t -> Bool
== :: TransInv t -> TransInv t -> Bool
$c== :: forall t. Eq t => TransInv t -> TransInv t -> Bool
Eq, TransInv t -> TransInv t -> Bool
TransInv t -> TransInv t -> Ordering
TransInv t -> TransInv t -> TransInv t
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {t}. Ord t => Eq (TransInv t)
forall t. Ord t => TransInv t -> TransInv t -> Bool
forall t. Ord t => TransInv t -> TransInv t -> Ordering
forall t. Ord t => TransInv t -> TransInv t -> TransInv t
min :: TransInv t -> TransInv t -> TransInv t
$cmin :: forall t. Ord t => TransInv t -> TransInv t -> TransInv t
max :: TransInv t -> TransInv t -> TransInv t
$cmax :: forall t. Ord t => TransInv t -> TransInv t -> TransInv t
>= :: TransInv t -> TransInv t -> Bool
$c>= :: forall t. Ord t => TransInv t -> TransInv t -> Bool
> :: TransInv t -> TransInv t -> Bool
$c> :: forall t. Ord t => TransInv t -> TransInv t -> Bool
<= :: TransInv t -> TransInv t -> Bool
$c<= :: forall t. Ord t => TransInv t -> TransInv t -> Bool
< :: TransInv t -> TransInv t -> Bool
$c< :: forall t. Ord t => TransInv t -> TransInv t -> Bool
compare :: TransInv t -> TransInv t -> Ordering
$ccompare :: forall t. Ord t => TransInv t -> TransInv t -> Ordering
Ord, Int -> TransInv t -> ShowS
forall t. Show t => Int -> TransInv t -> ShowS
forall t. Show t => [TransInv t] -> ShowS
forall t. Show t => TransInv t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransInv t] -> ShowS
$cshowList :: forall t. Show t => [TransInv t] -> ShowS
show :: TransInv t -> String
$cshow :: forall t. Show t => TransInv t -> String
showsPrec :: Int -> TransInv t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> TransInv t -> ShowS
Show, NonEmpty (TransInv t) -> TransInv t
TransInv t -> TransInv t -> TransInv t
forall b. Integral b => b -> TransInv t -> TransInv t
forall t. Semigroup t => NonEmpty (TransInv t) -> TransInv t
forall t. Semigroup t => TransInv t -> TransInv t -> TransInv t
forall t b.
(Semigroup t, Integral b) =>
b -> TransInv t -> TransInv t
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> TransInv t -> TransInv t
$cstimes :: forall t b.
(Semigroup t, Integral b) =>
b -> TransInv t -> TransInv t
sconcat :: NonEmpty (TransInv t) -> TransInv t
$csconcat :: forall t. Semigroup t => NonEmpty (TransInv t) -> TransInv t
<> :: TransInv t -> TransInv t -> TransInv t
$c<> :: forall t. Semigroup t => TransInv t -> TransInv t -> TransInv t
Semigroup, TransInv t
[TransInv t] -> TransInv t
TransInv t -> TransInv t -> TransInv t
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall {t}. Monoid t => Semigroup (TransInv t)
forall t. Monoid t => TransInv t
forall t. Monoid t => [TransInv t] -> TransInv t
forall t. Monoid t => TransInv t -> TransInv t -> TransInv t
mconcat :: [TransInv t] -> TransInv t
$cmconcat :: forall t. Monoid t => [TransInv t] -> TransInv t
mappend :: TransInv t -> TransInv t -> TransInv t
$cmappend :: forall t. Monoid t => TransInv t -> TransInv t -> TransInv t
mempty :: TransInv t
$cmempty :: forall t. Monoid t => TransInv t
Monoid)
instance Wrapped (TransInv t) where
type Unwrapped (TransInv t) = t
_Wrapped' :: Iso' (TransInv t) (Unwrapped (TransInv t))
_Wrapped' = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(TransInv t
t) -> t
t) forall t. t -> TransInv t
TransInv
instance Rewrapped (TransInv t) (TransInv t')
type instance V (TransInv t) = V t
type instance N (TransInv t) = N t
instance HasOrigin (TransInv t) where
moveOriginTo :: Point (V (TransInv t)) (N (TransInv t)) -> TransInv t -> TransInv t
moveOriginTo = forall a b. a -> b -> a
const forall a. a -> a
id
instance (Num (N t), Additive (V t), Transformable t) => Transformable (TransInv t) where
transform :: Transformation (V (TransInv t)) (N (TransInv t))
-> TransInv t -> TransInv t
transform (Transformation V (TransInv t) (N (TransInv t)) :-: V (TransInv t) (N (TransInv t))
a V (TransInv t) (N (TransInv t)) :-: V (TransInv t) (N (TransInv t))
a' V (TransInv t) (N (TransInv t))
_) (TransInv t
t)
= forall t. t -> TransInv t
TransInv (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform (forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation V (TransInv t) (N (TransInv t)) :-: V (TransInv t) (N (TransInv t))
a V (TransInv t) (N (TransInv t)) :-: V (TransInv t) (N (TransInv t))
a' forall (f :: * -> *) a. (Additive f, Num a) => f a
zero) t
t)
instance (InSpace v n t, Transformable t, HasLinearMap v, Floating n)
=> Transformable (Measured n t) where
transform :: Transformation (V (Measured n t)) (N (Measured n t))
-> Measured n t -> Measured n t
transform Transformation (V (Measured n t)) (N (Measured n t))
t = forall n a. Num n => n -> Measured n a -> Measured n a
scaleLocal n
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation v n
t')
where
t' :: Transformation v n
t' = Transformation (V (Measured n t)) (N (Measured n t))
t forall a. Semigroup a => a -> a -> a
<> forall (v :: * -> *) n.
(Additive v, Fractional n) =>
n -> Transformation v n
scaling (n
1 forall a. Fractional a => a -> a -> a
/ forall (v :: * -> *) n.
(Additive v, Traversable v, Floating n) =>
Transformation v n -> n
avgScale Transformation (V (Measured n t)) (N (Measured n t))
t)
n :: n
n = forall (v :: * -> *) n.
(Additive v, Traversable v, Floating n) =>
Transformation v n -> n
avgScale Transformation (V (Measured n t)) (N (Measured n t))
t
translation :: v n -> Transformation v n
translation :: forall (v :: * -> *) n. v n -> Transformation v n
translation = forall (v :: * -> *) n.
(v n :-: v n) -> (v n :-: v n) -> v n -> Transformation v n
Transformation forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
translate :: (Transformable t) => Vn t -> t -> t
translate :: forall t. Transformable t => Vn t -> t -> t
translate = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. v n -> Transformation v n
translation
scaling :: (Additive v, Fractional n) => n -> Transformation v n
scaling :: forall (v :: * -> *) n.
(Additive v, Fractional n) =>
n -> Transformation v n
scaling n
s = forall (v :: * -> *) n.
(Additive v, Num n) =>
(v n :-: v n) -> Transformation v n
fromSymmetric v n :-: v n
lin
where lin :: v n :-: v n
lin = (n
s forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^) forall u v. (u -> v) -> (v -> u) -> u :-: v
<-> (forall (f :: * -> *) a.
(Functor f, Fractional a) =>
f a -> a -> f a
^/ n
s)
scale :: (InSpace v n a, Eq n, Fractional n, Transformable a)
=> n -> a -> a
scale :: forall (v :: * -> *) n a.
(InSpace v n a, Eq n, Fractional n, Transformable a) =>
n -> a -> a
scale n
0 = forall a. HasCallStack => String -> a
error String
"scale by zero! Halp!"
scale n
s = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) n.
(Additive v, Fractional n) =>
n -> Transformation v n
scaling n
s