{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Diagrams.Transform.ScaleInv
( ScaleInv(..)
, scaleInvObj, scaleInvDir, scaleInvLoc
, scaleInv, scaleInvPrim)
where
import Control.Lens (makeLenses, view, (^.))
import Data.Typeable
import Diagrams.Angle
import Diagrams.Core
import Diagrams.TwoD.Transform
import Diagrams.TwoD.Types
import Linear.Affine
import Linear.Vector
data ScaleInv t =
ScaleInv
{ forall t. ScaleInv t -> t
_scaleInvObj :: t
, forall t. ScaleInv t -> Vn t
_scaleInvDir :: Vn t
, forall t. ScaleInv t -> Point (V t) (N t)
_scaleInvLoc :: Point (V t) (N t)
}
deriving Typeable
deriving instance (Show t, Show (Vn t)) => Show (ScaleInv t)
makeLenses ''ScaleInv
scaleInv :: (V t ~ v, N t ~ n, Additive v, Num n) => t -> v n -> ScaleInv t
scaleInv :: forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, Additive v, Num n) =>
t -> v n -> ScaleInv t
scaleInv t
t v n
d = forall t. t -> Vn t -> Point (V t) (N t) -> ScaleInv t
ScaleInv t
t v n
d forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin
type instance V (ScaleInv t) = V t
type instance N (ScaleInv t) = N t
instance (V t ~ v, N t ~ n, Additive v, Num n, HasOrigin t) => HasOrigin (ScaleInv t) where
moveOriginTo :: Point (V (ScaleInv t)) (N (ScaleInv t)) -> ScaleInv t -> ScaleInv t
moveOriginTo Point (V (ScaleInv t)) (N (ScaleInv t))
p (ScaleInv t
t Vn t
v Point (V t) (N t)
l) = forall t. t -> Vn t -> Point (V t) (N t) -> ScaleInv t
ScaleInv (forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo Point (V (ScaleInv t)) (N (ScaleInv t))
p t
t) Vn t
v (forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo Point (V (ScaleInv t)) (N (ScaleInv t))
p Point (V t) (N t)
l)
instance (V t ~ V2, N t ~ n, RealFloat n, Transformable t) => Transformable (ScaleInv t) where
transform :: Transformation (V (ScaleInv t)) (N (ScaleInv t))
-> ScaleInv t -> ScaleInv t
transform Transformation (V (ScaleInv t)) (N (ScaleInv t))
tr (ScaleInv t
t Vn t
v Point (V t) (N t)
l) = forall t. t -> Vn t -> Point (V t) (N t) -> ScaleInv t
ScaleInv (t -> t
trans forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. (V k ~ V t, N k ~ N t, Transformable k) => k -> k
rot forall a b. (a -> b) -> a -> b
$ t
t) (forall k. (V k ~ V t, N k ~ N t, Transformable k) => k -> k
rot Vn t
v) Point V2 n
l'
where
angle :: Angle n
angle = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (ScaleInv t)) (N (ScaleInv t))
tr Vn t
v forall s a. s -> Getting a s a -> a
^. forall (t :: * -> *) n.
(HasTheta t, RealFloat n) =>
Lens' (t n) (Angle n)
_theta
rot :: (V k ~ V t, N k ~ N t, Transformable k) => k -> k
rot :: forall k. (V k ~ V t, N k ~ N t, Transformable k) => k -> k
rot = forall n t.
(InSpace V2 n t, Transformable t, Floating n) =>
P2 n -> Angle n -> t -> t
rotateAround Point (V t) (N t)
l Angle n
angle
l' :: Point V2 n
l' = forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (ScaleInv t)) (N (ScaleInv t))
tr Point (V t) (N t)
l
trans :: t -> t
trans = forall t. Transformable t => Vn t -> t -> t
translate (Point V2 n
l' forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
.-. Point (V t) (N t)
l)
instance (V t ~ V2, N t ~ n, RealFloat n, Renderable t b) => Renderable (ScaleInv t) b where
render :: b -> ScaleInv t -> Render b (V (ScaleInv t)) (N (ScaleInv t))
render b
b = forall t b. Renderable t b => b -> t -> Render b (V t) (N t)
render b
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall t. Lens' (ScaleInv t) t
scaleInvObj
scaleInvPrim :: (V t ~ V2, N t ~ n, RealFloat n, Typeable t, Renderable t b, Monoid m)
=> t -> V2 n -> QDiagram b (V t) (N t) m
scaleInvPrim :: forall t n b m.
(V t ~ V2, N t ~ n, RealFloat n, Typeable t, Renderable t b,
Monoid m) =>
t -> V2 n -> QDiagram b (V t) (N t) m
scaleInvPrim t
t V2 n
d = forall b (v :: * -> *) n m.
Prim b v n
-> Envelope v n
-> Trace v n
-> SubMap b v n m
-> Query v n m
-> QDiagram b v n m
mkQD (forall p b.
(Transformable p, Typeable p, Renderable p b) =>
p -> Prim b (V p) (N p)
Prim forall a b. (a -> b) -> a -> b
$ forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, Additive v, Num n) =>
t -> v n -> ScaleInv t
scaleInv t
t V2 n
d) forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty