{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Diagrams.Path
(
Path(..), pathTrails
, ToPath (..)
, pathFromTrail
, pathFromTrailAt
, pathFromLocTrail
, pathPoints
, pathVertices'
, pathVertices
, pathOffsets
, pathCentroid
, pathLocSegments, fixPath
, scalePath
, reversePath
, explodePath
, partitionPath
) where
import Control.Arrow ((***))
import Control.Lens hiding (at, transform, ( # ))
import qualified Data.Foldable as F
import Data.List (partition)
import Data.Semigroup
import Data.Typeable
import Diagrams.Align
import Diagrams.Core
import Diagrams.Located
import Diagrams.Points
import Diagrams.Segment
import Diagrams.Trail
import Diagrams.TrailLike
import Diagrams.Transform
import Linear.Metric
import Linear.Vector
import Data.Serialize (Serialize)
import GHC.Generics (Generic)
newtype Path v n = Path [Located (Trail v n)]
deriving (b -> Path v n -> Path v n
NonEmpty (Path v n) -> Path v n
Path v n -> Path v n -> Path v n
(Path v n -> Path v n -> Path v n)
-> (NonEmpty (Path v n) -> Path v n)
-> (forall b. Integral b => b -> Path v n -> Path v n)
-> Semigroup (Path v n)
forall b. Integral b => b -> Path v n -> Path v n
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (v :: * -> *) n. NonEmpty (Path v n) -> Path v n
forall (v :: * -> *) n. Path v n -> Path v n -> Path v n
forall (v :: * -> *) n b. Integral b => b -> Path v n -> Path v n
stimes :: b -> Path v n -> Path v n
$cstimes :: forall (v :: * -> *) n b. Integral b => b -> Path v n -> Path v n
sconcat :: NonEmpty (Path v n) -> Path v n
$csconcat :: forall (v :: * -> *) n. NonEmpty (Path v n) -> Path v n
<> :: Path v n -> Path v n -> Path v n
$c<> :: forall (v :: * -> *) n. Path v n -> Path v n -> Path v n
Semigroup, Semigroup (Path v n)
Path v n
Semigroup (Path v n)
-> Path v n
-> (Path v n -> Path v n -> Path v n)
-> ([Path v n] -> Path v n)
-> Monoid (Path v n)
[Path v n] -> Path v n
Path v n -> Path v n -> Path v n
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (v :: * -> *) n. Semigroup (Path v n)
forall (v :: * -> *) n. Path v n
forall (v :: * -> *) n. [Path v n] -> Path v n
forall (v :: * -> *) n. Path v n -> Path v n -> Path v n
mconcat :: [Path v n] -> Path v n
$cmconcat :: forall (v :: * -> *) n. [Path v n] -> Path v n
mappend :: Path v n -> Path v n -> Path v n
$cmappend :: forall (v :: * -> *) n. Path v n -> Path v n -> Path v n
mempty :: Path v n
$cmempty :: forall (v :: * -> *) n. Path v n
$cp1Monoid :: forall (v :: * -> *) n. Semigroup (Path v n)
Monoid, (forall x. Path v n -> Rep (Path v n) x)
-> (forall x. Rep (Path v n) x -> Path v n) -> Generic (Path v n)
forall x. Rep (Path v n) x -> Path v n
forall x. Path v n -> Rep (Path v n) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (v :: * -> *) n x. Rep (Path v n) x -> Path v n
forall (v :: * -> *) n x. Path v n -> Rep (Path v n) x
$cto :: forall (v :: * -> *) n x. Rep (Path v n) x -> Path v n
$cfrom :: forall (v :: * -> *) n x. Path v n -> Rep (Path v n) x
Generic
, Typeable
)
instance (OrderedField n, Metric v, Serialize (v n), Serialize (V (v n) (N (v n)))) =>
Serialize (Path v n)
instance Wrapped (Path v n) where
type Unwrapped (Path v n) = [Located (Trail v n)]
_Wrapped' :: p (Unwrapped (Path v n)) (f (Unwrapped (Path v n)))
-> p (Path v n) (f (Path v n))
_Wrapped' = (Path v n -> [Located (Trail v n)])
-> ([Located (Trail v n)] -> Path v n)
-> Iso
(Path v n) (Path v n) [Located (Trail v n)] [Located (Trail v n)]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Path [Located (Trail v n)]
x) -> [Located (Trail v n)]
x) [Located (Trail v n)] -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
instance Rewrapped (Path v n) (Path v' n')
instance Each (Path v n) (Path v' n') (Located (Trail v n)) (Located (Trail v' n')) where
each :: (Located (Trail v n) -> f (Located (Trail v' n')))
-> Path v n -> f (Path v' n')
each = ([Located (Trail v n)] -> f [Located (Trail v' n')])
-> Path v n -> f (Path v' n')
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (([Located (Trail v n)] -> f [Located (Trail v' n')])
-> Path v n -> f (Path v' n'))
-> ((Located (Trail v n) -> f (Located (Trail v' n')))
-> [Located (Trail v n)] -> f [Located (Trail v' n')])
-> (Located (Trail v n) -> f (Located (Trail v' n')))
-> Path v n
-> f (Path v' n')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> f (Located (Trail v' n')))
-> [Located (Trail v n)] -> f [Located (Trail v' n')]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
instance AsEmpty (Path v n) where
_Empty :: p () (f ()) -> p (Path v n) (f (Path v n))
_Empty = p [Located (Trail v n)] (f [Located (Trail v n)])
-> p (Path v n) (f (Path v n))
forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' (p [Located (Trail v n)] (f [Located (Trail v n)])
-> p (Path v n) (f (Path v n)))
-> (p () (f ())
-> p [Located (Trail v n)] (f [Located (Trail v n)]))
-> p () (f ())
-> p (Path v n) (f (Path v n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p () (f ()) -> p [Located (Trail v n)] (f [Located (Trail v n)])
forall a. AsEmpty a => Prism' a ()
_Empty
instance Cons (Path v n) (Path v' n') (Located (Trail v n)) (Located (Trail v' n')) where
_Cons :: p (Located (Trail v n), Path v n)
(f (Located (Trail v' n'), Path v' n'))
-> p (Path v n) (f (Path v' n'))
_Cons = p [Located (Trail v n)] (f [Located (Trail v' n')])
-> p (Path v n) (f (Path v' n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p [Located (Trail v n)] (f [Located (Trail v' n')])
-> p (Path v n) (f (Path v' n')))
-> (p (Located (Trail v n), Path v n)
(f (Located (Trail v' n'), Path v' n'))
-> p [Located (Trail v n)] (f [Located (Trail v' n')]))
-> p (Located (Trail v n), Path v n)
(f (Located (Trail v' n'), Path v' n'))
-> p (Path v n) (f (Path v' n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Located (Trail v n), [Located (Trail v n)])
(f (Located (Trail v' n'), [Located (Trail v' n')]))
-> p [Located (Trail v n)] (f [Located (Trail v' n')])
forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
_Cons (p (Located (Trail v n), [Located (Trail v n)])
(f (Located (Trail v' n'), [Located (Trail v' n')]))
-> p [Located (Trail v n)] (f [Located (Trail v' n')]))
-> (p (Located (Trail v n), Path v n)
(f (Located (Trail v' n'), Path v' n'))
-> p (Located (Trail v n), [Located (Trail v n)])
(f (Located (Trail v' n'), [Located (Trail v' n')])))
-> p (Located (Trail v n), Path v n)
(f (Located (Trail v' n'), Path v' n'))
-> p [Located (Trail v n)] (f [Located (Trail v' n')])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
(Located (Trail v n))
(Located (Trail v' n'))
(Located (Trail v n))
(Located (Trail v' n'))
-> AnIso
[Located (Trail v n)]
[Located (Trail v' n')]
(Path v n)
(Path v' n')
-> Iso
(Located (Trail v n), [Located (Trail v n)])
(Located (Trail v' n'), [Located (Trail v' n')])
(Located (Trail v n), Path v n)
(Located (Trail v' n'), Path v' n')
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
(Located (Trail v n))
(Located (Trail v' n'))
(Located (Trail v n))
(Located (Trail v' n'))
forall a. a -> a
id AnIso
[Located (Trail v n)]
[Located (Trail v' n')]
(Path v n)
(Path v' n')
forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped
{-# INLINE _Cons #-}
instance Snoc (Path v n) (Path v' n') (Located (Trail v n)) (Located (Trail v' n')) where
_Snoc :: p (Path v n, Located (Trail v n))
(f (Path v' n', Located (Trail v' n')))
-> p (Path v n) (f (Path v' n'))
_Snoc = p [Located (Trail v n)] (f [Located (Trail v' n')])
-> p (Path v n) (f (Path v' n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p [Located (Trail v n)] (f [Located (Trail v' n')])
-> p (Path v n) (f (Path v' n')))
-> (p (Path v n, Located (Trail v n))
(f (Path v' n', Located (Trail v' n')))
-> p [Located (Trail v n)] (f [Located (Trail v' n')]))
-> p (Path v n, Located (Trail v n))
(f (Path v' n', Located (Trail v' n')))
-> p (Path v n) (f (Path v' n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p ([Located (Trail v n)], Located (Trail v n))
(f ([Located (Trail v' n')], Located (Trail v' n')))
-> p [Located (Trail v n)] (f [Located (Trail v' n')])
forall s t a b. Snoc s t a b => Prism s t (s, a) (t, b)
_Snoc (p ([Located (Trail v n)], Located (Trail v n))
(f ([Located (Trail v' n')], Located (Trail v' n')))
-> p [Located (Trail v n)] (f [Located (Trail v' n')]))
-> (p (Path v n, Located (Trail v n))
(f (Path v' n', Located (Trail v' n')))
-> p ([Located (Trail v n)], Located (Trail v n))
(f ([Located (Trail v' n')], Located (Trail v' n'))))
-> p (Path v n, Located (Trail v n))
(f (Path v' n', Located (Trail v' n')))
-> p [Located (Trail v n)] (f [Located (Trail v' n')])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
[Located (Trail v n)]
[Located (Trail v' n')]
(Path v n)
(Path v' n')
-> AnIso
(Located (Trail v n))
(Located (Trail v' n'))
(Located (Trail v n))
(Located (Trail v' n'))
-> Iso
([Located (Trail v n)], Located (Trail v n))
([Located (Trail v' n')], Located (Trail v' n'))
(Path v n, Located (Trail v n))
(Path v' n', Located (Trail v' n'))
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
[Located (Trail v n)]
[Located (Trail v' n')]
(Path v n)
(Path v' n')
forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped AnIso
(Located (Trail v n))
(Located (Trail v' n'))
(Located (Trail v n))
(Located (Trail v' n'))
forall a. a -> a
id
{-# INLINE _Snoc #-}
pathTrails :: Path v n -> [Located (Trail v n)]
pathTrails :: Path v n -> [Located (Trail v n)]
pathTrails = (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
deriving instance Show (v n) => Show (Path v n)
deriving instance Eq (v n) => Eq (Path v n)
deriving instance Ord (v n) => Ord (Path v n)
type instance V (Path v n) = v
type instance N (Path v n) = n
instance (Additive v, Num n) => HasOrigin (Path v n) where
moveOriginTo :: Point (V (Path v n)) (N (Path v n)) -> Path v n -> Path v n
moveOriginTo = ASetter
(Path v n) (Path v n) [Located (Trail v n)] [Located (Trail v n)]
-> ([Located (Trail v n)] -> [Located (Trail v n)])
-> Path v n
-> Path v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(Path v n) (Path v n) [Located (Trail v n)] [Located (Trail v n)]
forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' (([Located (Trail v n)] -> [Located (Trail v n)])
-> Path v n -> Path v n)
-> (Point v n -> [Located (Trail v n)] -> [Located (Trail v n)])
-> Point v n
-> Path v n
-> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> Located (Trail v n))
-> [Located (Trail v n)] -> [Located (Trail v n)]
forall a b. (a -> b) -> [a] -> [b]
map ((Located (Trail v n) -> Located (Trail v n))
-> [Located (Trail v n)] -> [Located (Trail v n)])
-> (Point v n -> Located (Trail v n) -> Located (Trail v n))
-> Point v n
-> [Located (Trail v n)]
-> [Located (Trail v n)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Point v n -> Located (Trail v n) -> Located (Trail v n)
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo
instance (Metric v, OrderedField n) => TrailLike (Path v n) where
trailLike :: Located (Trail (V (Path v n)) (N (Path v n))) -> Path v n
trailLike = [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) -> [Located (Trail v n)])
-> Located (Trail v n)
-> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n)
-> [Located (Trail v n)] -> [Located (Trail v n)]
forall a. a -> [a] -> [a]
:[])
instance (HasLinearMap v, Metric v, OrderedField n)
=> Transformable (Path v n) where
transform :: Transformation (V (Path v n)) (N (Path v n))
-> Path v n -> Path v n
transform = ASetter
(Path v n) (Path v n) [Located (Trail v n)] [Located (Trail v n)]
-> ([Located (Trail v n)] -> [Located (Trail v n)])
-> Path v n
-> Path v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
(Path v n) (Path v n) [Located (Trail v n)] [Located (Trail v n)]
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (([Located (Trail v n)] -> [Located (Trail v n)])
-> Path v n -> Path v n)
-> (Transformation v n
-> [Located (Trail v n)] -> [Located (Trail v n)])
-> Transformation v n
-> Path v n
-> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> Located (Trail v n))
-> [Located (Trail v n)] -> [Located (Trail v n)]
forall a b. (a -> b) -> [a] -> [b]
map ((Located (Trail v n) -> Located (Trail v n))
-> [Located (Trail v n)] -> [Located (Trail v n)])
-> (Transformation v n
-> Located (Trail v n) -> Located (Trail v n))
-> Transformation v n
-> [Located (Trail v n)]
-> [Located (Trail v n)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transformation v n -> Located (Trail v n) -> Located (Trail v n)
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
instance (Metric v, OrderedField n) => Enveloped (Path v n) where
getEnvelope :: Path v n -> Envelope (V (Path v n)) (N (Path v n))
getEnvelope = (Located (Trail v n) -> Envelope v n)
-> [Located (Trail v n)] -> Envelope v n
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap Located (Trail v n) -> Envelope v n
trailEnvelope ([Located (Trail v n)] -> Envelope v n)
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
where trailEnvelope :: Located (Trail v n) -> Envelope v n
trailEnvelope :: Located (Trail v n) -> Envelope v n
trailEnvelope (Located (Trail v n)
-> (Point (V (Trail v n)) (N (Trail v n)), Trail v n)
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail v n)) (N (Trail v n))
p, Trail v n
t)) = Point (V (Envelope v n)) (N (Envelope v n))
-> Envelope v n -> Envelope v n
forall t. HasOrigin t => Point (V t) (N t) -> t -> t
moveOriginTo ((-n
1) n -> Point v n -> Point v n
forall (v :: * -> *) n.
(Functor v, Num n) =>
n -> Point v n -> Point v n
*. Point v n
Point (V (Trail v n)) (N (Trail v n))
p) (Trail v n -> Envelope (V (Trail v n)) (N (Trail v n))
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope Trail v n
t)
instance (Metric v, OrderedField n) => Juxtaposable (Path v n) where
juxtapose :: Vn (Path v n) -> Path v n -> Path v n -> Path v n
juxtapose = Vn (Path v n) -> Path v n -> Path v n -> Path v n
forall a. (Enveloped a, HasOrigin a) => Vn a -> a -> a -> a
juxtaposeDefault
instance (Metric v, OrderedField n) => Alignable (Path v n) where
defaultBoundary :: v n -> Path v n -> Point v n
defaultBoundary = v n -> Path v n -> Point v n
forall a (v :: * -> *) n.
(V a ~ v, N a ~ n, Enveloped a) =>
v n -> a -> Point v n
envelopeBoundary
instance (HasLinearMap v, Metric v, OrderedField n)
=> Renderable (Path v n) NullBackend where
render :: NullBackend
-> Path v n -> Render NullBackend (V (Path v n)) (N (Path v n))
render NullBackend
_ Path v n
_ = Render NullBackend (V (Path v n)) (N (Path v n))
forall a. Monoid a => a
mempty
class ToPath t where
toPath :: (Metric (V t), OrderedField (N t)) => t -> Path (V t) (N t)
instance ToPath (Path v n) where
toPath :: Path v n -> Path (V (Path v n)) (N (Path v n))
toPath = Path v n -> Path (V (Path v n)) (N (Path v n))
forall a. a -> a
id
instance ToPath (Trail v n) where
toPath :: Trail v n -> Path (V (Trail v n)) (N (Trail v n))
toPath = Trail v n -> Path (V (Trail v n)) (N (Trail v n))
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Path v n
pathFromTrail
instance ToPath (Trail' l v n) where
toPath :: Trail' l v n -> Path (V (Trail' l v n)) (N (Trail' l v n))
toPath Trail' l v n
t = [Located (Trail v n)] -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path [Trail' l v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail Trail' l v n
t Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin]
instance ToPath (Located (Trail v n)) where
toPath :: Located (Trail v n)
-> Path (V (Located (Trail v n))) (N (Located (Trail v n)))
toPath = Located (Trail v n)
-> Path (V (Located (Trail v n))) (N (Located (Trail v n)))
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Path v n
pathFromLocTrail
instance ToPath (Located (Trail' l v n)) where
toPath :: Located (Trail' l v n)
-> Path (V (Located (Trail' l v n))) (N (Located (Trail' l v n)))
toPath = Located (Trail v n) -> Path v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Path v n
pathFromLocTrail (Located (Trail v n) -> Path v n)
-> (Located (Trail' l v n) -> Located (Trail v n))
-> Located (Trail' l v n)
-> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' l v n -> Trail v n)
-> Located (Trail' l v n) -> Located (Trail v n)
forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc Trail' l v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail
instance ToPath (Located (Segment Closed v n)) where
toPath :: Located (Segment Closed v n)
-> Path
(V (Located (Segment Closed v n)))
(N (Located (Segment Closed v n)))
toPath (Located (Segment Closed v n)
-> (Point (V (Segment Closed v n)) (N (Segment Closed v n)),
Segment Closed v n)
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Segment Closed v n)) (N (Segment Closed v n))
p,Segment Closed v n
seg))
= [Located (Trail v n)] -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path [[Segment Closed v n] -> Trail v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments [Segment Closed v n
seg] Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Segment Closed v n)) (N (Segment Closed v n))
Point (V (Trail v n)) (N (Trail v n))
p]
instance ToPath (Located [Segment Closed v n]) where
toPath :: Located [Segment Closed v n]
-> Path
(V (Located [Segment Closed v n]))
(N (Located [Segment Closed v n]))
toPath (Located [Segment Closed v n]
-> (Point (V [Segment Closed v n]) (N [Segment Closed v n]),
[Segment Closed v n])
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V [Segment Closed v n]) (N [Segment Closed v n])
p,[Segment Closed v n]
segs))
= [Located (Trail v n)] -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path [[Segment Closed v n] -> Trail v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments [Segment Closed v n]
segs Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V [Segment Closed v n]) (N [Segment Closed v n])
Point (V (Trail v n)) (N (Trail v n))
p]
instance ToPath (FixedSegment v n) where
toPath :: FixedSegment v n
-> Path (V (FixedSegment v n)) (N (FixedSegment v n))
toPath = Located (Segment Closed v n) -> Path v n
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath (Located (Segment Closed v n) -> Path v n)
-> (FixedSegment v n -> Located (Segment Closed v n))
-> FixedSegment v n
-> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedSegment v n -> Located (Segment Closed v n)
forall n (v :: * -> *).
(Num n, Additive v) =>
FixedSegment v n -> Located (Segment Closed v n)
fromFixedSeg
instance ToPath a => ToPath [a] where
toPath :: [a] -> Path (V [a]) (N [a])
toPath = (a -> Path (V a) (N a)) -> [a] -> Path (V a) (N a)
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
F.foldMap a -> Path (V a) (N a)
forall t.
(ToPath t, Metric (V t), OrderedField (N t)) =>
t -> Path (V t) (N t)
toPath
pathFromTrail :: (Metric v, OrderedField n) => Trail v n -> Path v n
pathFromTrail :: Trail v n -> Path v n
pathFromTrail = Located (Trail v n) -> Path v n
forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike (Located (Trail v n) -> Path v n)
-> (Trail v n -> Located (Trail v n)) -> Trail v n -> Path v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin)
pathFromTrailAt :: (Metric v, OrderedField n) => Trail v n -> Point v n -> Path v n
pathFromTrailAt :: Trail v n -> Point v n -> Path v n
pathFromTrailAt Trail v n
t Point v n
p = Located (Trail (V (Path v n)) (N (Path v n))) -> Path v n
forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike (Trail v n
t Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point v n
Point (V (Trail v n)) (N (Trail v n))
p)
pathFromLocTrail :: (Metric v, OrderedField n) => Located (Trail v n) -> Path v n
pathFromLocTrail :: Located (Trail v n) -> Path v n
pathFromLocTrail = Located (Trail v n) -> Path v n
forall t. TrailLike t => Located (Trail (V t) (N t)) -> t
trailLike
pathVertices' :: (Metric v, OrderedField n) => n -> Path v n -> [[Point v n]]
pathVertices' :: n -> Path v n -> [[Point v n]]
pathVertices' n
toler = (Located (Trail v n) -> [Point v n])
-> [Located (Trail v n)] -> [[Point v n]]
forall a b. (a -> b) -> [a] -> [b]
map (n -> Located (Trail v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail v n) -> [Point v n]
trailVertices' n
toler) ([Located (Trail v n)] -> [[Point v n]])
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> [[Point v n]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
pathVertices :: (Metric v, OrderedField n) => Path v n -> [[Point v n]]
pathVertices :: Path v n -> [[Point v n]]
pathVertices = (Located (Trail v n) -> [Point v n])
-> [Located (Trail v n)] -> [[Point v n]]
forall a b. (a -> b) -> [a] -> [b]
map Located (Trail v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailVertices ([Located (Trail v n)] -> [[Point v n]])
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> [[Point v n]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
pathPoints :: (Metric v, OrderedField n) => Path v n -> [[Point v n]]
pathPoints :: Path v n -> [[Point v n]]
pathPoints = (Located (Trail v n) -> [Point v n])
-> [Located (Trail v n)] -> [[Point v n]]
forall a b. (a -> b) -> [a] -> [b]
map Located (Trail v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailPoints ([Located (Trail v n)] -> [[Point v n]])
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> [[Point v n]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
pathOffsets :: (Metric v, OrderedField n) => Path v n -> [v n]
pathOffsets :: Path v n -> [v n]
pathOffsets = (Located (Trail v n) -> v n) -> [Located (Trail v n)] -> [v n]
forall a b. (a -> b) -> [a] -> [b]
map (Trail v n -> v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> v n
trailOffset (Trail v n -> v n)
-> (Located (Trail v n) -> Trail v n) -> Located (Trail v n) -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Trail v n) -> Trail v n
forall a. Located a -> a
unLoc) ([Located (Trail v n)] -> [v n])
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> [v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
pathCentroid :: (Metric v, OrderedField n) => Path v n -> Point v n
pathCentroid :: Path v n -> Point v n
pathCentroid = [Point v n] -> Point v n
forall (v :: * -> *) n.
(Additive v, Fractional n) =>
[Point v n] -> Point v n
centroid ([Point v n] -> Point v n)
-> (Path v n -> [Point v n]) -> Path v n -> Point v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Point v n]] -> [Point v n]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Point v n]] -> [Point v n])
-> (Path v n -> [[Point v n]]) -> Path v n -> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path v n -> [[Point v n]]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Path v n -> [[Point v n]]
pathVertices
pathLocSegments :: (Metric v, OrderedField n) => Path v n -> [[Located (Segment Closed v n)]]
pathLocSegments :: Path v n -> [[Located (Segment Closed v n)]]
pathLocSegments = (Located (Trail v n) -> [Located (Segment Closed v n)])
-> [Located (Trail v n)] -> [[Located (Segment Closed v n)]]
forall a b. (a -> b) -> [a] -> [b]
map Located (Trail v n) -> [Located (Segment Closed v n)]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments ([Located (Trail v n)] -> [[Located (Segment Closed v n)]])
-> (Path v n -> [Located (Trail v n)])
-> Path v n
-> [[Located (Segment Closed v n)]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
fixPath :: (Metric v, OrderedField n) => Path v n -> [[FixedSegment v n]]
fixPath :: Path v n -> [[FixedSegment v n]]
fixPath = (Located (Trail v n) -> [FixedSegment v n])
-> [Located (Trail v n)] -> [[FixedSegment v n]]
forall a b. (a -> b) -> [a] -> [b]
map Located (Trail v n) -> [FixedSegment v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [FixedSegment v n]
fixTrail ([Located (Trail v n)] -> [[FixedSegment v n]])
-> (Path v n -> [Located (Trail v n)])
-> Path v n
-> [[FixedSegment v n]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
explodePath :: (V t ~ v, N t ~ n, TrailLike t) => Path v n -> [[t]]
explodePath :: Path v n -> [[t]]
explodePath = (Located (Trail v n) -> [t]) -> [Located (Trail v n)] -> [[t]]
forall a b. (a -> b) -> [a] -> [b]
map Located (Trail v n) -> [t]
forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t) =>
Located (Trail v n) -> [t]
explodeTrail ([Located (Trail v n)] -> [[t]])
-> (Path v n -> [Located (Trail v n)]) -> Path v n -> [[t]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
partitionPath :: (Located (Trail v n) -> Bool) -> Path v n -> (Path v n, Path v n)
partitionPath :: (Located (Trail v n) -> Bool) -> Path v n -> (Path v n, Path v n)
partitionPath Located (Trail v n) -> Bool
p = (Getting (Path v n) [Located (Trail v n)] (Path v n)
-> [Located (Trail v n)] -> Path v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path v n) [Located (Trail v n)] (Path v n)
forall s. Wrapped s => Iso' (Unwrapped s) s
_Unwrapped' ([Located (Trail v n)] -> Path v n)
-> ([Located (Trail v n)] -> Path v n)
-> ([Located (Trail v n)], [Located (Trail v n)])
-> (Path v n, Path v n)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Getting (Path v n) [Located (Trail v n)] (Path v n)
-> [Located (Trail v n)] -> Path v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Path v n) [Located (Trail v n)] (Path v n)
forall s. Wrapped s => Iso' (Unwrapped s) s
_Unwrapped') (([Located (Trail v n)], [Located (Trail v n)])
-> (Path v n, Path v n))
-> (Path v n -> ([Located (Trail v n)], [Located (Trail v n)]))
-> Path v n
-> (Path v n, Path v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> Bool)
-> [Located (Trail v n)]
-> ([Located (Trail v n)], [Located (Trail v n)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Located (Trail v n) -> Bool
p ([Located (Trail v n)]
-> ([Located (Trail v n)], [Located (Trail v n)]))
-> (Path v n -> [Located (Trail v n)])
-> Path v n
-> ([Located (Trail v n)], [Located (Trail v n)])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped (Path v n) -> Path v n)
-> Path v n -> Unwrapped (Path v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (Path v n) -> Path v n
forall (v :: * -> *) n. [Located (Trail v n)] -> Path v n
Path
scalePath :: (HasLinearMap v, Metric v, OrderedField n) => n -> Path v n -> Path v n
scalePath :: n -> Path v n -> Path v n
scalePath n
d Path v n
p = AnIso (Path v n) (Path v n) (Path v n) (Path v n)
-> (Path v n -> Path v n) -> Path v n -> Path v n
forall s t a b. AnIso s t a b -> (t -> s) -> b -> a
under (Point v n -> Iso (Path v n) (Path v n) (Path v n) (Path v n)
forall (v :: * -> *) n a b.
(InSpace v n a, SameSpace a b, HasOrigin a, HasOrigin b) =>
Point v n -> Iso a b a b
movedFrom (Path v n -> Point v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Path v n -> Point v n
pathCentroid Path v n
p)) (n -> Path v n -> Path v n
forall (v :: * -> *) n a.
(InSpace v n a, Eq n, Fractional n, Transformable a) =>
n -> a -> a
scale n
d) Path v n
p
reversePath :: (Metric v, OrderedField n) => Path v n -> Path v n
reversePath :: Path v n -> Path v n
reversePath = ([Located (Trail v n)] -> Identity [Located (Trail v n)])
-> Path v n -> Identity (Path v n)
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (([Located (Trail v n)] -> Identity [Located (Trail v n)])
-> Path v n -> Identity (Path v n))
-> ((Located (Trail v n) -> Identity (Located (Trail v n)))
-> [Located (Trail v n)] -> Identity [Located (Trail v n)])
-> (Located (Trail v n) -> Identity (Located (Trail v n)))
-> Path v n
-> Identity (Path v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> Identity (Located (Trail v n)))
-> [Located (Trail v n)] -> Identity [Located (Trail v n)]
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped ((Located (Trail v n) -> Identity (Located (Trail v n)))
-> Path v n -> Identity (Path v n))
-> (Located (Trail v n) -> Located (Trail v n))
-> Path v n
-> Path v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Located (Trail v n) -> Located (Trail v n)
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Located (Trail v n)
reverseLocTrail
instance (Metric v, OrderedField n) => Reversing (Path v n) where
reversing :: Path v n -> Path v n
reversing = ([Located (Trail v n)] -> Identity [Located (Trail v n)])
-> Path v n -> Identity (Path v n)
forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' (([Located (Trail v n)] -> Identity [Located (Trail v n)])
-> Path v n -> Identity (Path v n))
-> ((Located (Trail v n) -> Identity (Located (Trail v n)))
-> [Located (Trail v n)] -> Identity [Located (Trail v n)])
-> (Located (Trail v n) -> Identity (Located (Trail v n)))
-> Path v n
-> Identity (Path v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Located (Trail v n) -> Identity (Located (Trail v n)))
-> [Located (Trail v n)] -> Identity [Located (Trail v n)]
forall (f :: * -> *) a b. Functor f => Setter (f a) (f b) a b
mapped ((Located (Trail v n) -> Identity (Located (Trail v n)))
-> Path v n -> Identity (Path v n))
-> (Located (Trail v n) -> Located (Trail v n))
-> Path v n
-> Path v n
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Located (Trail v n) -> Located (Trail v n)
forall t. Reversing t => t -> t
reversing