{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Diagrams.TrailLike
(
TrailLike(..)
, fromSegments, fromLocSegments, fromOffsets, fromLocOffsets, fromVertices
, (~~), explodeTrail
) where
import Control.Lens (view, _Unwrapped')
import Diagrams.Core
import Diagrams.Located
import Diagrams.Segment
import Diagrams.Trail
import Linear.Affine
import Linear.Metric
import Linear.Vector
class (Metric (V t), OrderedField (N t)) => TrailLike t where
trailLike
:: Located (Trail (V t) (N t))
-> t
instance (Metric v, OrderedField n) => TrailLike [Point v n] where
trailLike :: Located (Trail (V [Point v n]) (N [Point v n])) -> [Point v n]
trailLike = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailPoints
instance (Metric v, OrderedField n) => TrailLike (Trail' Line v n) where
trailLike :: Located (Trail (V (Trail' Line v n)) (N (Trail' Line v n)))
-> Trail' Line v n
trailLike = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail forall a. a -> a
id forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Located a -> a
unLoc
instance (Metric v, OrderedField n) => TrailLike (Trail' Loop v n) where
trailLike :: Located (Trail (V (Trail' Loop v n)) (N (Trail' Loop v n)))
-> Trail' Loop v n
trailLike = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Located a -> a
unLoc
instance (Metric v, OrderedField n) => TrailLike (Trail v n) where
trailLike :: Located (Trail (V (Trail v n)) (N (Trail v n))) -> Trail v n
trailLike = forall a. Located a -> a
unLoc
instance TrailLike t => TrailLike (TransInv t) where
trailLike :: Located (Trail (V (TransInv t)) (N (TransInv t))) -> TransInv t
trailLike = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s. Wrapped s => Iso' (Unwrapped s) s
_Unwrapped' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike
instance TrailLike t => TrailLike (Located t) where
trailLike :: Located (Trail (V (Located t)) (N (Located t))) -> Located t
trailLike Located (Trail (V (Located t)) (N (Located t)))
t = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike Located (Trail (V (Located t)) (N (Located t)))
t forall a. a -> Point (V a) (N a) -> Located a
`at` forall a. Located a -> Point (V a) (N a)
loc Located (Trail (V (Located t)) (N (Located t)))
t
fromSegments :: TrailLike t => [Segment Closed (V t) (N t)] -> t
fromSegments :: forall t. TrailLike t => [Segment Closed (V t) (N t)] -> t
fromSegments = forall t. TrailLike t => Located [Segment Closed (V t) (N t)] -> t
fromLocSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin)
fromLocSegments :: TrailLike t => Located [Segment Closed (V t) (N t)] -> t
fromLocSegments :: forall t. TrailLike t => Located [Segment Closed (V t) (N t)] -> t
fromLocSegments = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments
fromOffsets :: TrailLike t => [Vn t] -> t
fromOffsets :: forall t. TrailLike t => [Vn t] -> t
fromOffsets = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[v n] -> Trail v n
trailFromOffsets
fromLocOffsets :: (V t ~ v, N t ~ n, V (v n) ~ v, N (v n) ~ n, TrailLike t) => Located [v n] -> t
fromLocOffsets :: forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, V (v n) ~ v, N (v n) ~ n, TrailLike t) =>
Located [v n] -> t
fromLocOffsets = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[v n] -> Trail v n
trailFromOffsets
fromVertices :: TrailLike t => [Point (V t) (N t)] -> t
fromVertices :: forall t. TrailLike t => [Point (V t) (N t)] -> t
fromVertices [] = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike (forall (v :: * -> *) n. (Metric v, OrderedField n) => Trail v n
emptyTrail forall a. a -> Point (V a) (N a) -> Located a
`at` forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin)
fromVertices ps :: [Point (V t) (N t)]
ps@(Point (V t) (N t)
p:[Point (V t) (N t)]
_) = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments (forall (v :: * -> *) n.
(Additive v, Num n) =>
[Point v n] -> [Segment Closed v n]
segmentsFromVertices [Point (V t) (N t)]
ps) forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V t) (N t)
p)
segmentsFromVertices :: (Additive v, Num n) => [Point v n] -> [Segment Closed v n]
segmentsFromVertices :: forall (v :: * -> *) n.
(Additive v, Num n) =>
[Point v n] -> [Segment Closed v n]
segmentsFromVertices [] = []
segmentsFromVertices vvs :: [Point v n]
vvs@(Point v n
_:[Point v n]
vs) = forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. v n -> Segment Closed v n
straight (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
(.-.)) [Point v n]
vvs [Point v n]
vs)
(~~) :: (V t ~ v, N t ~ n, TrailLike t) => Point v n -> Point v n -> t
Point v n
p1 ~~ :: forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t) =>
Point v n -> Point v n -> t
~~ Point v n
p2 = forall t. TrailLike t => [Point (V t) (N t)] -> t
fromVertices [Point v n
p1, Point v n
p2]
explodeTrail :: (V t ~ v, N t ~ n, TrailLike t) => Located (Trail v n) -> [t]
explodeTrail :: forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t) =>
Located (Trail v n) -> [t]
explodeTrail = forall a b. (a -> b) -> [a] -> [b]
map (Located (Segment Closed (V t) (N t)) -> t
mkTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n (v :: * -> *).
(Num n, Additive v) =>
FixedSegment v n -> Located (Segment Closed v n)
fromFixedSeg) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [FixedSegment v n]
fixTrail
where
mkTrail :: Located (Segment Closed (V t) (N t)) -> t
mkTrail = forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[]))