{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Diagrams.Transform
(
Transformation, inv, transl, apply, papply
, Transformable(..)
, translation, translate, moveTo, place, scaling, scale
, conjugate, underT, transformed, translated, movedTo, movedFrom
, HasOrigin(..), moveOriginBy
) where
import Control.Lens hiding (transform)
import Data.Semigroup
import Diagrams.Core
import Linear.Vector
conjugate :: (Additive v, Num n)
=> Transformation v n -> Transformation v n -> Transformation v n
conjugate :: Transformation v n -> Transformation v n -> Transformation v n
conjugate Transformation v n
t1 Transformation v n
t2 = Transformation v n -> Transformation v n
forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv Transformation v n
t1 Transformation v n -> Transformation v n -> Transformation v n
forall a. Semigroup a => a -> a -> a
<> Transformation v n
t2 Transformation v n -> Transformation v n -> Transformation v n
forall a. Semigroup a => a -> a -> a
<> Transformation v n
t1
underT :: (InSpace v n a, SameSpace a b, Transformable a, Transformable b)
=> (a -> b) -> Transformation v n -> a -> b
a -> b
f underT :: (a -> b) -> Transformation v n -> a -> b
`underT` Transformation v n
t = Transformation (V b) (N b) -> b -> b
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform (Transformation v n -> Transformation v n
forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv Transformation v n
t) (b -> b) -> (a -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f (a -> b) -> (a -> a) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transformation (V a) (N a) -> a -> a
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation v n
Transformation (V a) (N a)
t
transformed :: (InSpace v n a, SameSpace a b, Transformable a, Transformable b)
=> Transformation v n -> Iso a b a b
transformed :: Transformation v n -> Iso a b a b
transformed Transformation v n
t = (a -> a) -> (b -> b) -> Iso a b a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (Transformation (V a) (N a) -> a -> a
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform (Transformation (V a) (N a) -> a -> a)
-> Transformation (V a) (N a) -> a -> a
forall a b. (a -> b) -> a -> b
$ Transformation v n -> Transformation v n
forall (v :: * -> *) n.
(Functor v, Num n) =>
Transformation v n -> Transformation v n
inv Transformation v n
t) (Transformation (V b) (N b) -> b -> b
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation v n
Transformation (V b) (N b)
t)
movedTo :: (InSpace v n a, SameSpace a b, HasOrigin a, HasOrigin b)
=> Point v n -> Iso a b a b
movedTo :: Point v n -> Iso a b a b
movedTo Point v n
p = (a -> a) -> (b -> b) -> Iso a b a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (Point v n -> a -> a
forall (v :: * -> *) n t.
(InSpace v n t, HasOrigin t) =>
Point v n -> t -> t
moveTo (Point v n -> Point v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated Point v n
p)) (Point v n -> b -> b
forall (v :: * -> *) n t.
(InSpace v n t, HasOrigin t) =>
Point v n -> t -> t
moveTo Point v n
p)
movedFrom :: (InSpace v n a, SameSpace a b, HasOrigin a, HasOrigin b)
=> Point v n -> Iso a b a b
movedFrom :: Point v n -> Iso a b a b
movedFrom Point v n
p = (a -> a) -> (b -> b) -> Iso a b a b
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (Point (V a) (N a) -> a -> a
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo (Point v n -> Point v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated Point v n
p)) (Point (V b) (N b) -> b -> b
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo Point v n
Point (V b) (N b)
p)
translated :: (InSpace v n a, SameSpace a b, Transformable a, Transformable b)
=> v n -> Iso a b a b
translated :: v n -> Iso a b a b
translated v n
v = Transformation v n -> Iso a b a b
forall (v :: * -> *) n a b.
(InSpace v n a, SameSpace a b, Transformable a, Transformable b) =>
Transformation v n -> Iso a b a b
transformed (Transformation v n -> Iso a b a b)
-> Transformation v n -> Iso a b a b
forall a b. (a -> b) -> a -> b
$ v n -> Transformation v n
forall (v :: * -> *) n. v n -> Transformation v n
translation v n
v