{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Diagrams.Combinators
(
withEnvelope, withTrace
, phantom, strut
, pad, frame
, extrudeEnvelope, intrudeEnvelope
, atop
, beneath
, beside
, atDirection
, appends
, position, atPoints
, cat, cat'
, CatOpts(_catMethod, _sep), catMethod, sep
, CatMethod(..)
, composeAligned
) where
import Control.Lens hiding (beside, ( # ))
import Data.Default
import Data.Maybe (fromJust)
import Data.Monoid.Deletable (toDeletable)
import Data.Monoid.MList (inj)
import Data.Proxy
import Data.Semigroup
import qualified Data.Tree.DUAL as D
import Diagrams.Core
import Diagrams.Core.Types (QDiagram (QD))
import Diagrams.Direction
import Diagrams.Names (named)
import Diagrams.Segment (straight)
import Diagrams.Util
import Linear.Affine
import Linear.Metric
import Linear.Vector
withEnvelope :: (InSpace v n a, Monoid' m, Enveloped a)
=> a -> QDiagram b v n m -> QDiagram b v n m
withEnvelope :: forall (v :: * -> *) n a m b.
(InSpace v n a, Monoid' m, Enveloped a) =>
a -> QDiagram b v n m -> QDiagram b v n m
withEnvelope = Envelope v n -> QDiagram b v n m -> QDiagram b v n m
forall b (v :: * -> *) n m.
(OrderedField n, Metric v, Monoid' m) =>
Envelope v n -> QDiagram b v n m -> QDiagram b v n m
setEnvelope (Envelope v n -> QDiagram b v n m -> QDiagram b v n m)
-> (a -> Envelope v n) -> a -> QDiagram b v n m -> QDiagram b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Envelope v n
a -> Envelope (V a) (N a)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope
withTrace :: (InSpace v n a, Metric v, OrderedField n, Monoid' m, Traced a)
=> a -> QDiagram b v n m -> QDiagram b v n m
withTrace :: forall (v :: * -> *) n a m b.
(InSpace v n a, Metric v, OrderedField n, Monoid' m, Traced a) =>
a -> QDiagram b v n m -> QDiagram b v n m
withTrace = Trace v n -> QDiagram b v n m -> QDiagram b v n m
forall b (v :: * -> *) n m.
(OrderedField n, Metric v, Semigroup m) =>
Trace v n -> QDiagram b v n m -> QDiagram b v n m
setTrace (Trace v n -> QDiagram b v n m -> QDiagram b v n m)
-> (a -> Trace v n) -> a -> QDiagram b v n m -> QDiagram b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Trace v n
a -> Trace (V a) (N a)
forall a. Traced a => a -> Trace (V a) (N a)
getTrace
phantom :: (InSpace v n a, Monoid' m, Enveloped a, Traced a) => a -> QDiagram b v n m
phantom :: forall (v :: * -> *) n a m b.
(InSpace v n a, Monoid' m, Enveloped a, Traced a) =>
a -> QDiagram b v n m
phantom a
a = DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
forall b (v :: * -> *) n m.
DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
QD (DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m)
-> DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
forall a b. (a -> b) -> a -> b
$ UpAnnots b v n m
-> DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
forall u d a l. u -> DUALTree d u a l
D.leafU ((Deletable (Envelope v n) -> UpAnnots b v n m
forall l a. (l :>: a) => a -> l
inj (Deletable (Envelope v n) -> UpAnnots b v n m)
-> (a -> Deletable (Envelope v n)) -> a -> UpAnnots b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Envelope v n -> Deletable (Envelope v n)
forall m. m -> Deletable m
toDeletable (Envelope v n -> Deletable (Envelope v n))
-> (a -> Envelope v n) -> a -> Deletable (Envelope v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Envelope v n
a -> Envelope (V a) (N a)
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope (a -> UpAnnots b v n m) -> a -> UpAnnots b v n m
forall a b. (a -> b) -> a -> b
$ a
a) UpAnnots b v n m -> UpAnnots b v n m -> UpAnnots b v n m
forall a. Semigroup a => a -> a -> a
<> (Deletable (Trace v n) -> UpAnnots b v n m
forall l a. (l :>: a) => a -> l
inj (Deletable (Trace v n) -> UpAnnots b v n m)
-> (a -> Deletable (Trace v n)) -> a -> UpAnnots b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trace v n -> Deletable (Trace v n)
forall m. m -> Deletable m
toDeletable (Trace v n -> Deletable (Trace v n))
-> (a -> Trace v n) -> a -> Deletable (Trace v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Trace v n
a -> Trace (V a) (N a)
forall a. Traced a => a -> Trace (V a) (N a)
getTrace (a -> UpAnnots b v n m) -> a -> UpAnnots b v n m
forall a b. (a -> b) -> a -> b
$ a
a))
pad :: (Metric v, OrderedField n, Monoid' m)
=> n -> QDiagram b v n m -> QDiagram b v n m
pad :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
n -> QDiagram b v n m -> QDiagram b v n m
pad n
s QDiagram b v n m
d = QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
forall (v :: * -> *) n a m b.
(InSpace v n a, Monoid' m, Enveloped a) =>
a -> QDiagram b v n m -> QDiagram b v n m
withEnvelope (QDiagram b v n m
d QDiagram b v n m
-> (QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m
forall a b. a -> (a -> b) -> b
# n -> QDiagram b v n m -> QDiagram b v n m
forall (v :: * -> *) n a.
(InSpace v n a, Eq n, Fractional n, Transformable a) =>
n -> a -> a
scale n
s) QDiagram b v n m
d
frame :: (Metric v, OrderedField n, Monoid' m)
=> n -> QDiagram b v n m -> QDiagram b v n m
frame :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
n -> QDiagram b v n m -> QDiagram b v n m
frame n
s = ASetter
(QDiagram b v n m) (QDiagram b v n m) (Envelope v n) (Envelope v n)
-> (Envelope v n -> Envelope v n)
-> QDiagram b v n m
-> QDiagram b v n m
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(QDiagram b v n m) (QDiagram b v n m) (Envelope v n) (Envelope v n)
forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Monoid' m) =>
Lens' (QDiagram b v n m) (Envelope v n)
Lens' (QDiagram b v n m) (Envelope v n)
envelope (((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
forall (v :: * -> *) n.
((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
onEnvelope (((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n)
-> ((v n -> n) -> v n -> n) -> Envelope v n -> Envelope v n
forall a b. (a -> b) -> a -> b
$ \v n -> n
f v n
x -> v n -> n
f v n
x n -> n -> n
forall a. Num a => a -> a -> a
+ n
s)
strut :: (Metric v, OrderedField n)
=> v n -> QDiagram b v n m
strut :: forall (v :: * -> *) n b m.
(Metric v, OrderedField n) =>
v n -> QDiagram b v n m
strut v n
v = DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
forall b (v :: * -> *) n m.
DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
QD (DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m)
-> DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
-> QDiagram b v n m
forall a b. (a -> b) -> a -> b
$ UpAnnots b v n m
-> DUALTree
(DownAnnots v n) (UpAnnots b v n m) Annotation (QDiaLeaf b v n m)
forall u d a l. u -> DUALTree d u a l
D.leafU (Deletable (Envelope v n) -> UpAnnots b v n m
forall l a. (l :>: a) => a -> l
inj (Deletable (Envelope v n) -> UpAnnots b v n m)
-> (Envelope v n -> Deletable (Envelope v n))
-> Envelope v n
-> UpAnnots b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Envelope v n -> Deletable (Envelope v n)
forall m. m -> Deletable m
toDeletable (Envelope v n -> UpAnnots b v n m)
-> Envelope v n -> UpAnnots b v n m
forall a b. (a -> b) -> a -> b
$ Envelope v n
env)
where env :: Envelope v n
env = Vn (Envelope v n) -> Envelope v n -> Envelope v n
forall t. Transformable t => Vn t -> t -> t
translate ((-n
0.5) n -> v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ v n
v) (Envelope v n -> Envelope v n)
-> (Segment Closed v n -> Envelope v n)
-> Segment Closed v n
-> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Segment Closed v n -> Envelope v n
Segment Closed v n
-> Envelope (V (Segment Closed v n)) (N (Segment Closed v n))
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope (Segment Closed v n -> Envelope v n)
-> Segment Closed v n -> Envelope v n
forall a b. (a -> b) -> a -> b
$ v n -> Segment Closed v n
forall (v :: * -> *) n. v n -> Segment Closed v n
straight v n
v
extrudeEnvelope
:: (Metric v, OrderedField n, Monoid' m)
=> v n -> QDiagram b v n m -> QDiagram b v n m
extrudeEnvelope :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
v n -> QDiagram b v n m -> QDiagram b v n m
extrudeEnvelope = n -> v n -> QDiagram b v n m -> QDiagram b v n m
forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
n -> v n -> QDiagram b v n m -> QDiagram b v n m
deformEnvelope n
1
intrudeEnvelope
:: (Metric v, OrderedField n, Monoid' m)
=> v n -> QDiagram b v n m -> QDiagram b v n m
intrudeEnvelope :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
v n -> QDiagram b v n m -> QDiagram b v n m
intrudeEnvelope = n -> v n -> QDiagram b v n m -> QDiagram b v n m
forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
n -> v n -> QDiagram b v n m -> QDiagram b v n m
deformEnvelope (-n
1)
deformEnvelope
:: (Metric v, OrderedField n, Monoid' m)
=> n -> v n -> QDiagram b v n m -> QDiagram b v n m
deformEnvelope :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
n -> v n -> QDiagram b v n m -> QDiagram b v n m
deformEnvelope n
s v n
v = ASetter
(QDiagram b v n m)
(QDiagram b v n m)
(Maybe (v n -> Max n))
(Maybe (v n -> Max n))
-> (Maybe (v n -> Max n) -> Maybe (v n -> Max n))
-> QDiagram b v n m
-> QDiagram b v n m
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Envelope v n -> Identity (Envelope v n))
-> QDiagram b v n m -> Identity (QDiagram b v n m)
forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Monoid' m) =>
Lens' (QDiagram b v n m) (Envelope v n)
Lens' (QDiagram b v n m) (Envelope v n)
envelope ((Envelope v n -> Identity (Envelope v n))
-> QDiagram b v n m -> Identity (QDiagram b v n m))
-> ((Maybe (v n -> Max n) -> Identity (Maybe (v n -> Max n)))
-> Envelope v n -> Identity (Envelope v n))
-> ASetter
(QDiagram b v n m)
(QDiagram b v n m)
(Maybe (v n -> Max n))
(Maybe (v n -> Max n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Envelope v n) -> Envelope v n)
-> Iso
(Envelope v n)
(Envelope v n)
(Unwrapped (Envelope v n))
(Unwrapped (Envelope v n))
forall s t.
Rewrapping s t =>
(Unwrapped s -> s) -> Iso s t (Unwrapped s) (Unwrapped t)
_Wrapping Maybe (v n -> Max n) -> Envelope v n
Unwrapped (Envelope v n) -> Envelope v n
forall (v :: * -> *) n. Maybe (v n -> Max n) -> Envelope v n
Envelope) Maybe (v n -> Max n) -> Maybe (v n -> Max n)
deformE
where
deformE :: Maybe (v n -> Max n) -> Maybe (v n -> Max n)
deformE = ((v n -> Max n) -> v n -> Max n)
-> Maybe (v n -> Max n) -> Maybe (v n -> Max n)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (v n -> Max n) -> v n -> Max n
deformE'
deformE' :: (v n -> Max n) -> v n -> Max n
deformE' v n -> Max n
env v n
v'
| n
dp n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
0 = n -> Max n
forall a. a -> Max a
Max (n -> Max n) -> n -> Max n
forall a b. (a -> b) -> a -> b
$ Max n -> n
forall a. Max a -> a
getMax (v n -> Max n
env v n
v') n -> n -> n
forall a. Num a => a -> a -> a
+ (n
dp n -> n -> n
forall a. Num a => a -> a -> a
* n
s) n -> n -> n
forall a. Fractional a => a -> a -> a
/ v n -> n
forall a. Num a => v a -> a
forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance v n
v'
| Bool
otherwise = v n -> Max n
env v n
v'
where
dp :: n
dp = v n
v' v n -> v n -> n
forall a. Num a => v a -> v a -> a
forall (f :: * -> *) a. (Metric f, Num a) => f a -> f a -> a
`dot` v n
v
beneath :: (Metric v, OrderedField n, Monoid' m)
=> QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
beneath :: forall (v :: * -> *) n m b.
(Metric v, OrderedField n, Monoid' m) =>
QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
beneath = (QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m)
-> QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
forall a b c. (a -> b -> c) -> b -> a -> c
flip QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Semigroup m) =>
QDiagram b v n m -> QDiagram b v n m -> QDiagram b v n m
atop
infixl 6 `beneath`
beside :: (Juxtaposable a, Semigroup a) => Vn a -> a -> a -> a
beside :: forall a. (Juxtaposable a, Semigroup a) => Vn a -> a -> a -> a
beside Vn a
v a
d1 a
d2 = a
d1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> Vn a -> a -> a -> a
forall a. Juxtaposable a => Vn a -> a -> a -> a
juxtapose Vn a
v a
d1 a
d2
atDirection :: (InSpace v n a, Metric v, Floating n, Juxtaposable a, Semigroup a)
=> Direction v n -> a -> a -> a
atDirection :: forall (v :: * -> *) n a.
(InSpace v n a, Metric v, Floating n, Juxtaposable a,
Semigroup a) =>
Direction v n -> a -> a -> a
atDirection = v n -> a -> a -> a
Vn a -> a -> a -> a
forall a. (Juxtaposable a, Semigroup a) => Vn a -> a -> a -> a
beside (v n -> a -> a -> a)
-> (Direction v n -> v n) -> Direction v n -> a -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Direction v n -> v n
forall (v :: * -> *) n.
(Metric v, Floating n) =>
Direction v n -> v n
fromDirection
appends :: (Juxtaposable a, Monoid' a) => a -> [(Vn a,a)] -> a
appends :: forall a. (Juxtaposable a, Monoid' a) => a -> [(Vn a, a)] -> a
appends a
d1 [(Vn a, a)]
apps = a
d1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> [a] -> a
forall a. Monoid a => [a] -> a
mconcat (((Vn a, a) -> a) -> [(Vn a, a)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (\(Vn a
v,a
d) -> Vn a -> a -> a -> a
forall a. Juxtaposable a => Vn a -> a -> a -> a
juxtapose Vn a
v a
d1 a
d) [(Vn a, a)]
apps)
position :: (InSpace v n a, HasOrigin a, Monoid' a) => [(Point v n, a)] -> a
position :: forall (v :: * -> *) n a.
(InSpace v n a, HasOrigin a, Monoid' a) =>
[(Point v n, a)] -> a
position = [a] -> a
forall a. Monoid a => [a] -> a
mconcat ([a] -> a) -> ([(Point v n, a)] -> [a]) -> [(Point v n, a)] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Point v n, a) -> a) -> [(Point v n, a)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map ((Point v n -> a -> a) -> (Point v n, a) -> a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Point v n -> a -> a
forall (v :: * -> *) n t.
(InSpace v n t, HasOrigin t) =>
Point v n -> t -> t
moveTo)
atPoints :: (InSpace v n a, HasOrigin a, Monoid' a) => [Point v n] -> [a] -> a
atPoints :: forall (v :: * -> *) n a.
(InSpace v n a, HasOrigin a, Monoid' a) =>
[Point v n] -> [a] -> a
atPoints [Point v n]
ps [a]
as = [(Point v n, a)] -> a
forall (v :: * -> *) n a.
(InSpace v n a, HasOrigin a, Monoid' a) =>
[(Point v n, a)] -> a
position ([(Point v n, a)] -> a) -> [(Point v n, a)] -> a
forall a b. (a -> b) -> a -> b
$ [Point v n] -> [a] -> [(Point v n, a)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Point v n]
ps [a]
as
data CatMethod = Cat
| Distrib
data CatOpts n = CatOpts { forall n. CatOpts n -> CatMethod
_catMethod :: CatMethod
, forall n. CatOpts n -> n
_sep :: n
, forall n. CatOpts n -> Proxy n
catOptsvProxy :: Proxy n
}
makeLensesWith (lensRules & generateSignatures .~ False) ''CatOpts
catMethod :: Lens' (CatOpts n) CatMethod
sep :: Lens' (CatOpts n) n
instance Num n => Default (CatOpts n) where
def :: CatOpts n
def = CatOpts { _catMethod :: CatMethod
_catMethod = CatMethod
Cat
, _sep :: n
_sep = n
0
, catOptsvProxy :: Proxy n
catOptsvProxy = Proxy n
forall {k} (t :: k). Proxy t
Proxy
}
cat :: (InSpace v n a, Metric v, Floating n, Juxtaposable a, Monoid' a, HasOrigin a)
=> v n -> [a] -> a
cat :: forall (v :: * -> *) n a.
(InSpace v n a, Metric v, Floating n, Juxtaposable a, Monoid' a,
HasOrigin a) =>
v n -> [a] -> a
cat v n
v = v n -> CatOpts n -> [a] -> a
forall (v :: * -> *) n a.
(InSpace v n a, Metric v, Floating n, Juxtaposable a, Monoid' a,
HasOrigin a) =>
v n -> CatOpts n -> [a] -> a
cat' v n
v CatOpts n
forall a. Default a => a
def
cat' :: (InSpace v n a, Metric v, Floating n, Juxtaposable a, Monoid' a, HasOrigin a)
=> v n -> CatOpts n -> [a] -> a
cat' :: forall (v :: * -> *) n a.
(InSpace v n a, Metric v, Floating n, Juxtaposable a, Monoid' a,
HasOrigin a) =>
v n -> CatOpts n -> [a] -> a
cat' v n
v (CatOpts { _catMethod :: forall n. CatOpts n -> CatMethod
_catMethod = CatMethod
Cat, _sep :: forall n. CatOpts n -> n
_sep = n
s }) = (a -> a -> a) -> a -> [a] -> a
forall a. (a -> a -> a) -> a -> [a] -> a
foldB a -> a -> a
comb a
forall a. Monoid a => a
mempty
where comb :: a -> a -> a
comb a
d1 a
d2 = a
d1 a -> a -> a
forall a. Semigroup a => a -> a -> a
<> (Vn a -> a -> a -> a
forall a. Juxtaposable a => Vn a -> a -> a -> a
juxtapose v n
Vn a
v a
d1 a
d2 a -> (a -> a) -> a
forall a b. a -> (a -> b) -> b
# v n -> a -> a
forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, HasOrigin t) =>
v n -> t -> t
moveOriginBy v n
vs)
vs :: v n
vs = n
s n -> v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ v n -> v n
forall a. Floating a => v a -> v a
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated v n
v)
cat' v n
v (CatOpts { _catMethod :: forall n. CatOpts n -> CatMethod
_catMethod = CatMethod
Distrib, _sep :: forall n. CatOpts n -> n
_sep = n
s }) =
[(Point v n, a)] -> a
forall (v :: * -> *) n a.
(InSpace v n a, HasOrigin a, Monoid' a) =>
[(Point v n, a)] -> a
position ([(Point v n, a)] -> a) -> ([a] -> [(Point v n, a)]) -> [a] -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Point v n] -> [a] -> [(Point v n, a)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((Point v n -> Point v n) -> Point v n -> [Point v n]
forall a. (a -> a) -> a -> [a]
iterate (Point v n -> Diff (Point v) n -> Point v n
forall a. Num a => Point v a -> Diff (Point v) a -> Point v a
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ (n
s n -> v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => a -> f a -> f a
*^ v n -> v n
forall a. Floating a => v a -> v a
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm v n
v)) Point v n
forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin)
composeAligned
:: (Monoid' m, Floating n, Ord n, Metric v)
=> (QDiagram b v n m -> QDiagram b v n m)
-> ([QDiagram b v n m] -> QDiagram b v n m)
-> ([QDiagram b v n m] -> QDiagram b v n m)
composeAligned :: forall m n (v :: * -> *) b.
(Monoid' m, Floating n, Ord n, Metric v) =>
(QDiagram b v n m -> QDiagram b v n m)
-> ([QDiagram b v n m] -> QDiagram b v n m)
-> [QDiagram b v n m]
-> QDiagram b v n m
composeAligned QDiagram b v n m -> QDiagram b v n m
_ [QDiagram b v n m] -> QDiagram b v n m
combine [] = [QDiagram b v n m] -> QDiagram b v n m
combine []
composeAligned QDiagram b v n m -> QDiagram b v n m
algn [QDiagram b v n m] -> QDiagram b v n m
comb (QDiagram b v n m
d:[QDiagram b v n m]
ds) = ([QDiagram b v n m] -> QDiagram b v n m
comb ([QDiagram b v n m] -> QDiagram b v n m)
-> [QDiagram b v n m] -> QDiagram b v n m
forall a b. (a -> b) -> a -> b
$ (QDiagram b v n m -> QDiagram b v n m)
-> [QDiagram b v n m] -> [QDiagram b v n m]
forall a b. (a -> b) -> [a] -> [b]
map QDiagram b v n m -> QDiagram b v n m
algn (QDiagram b v n m
dQDiagram b v n m -> [QDiagram b v n m] -> [QDiagram b v n m]
forall a. a -> [a] -> [a]
:[QDiagram b v n m]
ds)) QDiagram b v n m
-> (QDiagram b v n m -> QDiagram b v n m) -> QDiagram b v n m
forall a b. a -> (a -> b) -> b
# Point (V (QDiagram b v n m)) (N (QDiagram b v n m))
-> QDiagram b v n m -> QDiagram b v n m
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo Point v n
Point (V (QDiagram b v n m)) (N (QDiagram b v n m))
l
where
mss :: Maybe [Subdiagram b v n m]
mss = ( (() () -> QDiagram b v n m -> QDiagram b v n m
forall q a. (Qualifiable q, IsName a) => a -> q -> q
forall a. IsName a => a -> QDiagram b v n m -> QDiagram b v n m
.>> QDiagram b v n m
d)
# named () -- Mark the origin
# algn -- Apply the alignment function
)
QDiagram b v n m
-> Getting
(Maybe [Subdiagram b v n m])
(QDiagram b v n m)
(Maybe [Subdiagram b v n m])
-> Maybe [Subdiagram b v n m]
forall s a. s -> Getting a s a -> a
^. (SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m))
-> QDiagram b v n m
-> Const (Maybe [Subdiagram b v n m]) (QDiagram b v n m)
Lens' (QDiagram b v n m) (SubMap b v n m)
forall (v :: * -> *) m n b.
(Metric v, Semigroup m, OrderedField n) =>
Lens' (QDiagram b v n m) (SubMap b v n m)
subMap ((SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m))
-> QDiagram b v n m
-> Const (Maybe [Subdiagram b v n m]) (QDiagram b v n m))
-> ((Maybe [Subdiagram b v n m]
-> Const (Maybe [Subdiagram b v n m]) (Maybe [Subdiagram b v n m]))
-> SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m))
-> Getting
(Maybe [Subdiagram b v n m])
(QDiagram b v n m)
(Maybe [Subdiagram b v n m])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (SubMap b v n m)
-> Const (Maybe [Subdiagram b v n m]) (Unwrapped (SubMap b v n m)))
-> SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m)
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
Iso
(SubMap b v n m)
(SubMap b v n m)
(Unwrapped (SubMap b v n m))
(Unwrapped (SubMap b v n m))
_Wrapped ((Unwrapped (SubMap b v n m)
-> Const (Maybe [Subdiagram b v n m]) (Unwrapped (SubMap b v n m)))
-> SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m))
-> ((Maybe [Subdiagram b v n m]
-> Const (Maybe [Subdiagram b v n m]) (Maybe [Subdiagram b v n m]))
-> Unwrapped (SubMap b v n m)
-> Const (Maybe [Subdiagram b v n m]) (Unwrapped (SubMap b v n m)))
-> (Maybe [Subdiagram b v n m]
-> Const (Maybe [Subdiagram b v n m]) (Maybe [Subdiagram b v n m]))
-> SubMap b v n m
-> Const (Maybe [Subdiagram b v n m]) (SubMap b v n m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Unwrapped (SubMap b v n m))
-> Lens'
(Unwrapped (SubMap b v n m))
(Maybe (IxValue (Unwrapped (SubMap b v n m))))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
Control.Lens.at (() -> Name
forall a. IsName a => a -> Name
toName ())
l :: Point v n
l = Subdiagram b v n m -> Point v n
forall (v :: * -> *) n b m.
(Additive v, Num n) =>
Subdiagram b v n m -> Point v n
location (Subdiagram b v n m -> Point v n)
-> (Maybe [Subdiagram b v n m] -> Subdiagram b v n m)
-> Maybe [Subdiagram b v n m]
-> Point v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Subdiagram b v n m] -> Subdiagram b v n m
forall a. HasCallStack => [a] -> a
head ([Subdiagram b v n m] -> Subdiagram b v n m)
-> (Maybe [Subdiagram b v n m] -> [Subdiagram b v n m])
-> Maybe [Subdiagram b v n m]
-> Subdiagram b v n m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe [Subdiagram b v n m] -> [Subdiagram b v n m]
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe [Subdiagram b v n m] -> Point v n)
-> Maybe [Subdiagram b v n m] -> Point v n
forall a b. (a -> b) -> a -> b
$ Maybe [Subdiagram b v n m]
mss