{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FunctionalDependencies #-}
module Plots.Types.Line
(
trailPlot
, trailPlot'
, pathPlot
, pathPlot'
, linePlot
, linePlot'
, smoothLinePlot
, smoothLinePlot'
, mkTrail
, mkTrailOf
, mkPath
, mkPathOf
) where
import Control.Monad.State.Lazy
import qualified Data.Foldable as F
import Diagrams.Coordinates.Isomorphic
import Diagrams.Prelude
import Plots.Axis
import Plots.Types
trailPlot
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Trail v n
-> State (Plot (Path v n) b) ()
-> m ()
trailPlot :: forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Trail v n -> State (Plot (Path v n) b) () -> m ()
trailPlot = Path v n -> State (Plot (Path v n) b) () -> m ()
forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Path v n -> State (Plot (Path v n) b) () -> m ()
pathPlot (Path v n -> State (Plot (Path v n) b) () -> m ())
-> (Trail v n -> Path v n)
-> Trail v n
-> State (Plot (Path v n) b) ()
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail v n -> Path v n
Trail v n -> Path (V (Trail v n)) (N (Trail v n))
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath
trailPlot'
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Trail v n
-> m ()
trailPlot' :: forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Trail v n -> m ()
trailPlot' = Path (BaseSpace c) n -> m ()
forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Path v n -> m ()
pathPlot' (Path (BaseSpace c) n -> m ())
-> (Trail v n -> Path (BaseSpace c) n) -> Trail v n -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail v n -> Path (V (Trail v n)) (N (Trail v n))
Trail v n -> Path (BaseSpace c) n
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath
pathPlot
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Path v n
-> State (Plot (Path v n) b) ()
-> m ()
pathPlot :: forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Path v n -> State (Plot (Path v n) b) () -> m ()
pathPlot = Path v n -> State (Plot (Path v n) b) () -> m ()
forall (c :: * -> *) n p b (m :: * -> *).
(InSpace (BaseSpace c) n p, MonadState (Axis b c n) m,
Plotable p b) =>
p -> State (Plot p b) () -> m ()
addPlotable
pathPlot'
:: (BaseSpace c ~ v,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> Path v n
-> m ()
pathPlot' :: forall (c :: * -> *) (v :: * -> *) n b (m :: * -> *).
(BaseSpace c ~ v, Plotable (Path v n) b,
MonadState (Axis b c n) m) =>
Path v n -> m ()
pathPlot' = Path v n -> m ()
forall (v :: * -> *) n p b (m :: * -> *).
(InSpace (BaseSpace v) n p, MonadState (Axis b v n) m,
Plotable p b) =>
p -> m ()
addPlotable'
linePlot
:: (BaseSpace c ~ v,
Metric v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> f p
-> State (Plot (Path v n) b) ()
-> m ()
linePlot :: forall (c :: * -> *) (v :: * -> *) (f :: * -> *) n p b
(m :: * -> *).
(BaseSpace c ~ v, Metric v, Foldable f, PointLike v n p,
Plotable (Path v n) b, MonadState (Axis b c n) m) =>
f p -> State (Plot (Path v n) b) () -> m ()
linePlot = Path v n -> State (Plot (Path v n) b) () -> m ()
forall (c :: * -> *) n p b (m :: * -> *).
(InSpace (BaseSpace c) n p, MonadState (Axis b c n) m,
Plotable p b) =>
p -> State (Plot p b) () -> m ()
addPlotable (Path v n -> State (Plot (Path v n) b) () -> m ())
-> (f p -> Path v n) -> f p -> State (Plot (Path v n) b) () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Trail v n) -> Path v n
Located (Trail v n)
-> Path (V (Located (Trail v n))) (N (Located (Trail v n)))
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath (Located (Trail v n) -> Path v n)
-> (f p -> Located (Trail v n)) -> f p -> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f p -> Located (Trail v n)
forall (v :: * -> *) n p (f :: * -> *).
(PointLike v n p, OrderedField n, Foldable f) =>
f p -> Located (Trail v n)
mkTrail
linePlot'
:: (BaseSpace c ~ v,
Metric v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
MonadState (Axis b c n) m)
=> f p
-> m ()
linePlot' :: forall (c :: * -> *) (v :: * -> *) (f :: * -> *) n p b
(m :: * -> *).
(BaseSpace c ~ v, Metric v, Foldable f, PointLike v n p,
Plotable (Path v n) b, MonadState (Axis b c n) m) =>
f p -> m ()
linePlot' = Path (BaseSpace c) n -> m ()
forall (v :: * -> *) n p b (m :: * -> *).
(InSpace (BaseSpace v) n p, MonadState (Axis b v n) m,
Plotable p b) =>
p -> m ()
addPlotable' (Path (BaseSpace c) n -> m ())
-> (f p -> Path (BaseSpace c) n) -> f p -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Trail (BaseSpace c) n)
-> Path
(V (Located (Trail (BaseSpace c) n)))
(N (Located (Trail (BaseSpace c) n)))
Located (Trail (BaseSpace c) n) -> Path (BaseSpace c) n
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath (Located (Trail (BaseSpace c) n) -> Path (BaseSpace c) n)
-> (f p -> Located (Trail (BaseSpace c) n))
-> f p
-> Path (BaseSpace c) n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f p -> Located (Trail (BaseSpace c) n)
forall (v :: * -> *) n p (f :: * -> *).
(PointLike v n p, OrderedField n, Foldable f) =>
f p -> Located (Trail v n)
mkTrail
smoothLinePlot
:: (BaseSpace c ~ v,
F.Foldable f,
Metric v,
PointLike v n p,
Plotable (Path v n) b,
Fractional (v n),
MonadState (Axis b c n) m)
=> f p
-> State (Plot (Path v n) b) ()
-> m ()
smoothLinePlot :: forall (c :: * -> *) (v :: * -> *) (f :: * -> *) n p b
(m :: * -> *).
(BaseSpace c ~ v, Foldable f, Metric v, PointLike v n p,
Plotable (Path v n) b, Fractional (v n),
MonadState (Axis b c n) m) =>
f p -> State (Plot (Path v n) b) () -> m ()
smoothLinePlot = Path v n -> State (Plot (Path v n) b) () -> m ()
forall (c :: * -> *) n p b (m :: * -> *).
(InSpace (BaseSpace c) n p, MonadState (Axis b c n) m,
Plotable p b) =>
p -> State (Plot p b) () -> m ()
addPlotable (Path v n -> State (Plot (Path v n) b) () -> m ())
-> (f p -> Path v n) -> f p -> State (Plot (Path v n) b) () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> [Point v n] -> Path v n
forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t, Fractional (v n)) =>
Bool -> [Point v n] -> t
cubicSpline Bool
False ([Point v n] -> Path v n)
-> (f p -> [Point v n]) -> f p -> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting (Endo [Point v n]) (f p) (Point v n) -> f p -> [Point v n]
forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf ((p -> Const (Endo [Point v n]) p)
-> f p -> Const (Endo [Point v n]) (f p)
forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
IndexedFold Int (f p) p
folded ((p -> Const (Endo [Point v n]) p)
-> f p -> Const (Endo [Point v n]) (f p))
-> ((Point v n -> Const (Endo [Point v n]) (Point v n))
-> p -> Const (Endo [Point v n]) p)
-> Getting (Endo [Point v n]) (f p) (Point v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Point v n -> Const (Endo [Point v n]) (Point v n))
-> p -> Const (Endo [Point v n]) p
forall (v :: * -> *) n a. PointLike v n a => Iso' a (Point v n)
Iso' p (Point v n)
unpointLike)
smoothLinePlot'
:: (BaseSpace c ~ v,
F.Foldable f,
PointLike v n p,
Plotable (Path v n) b,
Fractional (v n),
MonadState (Axis b c n) m)
=> f p
-> m ()
smoothLinePlot' :: forall (c :: * -> *) (v :: * -> *) (f :: * -> *) n p b
(m :: * -> *).
(BaseSpace c ~ v, Foldable f, PointLike v n p,
Plotable (Path v n) b, Fractional (v n),
MonadState (Axis b c n) m) =>
f p -> m ()
smoothLinePlot' f p
xs = f p -> State (Plot (Path (BaseSpace c) n) b) () -> m ()
forall (c :: * -> *) (v :: * -> *) (f :: * -> *) n p b
(m :: * -> *).
(BaseSpace c ~ v, Foldable f, Metric v, PointLike v n p,
Plotable (Path v n) b, Fractional (v n),
MonadState (Axis b c n) m) =>
f p -> State (Plot (Path v n) b) () -> m ()
smoothLinePlot f p
xs (() -> State (Plot (Path (BaseSpace c) n) b) ()
forall a. a -> StateT (Plot (Path (BaseSpace c) n) b) Identity a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
mkTrail :: (PointLike v n p, OrderedField n, F.Foldable f) => f p -> Located (Trail v n)
mkTrail :: forall (v :: * -> *) n p (f :: * -> *).
(PointLike v n p, OrderedField n, Foldable f) =>
f p -> Located (Trail v n)
mkTrail = Fold (f p) p -> f p -> Located (Trail v n)
forall (v :: * -> *) n p s.
(PointLike v n p, OrderedField n) =>
Fold s p -> s -> Located (Trail v n)
mkTrailOf (p -> f p) -> f p -> f (f p)
Fold (f p) p
forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
IndexedFold Int (f p) p
folded
mkTrailOf :: (PointLike v n p, OrderedField n) => Fold s p -> s -> Located (Trail v n)
mkTrailOf :: forall (v :: * -> *) n p s.
(PointLike v n p, OrderedField n) =>
Fold s p -> s -> Located (Trail v n)
mkTrailOf Fold s p
f s
ps = [Point (V (Located (Trail v n))) (N (Located (Trail v n)))]
-> Located (Trail v n)
forall t. TrailLike t => [Point (V t) (N t)] -> t
fromVertices ([Point (V (Located (Trail v n))) (N (Located (Trail v n)))]
-> Located (Trail v n))
-> [Point (V (Located (Trail v n))) (N (Located (Trail v n)))]
-> Located (Trail v n)
forall a b. (a -> b) -> a -> b
$ Getting (Endo [Point v n]) s (Point v n) -> s -> [Point v n]
forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf ((p -> Const (Endo [Point v n]) p)
-> s -> Const (Endo [Point v n]) s
Fold s p
f ((p -> Const (Endo [Point v n]) p)
-> s -> Const (Endo [Point v n]) s)
-> ((Point v n -> Const (Endo [Point v n]) (Point v n))
-> p -> Const (Endo [Point v n]) p)
-> Getting (Endo [Point v n]) s (Point v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Point v n -> Const (Endo [Point v n]) (Point v n))
-> p -> Const (Endo [Point v n]) p
forall (v :: * -> *) n a. PointLike v n a => Iso' a (Point v n)
Iso' p (Point v n)
unpointLike) s
ps
mkPath :: (PointLike v n p, OrderedField n, F.Foldable f, F.Foldable g) => g (f p) -> Path v n
mkPath :: forall (v :: * -> *) n p (f :: * -> *) (g :: * -> *).
(PointLike v n p, OrderedField n, Foldable f, Foldable g) =>
g (f p) -> Path v n
mkPath g (f p)
pss = [Located (Trail v n)]
-> Path (V [Located (Trail v n)]) (N [Located (Trail v n)])
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath ([Located (Trail v n)]
-> Path (V [Located (Trail v n)]) (N [Located (Trail v n)]))
-> [Located (Trail v n)]
-> Path (V [Located (Trail v n)]) (N [Located (Trail v n)])
forall a b. (a -> b) -> a -> b
$ (f p -> Located (Trail v n)) -> [f p] -> [Located (Trail v n)]
forall a b. (a -> b) -> [a] -> [b]
map f p -> Located (Trail v n)
forall (v :: * -> *) n p (f :: * -> *).
(PointLike v n p, OrderedField n, Foldable f) =>
f p -> Located (Trail v n)
mkTrail (g (f p) -> [f p]
forall a. g a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList g (f p)
pss)
mkPathOf :: (PointLike v n p, OrderedField n) => Fold s t -> Fold t p -> s -> Path v n
mkPathOf :: forall (v :: * -> *) n p s t.
(PointLike v n p, OrderedField n) =>
Fold s t -> Fold t p -> s -> Path v n
mkPathOf Fold s t
f1 Fold t p
f2 s
as = [Located (Trail v n)] -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path ([Located (Trail v n)] -> Path v n)
-> [Located (Trail v n)] -> Path v n
forall a b. (a -> b) -> a -> b
$ (t -> Located (Trail v n)) -> [t] -> [Located (Trail v n)]
forall a b. (a -> b) -> [a] -> [b]
map (Fold t p -> t -> Located (Trail v n)
forall (v :: * -> *) n p s.
(PointLike v n p, OrderedField n) =>
Fold s p -> s -> Located (Trail v n)
mkTrailOf (p -> f p) -> t -> f t
Fold t p
f2) (Getting (Endo [t]) s t -> s -> [t]
forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf Getting (Endo [t]) s t
Fold s t
f1 s
as)