{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module Diagrams.Trail
(
Trail'(..)
, glueLine
, closeLine
, cutLoop
, Trail(..)
, _Line, _Loop
, _LocLine, _LocLoop
, wrapTrail, wrapLine, wrapLoop
, onTrail, onLine
, glueTrail, closeTrail, cutTrail
, emptyLine, emptyTrail
, lineFromVertices, trailFromVertices
, lineFromOffsets, trailFromOffsets
, lineFromSegments, trailFromSegments
, loopFromSegments
, withTrail', withTrail, withLine
, isLineEmpty, isTrailEmpty
, isLine, isLoop
, trailSegments, lineSegments, loopSegments
, onLineSegments
, trailOffsets, trailOffset
, lineOffsets, lineOffset, loopOffsets
, trailPoints, linePoints, loopPoints
, trailVertices', lineVertices', loopVertices'
, trailVertices, lineVertices, loopVertices
, trailLocSegments, fixTrail, unfixTrail
, reverseTrail, reverseLocTrail
, reverseLine, reverseLocLine
, reverseLoop, reverseLocLoop
, Line, Loop
, SegTree(..), trailMeasure, numSegs, offset
, GetSegment(..), getSegment, GetSegmentCodomain(..)
) where
import Control.Arrow ((***))
import Control.Lens hiding (at, transform, (<|), (|>))
import Data.FingerTree (FingerTree, ViewL (..), ViewR (..),
viewl, (<|), (|>))
import qualified Data.FingerTree as FT
import Data.Fixed
import qualified Data.Foldable as F
import Data.Monoid.MList
import Data.Semigroup
import qualified Numeric.Interval.Kaucher as I
import Diagrams.Core
import Diagrams.Located
import Diagrams.Parametric
import Diagrams.Segment
import Diagrams.Tangent
import Linear.Affine
import Linear.Metric
import Linear.Vector
import Data.Serialize (Serialize)
import qualified Data.Serialize as Serialize
type instance V (FingerTree m a) = V a
type instance N (FingerTree m a) = N a
instance (FT.Measured m a, Transformable a)
=> Transformable (FingerTree m a) where
transform :: Transformation (V (FingerTree m a)) (N (FingerTree m a))
-> FingerTree m a -> FingerTree m a
transform = forall v1 a1 v2 a2.
(Measured v1 a1, Measured v2 a2) =>
(a1 -> a2) -> FingerTree v1 a1 -> FingerTree v2 a2
FT.fmap' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform
instance (FT.Measured m a, FT.Measured n b)
=> Cons (FingerTree m a) (FingerTree n b) a b where
_Cons :: Prism
(FingerTree m a)
(FingerTree n b)
(a, FingerTree m a)
(b, FingerTree n b)
_Cons = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall v a. Measured v a => a -> FingerTree v a -> FingerTree v a
(FT.<|)) forall a b. (a -> b) -> a -> b
$ \FingerTree m a
aas -> case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree m a
aas of
a
a FT.:< FingerTree m a
as -> forall a b. b -> Either a b
Right (a
a, FingerTree m a
as)
ViewL (FingerTree m) a
EmptyL -> forall a b. a -> Either a b
Left forall a. Monoid a => a
mempty
{-# INLINE _Cons #-}
instance (FT.Measured m a, FT.Measured n b)
=> Snoc (FingerTree m a) (FingerTree n b) a b where
_Snoc :: Prism
(FingerTree m a)
(FingerTree n b)
(FingerTree m a, a)
(FingerTree n b, b)
_Snoc = forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
(FT.|>)) forall a b. (a -> b) -> a -> b
$ \FingerTree m a
aas -> case forall v a.
Measured v a =>
FingerTree v a -> ViewR (FingerTree v) a
FT.viewr FingerTree m a
aas of
FingerTree m a
as FT.:> a
a -> forall a b. b -> Either a b
Right (FingerTree m a
as, a
a)
ViewR (FingerTree m) a
EmptyR -> forall a b. a -> Either a b
Left forall a. Monoid a => a
mempty
{-# INLINE _Snoc #-}
newtype SegTree v n = SegTree (FingerTree (SegMeasure v n) (Segment Closed v n))
deriving (SegTree v n -> SegTree v n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (v :: * -> *) n.
Eq (v n) =>
SegTree v n -> SegTree v n -> Bool
/= :: SegTree v n -> SegTree v n -> Bool
$c/= :: forall (v :: * -> *) n.
Eq (v n) =>
SegTree v n -> SegTree v n -> Bool
== :: SegTree v n -> SegTree v n -> Bool
$c== :: forall (v :: * -> *) n.
Eq (v n) =>
SegTree v n -> SegTree v n -> Bool
Eq, SegTree v n -> SegTree v n -> Bool
SegTree v n -> SegTree v n -> Ordering
SegTree v n -> SegTree v n -> SegTree v n
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {v :: * -> *} {n}. Ord (v n) => Eq (SegTree v n)
forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Bool
forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Ordering
forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> SegTree v n
min :: SegTree v n -> SegTree v n -> SegTree v n
$cmin :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> SegTree v n
max :: SegTree v n -> SegTree v n -> SegTree v n
$cmax :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> SegTree v n
>= :: SegTree v n -> SegTree v n -> Bool
$c>= :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Bool
> :: SegTree v n -> SegTree v n -> Bool
$c> :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Bool
<= :: SegTree v n -> SegTree v n -> Bool
$c<= :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Bool
< :: SegTree v n -> SegTree v n -> Bool
$c< :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Bool
compare :: SegTree v n -> SegTree v n -> Ordering
$ccompare :: forall (v :: * -> *) n.
Ord (v n) =>
SegTree v n -> SegTree v n -> Ordering
Ord, Int -> SegTree v n -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (v :: * -> *) n. Show (v n) => Int -> SegTree v n -> ShowS
forall (v :: * -> *) n. Show (v n) => [SegTree v n] -> ShowS
forall (v :: * -> *) n. Show (v n) => SegTree v n -> String
showList :: [SegTree v n] -> ShowS
$cshowList :: forall (v :: * -> *) n. Show (v n) => [SegTree v n] -> ShowS
show :: SegTree v n -> String
$cshow :: forall (v :: * -> *) n. Show (v n) => SegTree v n -> String
showsPrec :: Int -> SegTree v n -> ShowS
$cshowsPrec :: forall (v :: * -> *) n. Show (v n) => Int -> SegTree v n -> ShowS
Show, SegTree v n
[SegTree v n] -> SegTree v n
SegTree v n -> SegTree v n -> SegTree v n
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall {v :: * -> *} {n}.
(Ord n, Floating n, Metric v) =>
Semigroup (SegTree v n)
forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
SegTree v n
forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
[SegTree v n] -> SegTree v n
forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
SegTree v n -> SegTree v n -> SegTree v n
mconcat :: [SegTree v n] -> SegTree v n
$cmconcat :: forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
[SegTree v n] -> SegTree v n
mappend :: SegTree v n -> SegTree v n -> SegTree v n
$cmappend :: forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
SegTree v n -> SegTree v n -> SegTree v n
mempty :: SegTree v n
$cmempty :: forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
SegTree v n
Monoid, Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
forall t. (Transformation (V t) (N t) -> t -> t) -> Transformable t
forall (v :: * -> *) n.
(Floating n, Ord n, Metric v) =>
Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
transform :: Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
$ctransform :: forall (v :: * -> *) n.
(Floating n, Ord n, Metric v) =>
Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
Transformable, FT.Measured (SegMeasure v n))
#if MIN_VERSION_base(4,9,0)
deriving instance (Ord n, Floating n, Metric v) => Semigroup (SegTree v n)
#endif
instance Wrapped (SegTree v n) where
type Unwrapped (SegTree v n) = FingerTree (SegMeasure v n) (Segment Closed v n)
_Wrapped' :: Iso' (SegTree v n) (Unwrapped (SegTree v n))
_Wrapped' = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
x) -> FingerTree (SegMeasure v n) (Segment Closed v n)
x) forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree
{-# INLINE _Wrapped' #-}
instance (Metric v, OrderedField n, Metric u, OrderedField n')
=> Cons (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') where
_Cons :: Prism
(SegTree v n)
(SegTree u n')
(Segment Closed v n, SegTree v n)
(Segment Closed u n', SegTree u n')
_Cons = forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
_Cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. a -> a
id forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped
{-# INLINE _Cons #-}
instance (Metric v, OrderedField n, Metric u, OrderedField n')
=> Snoc (SegTree v n) (SegTree u n') (Segment Closed v n) (Segment Closed u n') where
_Snoc :: Prism
(SegTree v n)
(SegTree u n')
(SegTree v n, Segment Closed v n)
(SegTree u n', Segment Closed u n')
_Snoc = forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Snoc s t a b => Prism s t (s, a) (t, b)
_Snoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped forall a. a -> a
id
{-# INLINE _Snoc #-}
instance Rewrapped (SegTree v n) (SegTree v' n')
type instance V (SegTree v n) = v
type instance N (SegTree v n) = n
type instance Codomain (SegTree v n) = v
instance (Metric v, OrderedField n, Real n)
=> Parametric (SegTree v n) where
atParam :: SegTree v n
-> N (SegTree v n) -> Codomain (SegTree v n) (N (SegTree v n))
atParam SegTree v n
t N (SegTree v n)
p = forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
t N (SegTree v n)
p
instance Num n => DomainBounds (SegTree v n)
instance (Metric v, OrderedField n, Real n)
=> EndValues (SegTree v n)
splitAtParam' :: (Metric v, OrderedField n, Real n)
=> SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
splitAtParam' :: forall (v :: * -> *) n.
(Metric v, OrderedField n, Real n) =>
SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
splitAtParam' (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) n
p
| n
tSegs forall a. Eq a => a -> a -> Bool
== n
0 = ((forall a. Monoid a => a
mempty , forall a. Monoid a => a
mempty ), forall a. a -> a
id)
| Bool
otherwise = ((forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
treeL, forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
treeR), n -> n
rescale)
where
tSegs :: n
tSegs = forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
t
splitParam :: n -> (n, n)
splitParam n
q | n
q forall a. Ord a => a -> a -> Bool
< n
0 = (n
0 , n
q forall a. Num a => a -> a -> a
* n
tSegs)
| n
q forall a. Ord a => a -> a -> Bool
>= n
1 = (n
tSegs forall a. Num a => a -> a -> a
- n
1, n
1 forall a. Num a => a -> a -> a
+ (n
q forall a. Num a => a -> a -> a
- n
1) forall a. Num a => a -> a -> a
* n
tSegs)
| Bool
otherwise = forall {b}. Real b => b -> (b, b)
propFrac forall a b. (a -> b) -> a -> b
$ n
q forall a. Num a => a -> a -> a
* n
tSegs
where propFrac :: b -> (b, b)
propFrac b
x = let m :: b
m = forall a. Real a => a -> a
mod1 b
x in (b
x forall a. Num a => a -> a -> a
- b
m, b
m)
(n
pSegs, n
pParam) = n -> (n, n)
splitParam n
p
(FingerTree (SegMeasure v n) (Segment Closed v n)
before, forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
viewl -> Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
after) = forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((n
pSegs forall a. Ord a => a -> a -> Bool
<) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs) FingerTree (SegMeasure v n) (Segment Closed v n)
t
(Segment Closed v n
segL, Segment Closed v n
segR) = Segment Closed v n
seg forall p. Sectionable p => p -> N p -> (p, p)
`splitAtParam` n
pParam
(FingerTree (SegMeasure v n) (Segment Closed v n)
treeL, FingerTree (SegMeasure v n) (Segment Closed v n)
treeR) | n
pParam forall a. Eq a => a -> a -> Bool
== n
0 = (FingerTree (SegMeasure v n) (Segment Closed v n)
before , Segment Closed v n
seg forall v a. Measured v a => a -> FingerTree v a -> FingerTree v a
<| FingerTree (SegMeasure v n) (Segment Closed v n)
after)
| n
pParam forall a. Eq a => a -> a -> Bool
== n
1 = (FingerTree (SegMeasure v n) (Segment Closed v n)
before forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> Segment Closed v n
seg , FingerTree (SegMeasure v n) (Segment Closed v n)
after)
| Bool
otherwise = (FingerTree (SegMeasure v n) (Segment Closed v n)
before forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> Segment Closed v n
segL, Segment Closed v n
segR forall v a. Measured v a => a -> FingerTree v a -> FingerTree v a
<| FingerTree (SegMeasure v n) (Segment Closed v n)
after)
rescale :: n -> n
rescale n
u | n
pSegs' forall a. Eq a => a -> a -> Bool
== n
uSegs = (n
uSegs forall a. Num a => a -> a -> a
+ n
uParam forall a. Fractional a => a -> a -> a
/ n
pParam' ) forall a. Fractional a => a -> a -> a
/ (n
pSegs' forall a. Num a => a -> a -> a
+ n
1)
| Bool
otherwise = n
u forall a. Num a => a -> a -> a
* n
tSegs forall a. Fractional a => a -> a -> a
/ (n
pSegs' forall a. Num a => a -> a -> a
+ n
1)
where
(n
pSegs', n
pParam') | n
pParam forall a. Eq a => a -> a -> Bool
== n
0 = (n
pSegsforall a. Num a => a -> a -> a
-n
1, n
1)
| Bool
otherwise = (n
pSegs , n
pParam)
(n
uSegs , n
uParam ) = n -> (n, n)
splitParam n
u
instance (Metric v, OrderedField n, Real n) => Sectionable (SegTree v n) where
splitAtParam :: SegTree v n -> N (SegTree v n) -> (SegTree v n, SegTree v n)
splitAtParam SegTree v n
tree N (SegTree v n)
p = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall (v :: * -> *) n.
(Metric v, OrderedField n, Real n) =>
SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
splitAtParam' SegTree v n
tree N (SegTree v n)
p
reverseDomain :: SegTree v n -> SegTree v n
reverseDomain (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) = forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree forall a b. (a -> b) -> a -> b
$ forall v a. Measured v a => FingerTree v a -> FingerTree v a
FT.reverse FingerTree (SegMeasure v n) (Segment Closed v n)
t'
where t' :: FingerTree (SegMeasure v n) (Segment Closed v n)
t' = forall v1 a1 v2 a2.
(Measured v1 a1, Measured v2 a2) =>
(a1 -> a2) -> FingerTree v1 a1 -> FingerTree v2 a2
FT.fmap' forall n (v :: * -> *).
(Num n, Additive v) =>
Segment Closed v n -> Segment Closed v n
reverseSegment FingerTree (SegMeasure v n) (Segment Closed v n)
t
section :: SegTree v n -> N (SegTree v n) -> N (SegTree v n) -> SegTree v n
section SegTree v n
x N (SegTree v n)
p1 N (SegTree v n)
p2 | N (SegTree v n)
p2 forall a. Eq a => a -> a -> Bool
== n
0 = forall p. Sectionable p => p -> p
reverseDomain forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
x N (SegTree v n)
p1
| N (SegTree v n)
p1 forall a. Ord a => a -> a -> Bool
<= N (SegTree v n)
p2 = let ((SegTree v n
a, SegTree v n
_), n -> n
rescale) = forall (v :: * -> *) n.
(Metric v, OrderedField n, Real n) =>
SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
splitAtParam' SegTree v n
x N (SegTree v n)
p2
in forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
a (n -> n
rescale N (SegTree v n)
p1)
| Bool
otherwise = forall p. Sectionable p => p -> p
reverseDomain forall a b. (a -> b) -> a -> b
$ forall p. Sectionable p => p -> N p -> N p -> p
section SegTree v n
x N (SegTree v n)
p2 N (SegTree v n)
p1
instance (Metric v, OrderedField n, Real n)
=> HasArcLength (SegTree v n) where
arcLengthBounded :: N (SegTree v n) -> SegTree v n -> Interval (N (SegTree v n))
arcLengthBounded N (SegTree v n)
eps SegTree v n
t
| forall a. Num a => Interval a -> a
I.width Interval n
i forall a. Ord a => a -> a -> Bool
<= N (SegTree v n)
eps = Interval n
i
| Bool
otherwise = n -> Interval n
fun (N (SegTree v n)
eps forall a. Fractional a => a -> a -> a
/ forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs SegTree v n
t)
where
i :: Interval n
i = forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure (forall a. a -> Interval a
I.singleton n
0)
forall n. ArcLength n -> Interval n
getArcLengthCached
SegTree v n
t
fun :: n -> Interval n
fun = forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure (forall a b. a -> b -> a
const Interval n
0)
forall n. ArcLength n -> n -> Interval n
getArcLengthFun
SegTree v n
t
arcLengthToParam :: N (SegTree v n)
-> SegTree v n -> N (SegTree v n) -> N (SegTree v n)
arcLengthToParam N (SegTree v n)
eps st :: SegTree v n
st@(SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) N (SegTree v n)
l
| N (SegTree v n)
l forall a. Ord a => a -> a -> Bool
< n
0 = case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree (SegMeasure v n) (Segment Closed v n)
t of
ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyL -> n
0
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (SegTree v n)
eps Segment Closed v n
seg N (SegTree v n)
l forall a. Fractional a => a -> a -> a
/ n
tSegs
| N (SegTree v n)
l forall a. Ord a => a -> a -> Bool
>= N (SegTree v n)
totalAL = case forall v a.
Measured v a =>
FingerTree v a -> ViewR (FingerTree v) a
FT.viewr FingerTree (SegMeasure v n) (Segment Closed v n)
t of
ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyR -> n
0
FingerTree (SegMeasure v n) (Segment Closed v n)
t' FT.:> Segment Closed v n
seg ->
let p :: N (Segment Closed v n)
p = forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam (N (SegTree v n)
epsforall a. Fractional a => a -> a -> a
/n
2) Segment Closed v n
seg
(N (SegTree v n)
l forall a. Num a => a -> a -> a
- forall p. HasArcLength p => N p -> p -> N p
arcLength (N (SegTree v n)
epsforall a. Fractional a => a -> a -> a
/n
2) (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t'))
in (N (Segment Closed v n)
p forall a. Num a => a -> a -> a
- n
1)forall a. Fractional a => a -> a -> a
/n
tSegs forall a. Num a => a -> a -> a
+ n
1
| Bool
otherwise = case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree (SegMeasure v n) (Segment Closed v n)
after of
ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyL -> n
0
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ ->
let p :: N (Segment Closed v n)
p = forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam (N (SegTree v n)
epsforall a. Fractional a => a -> a -> a
/n
2) Segment Closed v n
seg
(N (SegTree v n)
l forall a. Num a => a -> a -> a
- forall p. HasArcLength p => N p -> p -> N p
arcLength (N (SegTree v n)
epsforall a. Fractional a => a -> a -> a
/n
2) (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
before))
in (forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
before forall a. Num a => a -> a -> a
+ N (Segment Closed v n)
p) forall a. Fractional a => a -> a -> a
/ n
tSegs
where
totalAL :: N (SegTree v n)
totalAL = forall p. HasArcLength p => N p -> p -> N p
arcLength N (SegTree v n)
eps SegTree v n
st
tSegs :: n
tSegs = forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
t
before, after :: FingerTree (SegMeasure v n) (Segment Closed v n)
(FingerTree (SegMeasure v n) (Segment Closed v n)
before, FingerTree (SegMeasure v n) (Segment Closed v n)
after) =
forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((forall a. Ord a => a -> a -> Bool
>= N (SegTree v n)
l)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure
n
0
(forall a. Fractional a => Interval a -> a
I.midpoint forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. (Num n, Ord n) => n -> ArcLength n -> Interval n
getArcLengthBounded N (SegTree v n)
eps))
FingerTree (SegMeasure v n) (Segment Closed v n)
t
trailMeasure :: ( SegMeasure v n :>: m, FT.Measured (SegMeasure v n) t )
=> a -> (m -> a) -> t -> a
trailMeasure :: forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure a
d m -> a
f = forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
d m -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l a. (l :>: a) => l -> Maybe a
get forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v a. Measured v a => a -> v
FT.measure
numSegs :: (Num c, FT.Measured (SegMeasure v n) a)
=> a -> c
numSegs :: forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure Int
0 (forall a. Sum a -> a
getSum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Sum Int -> SegCount
SegCount)
offset :: ( OrderedField n, Metric v,
FT.Measured (SegMeasure v n) t
)
=> t -> v n
offset :: forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset = forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure forall (f :: * -> *) a. (Additive f, Num a) => f a
zero (forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset 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 (v :: * -> *) n.
Lens' (OffsetEnvelope v n) (TotalOffset v n)
oeOffset)
data Line
data Loop
data Trail' l v n where
Line :: SegTree v n -> Trail' Line v n
Loop :: SegTree v n -> Segment Open v n -> Trail' Loop v n
withTrail' :: (Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail' :: forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail' Trail' Line v n -> r
line Trail' Loop v n -> r
_ t :: Trail' l v n
t@(Line{}) = Trail' Line v n -> r
line Trail' l v n
t
withTrail' Trail' Line v n -> r
_ Trail' Loop v n -> r
loop t :: Trail' l v n
t@(Loop{}) = Trail' Loop v n -> r
loop Trail' l v n
t
deriving instance Eq (v n) => Eq (Trail' l v n)
deriving instance Ord (v n) => Ord (Trail' l v n)
instance Show (v n) => Show (Trail' l v n) where
showsPrec :: Int -> Trail' l v n -> ShowS
showsPrec Int
d (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft)) = Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"lineFromSegments " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => [a] -> ShowS
showList (forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
ft)
showsPrec Int
d (Loop (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft) Segment Open v n
o) = Bool -> ShowS -> ShowS
showParen (Int
d forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"loopFromSegments " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => [a] -> ShowS
showList (forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
ft) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
' ' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 Segment Open v n
o
type instance V (Trail' l v n) = v
type instance N (Trail' l v n) = n
type instance Codomain (Trail' l v n) = v
instance (OrderedField n, Metric v) => Semigroup (Trail' Line v n) where
(Line SegTree v n
t1) <> :: Trail' Line v n -> Trail' Line v n -> Trail' Line v n
<> (Line SegTree v n
t2) = forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (SegTree v n
t1 forall a. Monoid a => a -> a -> a
`mappend` SegTree v n
t2)
instance (Metric v, OrderedField n) => Monoid (Trail' Line v n) where
mempty :: Trail' Line v n
mempty = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
mappend :: Trail' Line v n -> Trail' Line v n -> Trail' Line v n
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance (Metric v, OrderedField n) => AsEmpty (Trail' Line v n) where
_Empty :: Prism' (Trail' Line v n) ()
_Empty = forall a. a -> (a -> Bool) -> Prism' a ()
nearly forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Bool
isLineEmpty
instance (HasLinearMap v, Metric v, OrderedField n)
=> Transformable (Trail' l v n) where
transform :: Transformation (V (Trail' l v n)) (N (Trail' l v n))
-> Trail' l v n -> Trail' l v n
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
tr (Line SegTree v n
t ) = forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
tr SegTree v n
t)
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
tr (Loop SegTree v n
t Segment Open v n
s) = forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
tr SegTree v n
t) (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
tr Segment Open v n
s)
instance (Metric v, OrderedField n) => Enveloped (Trail' l v n) where
getEnvelope :: Trail' l v n -> Envelope (V (Trail' l v n)) (N (Trail' l v n))
getEnvelope = forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail' Trail' Line v n -> Envelope v n
ftEnv (Trail' Line v n -> Envelope v n
ftEnv forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop)
where
ftEnv :: Trail' Line v n -> Envelope v n
ftEnv :: Trail' Line v n -> Envelope v n
ftEnv (Line SegTree v n
t) = forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure forall a. Monoid a => a
mempty (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall (v :: * -> *) n. Lens' (OffsetEnvelope v n) (Envelope v n)
oeEnvelope) SegTree v n
t
instance (HasLinearMap v, Metric v, OrderedField n)
=> Renderable (Trail' o v n) NullBackend where
render :: NullBackend
-> Trail' o v n
-> Render NullBackend (V (Trail' o v n)) (N (Trail' o v n))
render NullBackend
_ Trail' o v n
_ = forall a. Monoid a => a
mempty
instance (Metric v, OrderedField n, Real n)
=> Parametric (Trail' l v n) where
atParam :: Trail' l v n
-> N (Trail' l v n) -> Codomain (Trail' l v n) (N (Trail' l v n))
atParam Trail' l v n
t N (Trail' l v n)
p = forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail'
(\(Line SegTree v n
segT) -> SegTree v n
segT forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail' l v n)
p)
(\Trail' Loop v n
l -> forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` forall a. Real a => a -> a
mod1 N (Trail' l v n)
p)
Trail' l v n
t
instance (Parametric (GetSegment (Trail' c v n)), Additive v, Num n)
=> Parametric (Tangent (Trail' c v n)) where
Tangent Trail' c v n
tr atParam :: Tangent (Trail' c v n)
-> N (Tangent (Trail' c v n))
-> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
`atParam` N (Tangent (Trail' c v n))
p =
case forall t. t -> GetSegment t
GetSegment Trail' c v n
tr forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail' c v n))
p of
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
Nothing -> forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (v n
_, Segment Closed v n
seg, AnIso' n n
reparam)) -> forall t. t -> Tangent t
Tangent Segment Closed v n
seg forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` (N (Tangent (Trail' c v n))
p forall s a. s -> Getting a s a -> a
^. forall s t a b. AnIso s t a b -> Iso s t a b
cloneIso AnIso' n n
reparam)
instance ( Parametric (GetSegment (Trail' c v n))
, EndValues (GetSegment (Trail' c v n))
, Additive v
, Num n
)
=> EndValues (Tangent (Trail' c v n)) where
atStart :: Tangent (Trail' c v n)
-> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
atStart (Tangent Trail' c v n
tr) =
case forall p. EndValues p => p -> Codomain p (N p)
atStart (forall t. t -> GetSegment t
GetSegment Trail' c v n
tr) of
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
Nothing -> forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (v n
_, Segment Closed v n
seg, AnIso' n n
_)) -> forall p. EndValues p => p -> Codomain p (N p)
atStart (forall t. t -> Tangent t
Tangent Segment Closed v n
seg)
atEnd :: Tangent (Trail' c v n)
-> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
atEnd (Tangent Trail' c v n
tr) =
case forall p. EndValues p => p -> Codomain p (N p)
atEnd (forall t. t -> GetSegment t
GetSegment Trail' c v n
tr) of
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
Nothing -> forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (v n
_, Segment Closed v n
seg, AnIso' n n
_)) -> forall p. EndValues p => p -> Codomain p (N p)
atEnd (forall t. t -> Tangent t
Tangent Segment Closed v n
seg)
instance (Metric v , OrderedField n, Real n)
=> Parametric (Tangent (Trail v n)) where
Tangent Trail v n
tr atParam :: Tangent (Trail v n)
-> N (Tangent (Trail v n))
-> Codomain (Tangent (Trail v n)) (N (Tangent (Trail v n)))
`atParam` N (Tangent (Trail v n))
p
= forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
((forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail v n))
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent)
((forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail v n))
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent)
Trail v n
tr
instance (Metric v, OrderedField n, Real n)
=> EndValues (Tangent (Trail v n)) where
atStart :: Tangent (Trail v n)
-> Codomain (Tangent (Trail v n)) (N (Tangent (Trail v n)))
atStart (Tangent Trail v n
tr) = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall p. EndValues p => p -> Codomain p (N p)
atStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent) (forall p. EndValues p => p -> Codomain p (N p)
atStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent) Trail v n
tr
atEnd :: Tangent (Trail v n)
-> Codomain (Tangent (Trail v n)) (N (Tangent (Trail v n)))
atEnd (Tangent Trail v n
tr) = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall p. EndValues p => p -> Codomain p (N p)
atEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent) (forall p. EndValues p => p -> Codomain p (N p)
atEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> Tangent t
Tangent) Trail v n
tr
mod1 :: Real a => a -> a
mod1 :: forall a. Real a => a -> a
mod1 = (forall a. Real a => a -> a -> a
`mod'` a
1)
instance Num n => DomainBounds (Trail' l v n)
instance (Metric v, OrderedField n, Real n)
=> EndValues (Trail' l v n)
instance (Metric v, OrderedField n, Real n)
=> Sectionable (Trail' Line v n) where
splitAtParam :: Trail' Line v n
-> N (Trail' Line v n) -> (Trail' Line v n, Trail' Line v n)
splitAtParam (Line SegTree v n
t) N (Trail' Line v n)
p = (forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
t1, forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
t2)
where
(SegTree v n
t1, SegTree v n
t2) = forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
t N (Trail' Line v n)
p
section :: Trail' Line v n
-> N (Trail' Line v n) -> N (Trail' Line v n) -> Trail' Line v n
section (Line SegTree v n
t) N (Trail' Line v n)
p1 N (Trail' Line v n)
p2 = forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (forall p. Sectionable p => p -> N p -> N p -> p
section SegTree v n
t N (Trail' Line v n)
p1 N (Trail' Line v n)
p2)
reverseDomain :: Trail' Line v n -> Trail' Line v n
reverseDomain = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine
instance (Metric v, OrderedField n, Real n)
=> HasArcLength (Trail' l v n) where
arcLengthBounded :: N (Trail' l v n) -> Trail' l v n -> Interval (N (Trail' l v n))
arcLengthBounded N (Trail' l v n)
eps =
forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail'
(\(Line SegTree v n
t) -> forall p. HasArcLength p => N p -> p -> Interval (N p)
arcLengthBounded N (Trail' l v n)
eps SegTree v n
t)
(forall p. HasArcLength p => N p -> p -> Interval (N p)
arcLengthBounded N (Trail' l v n)
eps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop)
arcLengthToParam :: N (Trail' l v n)
-> Trail' l v n -> N (Trail' l v n) -> N (Trail' l v n)
arcLengthToParam N (Trail' l v n)
eps Trail' l v n
tr N (Trail' l v n)
l =
forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail'
(\(Line SegTree v n
t) -> forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail' l v n)
eps SegTree v n
t N (Trail' l v n)
l)
(\Trail' Loop v n
lp -> forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail' l v n)
eps (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
lp) N (Trail' l v n)
l)
Trail' l v n
tr
instance Rewrapped (Trail' Line v n) (Trail' Line v' n')
instance Wrapped (Trail' Line v n) where
type Unwrapped (Trail' Line v n) = SegTree v n
_Wrapped' :: Iso' (Trail' Line v n) (Unwrapped (Trail' Line v n))
_Wrapped' = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Line SegTree v n
x) -> SegTree v n
x) forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line
{-# INLINE _Wrapped' #-}
instance (Metric v, OrderedField n, Metric u, OrderedField n')
=> Cons (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') where
_Cons :: Prism
(Trail' Line v n)
(Trail' Line u n')
(Segment Closed v n, Trail' Line v n)
(Segment Closed u n', Trail' Line u n')
_Cons = forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
_Cons forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall a. a -> a
id forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped
{-# INLINE _Cons #-}
instance (Metric v, OrderedField n, Metric u, OrderedField n')
=> Snoc (Trail' Line v n) (Trail' Line u n') (Segment Closed v n) (Segment Closed u n') where
_Snoc :: Prism
(Trail' Line v n)
(Trail' Line u n')
(Trail' Line v n, Segment Closed v n)
(Trail' Line u n', Segment Closed u n')
_Snoc = forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a b. Snoc s t a b => Prism s t (s, a) (t, b)
_Snoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped forall a. a -> a
id
{-# INLINE _Snoc #-}
newtype GetSegment t = GetSegment t
newtype GetSegmentCodomain v n =
GetSegmentCodomain
(Maybe ( v n
, Segment Closed v n
, AnIso' n n
))
getSegment :: t -> GetSegment t
getSegment :: forall t. t -> GetSegment t
getSegment = forall t. t -> GetSegment t
GetSegment
type instance V (GetSegment t) = V t
type instance N (GetSegment t) = N t
type instance Codomain (GetSegment t) = GetSegmentCodomain (V t)
instance (Metric v, OrderedField n) => Parametric (GetSegment (Trail' Line v n)) where
atParam :: GetSegment (Trail' Line v n)
-> N (GetSegment (Trail' Line v n))
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
atParam (GetSegment (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft))) N (GetSegment (Trail' Line v n))
p
| N (GetSegment (Trail' Line v n))
p forall a. Ord a => a -> a -> Bool
<= n
0 = case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree (SegMeasure v n) (Segment Closed v n)
ft of
ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyL -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just (forall (f :: * -> *) a. (Additive f, Num a) => f a
zero, Segment Closed v n
seg, n -> Exchange n n n (Identity n) -> Exchange n n n (Identity n)
reparam n
0)
| N (GetSegment (Trail' Line v n))
p forall a. Ord a => a -> a -> Bool
>= n
1 = case forall v a.
Measured v a =>
FingerTree v a -> ViewR (FingerTree v) a
FT.viewr FingerTree (SegMeasure v n) (Segment Closed v n)
ft of
ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyR -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a. Maybe a
Nothing
FingerTree (SegMeasure v n) (Segment Closed v n)
ft' FT.:> Segment Closed v n
seg -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just (forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset FingerTree (SegMeasure v n) (Segment Closed v n)
ft', Segment Closed v n
seg, n -> Exchange n n n (Identity n) -> Exchange n n n (Identity n)
reparam (n
nforall a. Num a => a -> a -> a
-n
1))
| Bool
otherwise
= let (FingerTree (SegMeasure v n) (Segment Closed v n)
before, FingerTree (SegMeasure v n) (Segment Closed v n)
after) = forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((N (GetSegment (Trail' Line v n))
pforall a. Num a => a -> a -> a
*n
n forall a. Ord a => a -> a -> Bool
<) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs) FingerTree (SegMeasure v n) (Segment Closed v n)
ft
in case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree (SegMeasure v n) (Segment Closed v n)
after of
ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyL -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just (forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset FingerTree (SegMeasure v n) (Segment Closed v n)
before, Segment Closed v n
seg, n -> Exchange n n n (Identity n) -> Exchange n n n (Identity n)
reparam (forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
before))
where
n :: n
n = forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
ft
reparam :: n -> Exchange n n n (Identity n) -> Exchange n n n (Identity n)
reparam n
k = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (forall a. Num a => a -> a -> a
subtract n
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
*n
n))
((forall a. Fractional a => a -> a -> a
/n
n) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
+ n
k))
instance (Metric v, OrderedField n, Real n) => Parametric (GetSegment (Trail' Loop v n)) where
atParam :: GetSegment (Trail' Loop v n)
-> N (GetSegment (Trail' Loop v n))
-> Codomain
(GetSegment (Trail' Loop v n)) (N (GetSegment (Trail' Loop v n)))
atParam (GetSegment Trail' Loop v n
l) N (GetSegment (Trail' Loop v n))
p = forall p. Parametric p => p -> N p -> Codomain p (N p)
atParam (forall t. t -> GetSegment t
GetSegment (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l)) (forall a. Real a => a -> a
mod1 N (GetSegment (Trail' Loop v n))
p)
instance (Metric v, OrderedField n, Real n)
=> Parametric (GetSegment (Trail v n)) where
atParam :: GetSegment (Trail v n)
-> N (GetSegment (Trail v n))
-> Codomain (GetSegment (Trail v n)) (N (GetSegment (Trail v n)))
atParam (GetSegment Trail v n
t) N (GetSegment (Trail v n))
p
= forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
((forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (GetSegment (Trail v n))
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
((forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (GetSegment (Trail v n))
p) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
Trail v n
t
instance DomainBounds t => DomainBounds (GetSegment t) where
domainLower :: GetSegment t -> N (GetSegment t)
domainLower (GetSegment t
t) = forall p. DomainBounds p => p -> N p
domainLower t
t
domainUpper :: GetSegment t -> N (GetSegment t)
domainUpper (GetSegment t
t) = forall p. DomainBounds p => p -> N p
domainUpper t
t
instance (Metric v, OrderedField n)
=> EndValues (GetSegment (Trail' Line v n)) where
atStart :: GetSegment (Trail' Line v n)
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
atStart (GetSegment (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft)))
= case forall v a.
Measured v a =>
FingerTree v a -> ViewL (FingerTree v) a
FT.viewl FingerTree (SegMeasure v n) (Segment Closed v n)
ft of
ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyL -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ ->
let n :: n
n = forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
ft
in forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just (forall (f :: * -> *) a. (Additive f, Num a) => f a
zero, Segment Closed v n
seg, forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (forall a. Num a => a -> a -> a
*n
n) (forall a. Fractional a => a -> a -> a
/n
n))
atEnd :: GetSegment (Trail' Line v n)
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
atEnd (GetSegment (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft)))
= case forall v a.
Measured v a =>
FingerTree v a -> ViewR (FingerTree v) a
FT.viewr FingerTree (SegMeasure v n) (Segment Closed v n)
ft of
ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
EmptyR -> forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a. Maybe a
Nothing
FingerTree (SegMeasure v n) (Segment Closed v n)
ft' FT.:> Segment Closed v n
seg ->
let n :: n
n = forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs FingerTree (SegMeasure v n) (Segment Closed v n)
ft
in forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain forall a b. (a -> b) -> a -> b
$
forall a. a -> Maybe a
Just (forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset FingerTree (SegMeasure v n) (Segment Closed v n)
ft', Segment Closed v n
seg, forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (forall a. Num a => a -> a -> a
subtract (n
nforall a. Num a => a -> a -> a
-n
1) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
*n
n))
((forall a. Fractional a => a -> a -> a
/n
n) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
+ (n
nforall a. Num a => a -> a -> a
-n
1)))
)
instance (Metric v, OrderedField n, Real n)
=> EndValues (GetSegment (Trail' Loop v n)) where
atStart :: GetSegment (Trail' Loop v n)
-> Codomain
(GetSegment (Trail' Loop v n)) (N (GetSegment (Trail' Loop v n)))
atStart (GetSegment Trail' Loop v n
l) = forall p. EndValues p => p -> Codomain p (N p)
atStart (forall t. t -> GetSegment t
GetSegment (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l))
atEnd :: GetSegment (Trail' Loop v n)
-> Codomain
(GetSegment (Trail' Loop v n)) (N (GetSegment (Trail' Loop v n)))
atEnd (GetSegment Trail' Loop v n
l) = forall p. EndValues p => p -> Codomain p (N p)
atEnd (forall t. t -> GetSegment t
GetSegment (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l))
instance (Metric v, OrderedField n, Real n)
=> EndValues (GetSegment (Trail v n)) where
atStart :: GetSegment (Trail v n)
-> Codomain (GetSegment (Trail v n)) (N (GetSegment (Trail v n)))
atStart (GetSegment Trail v n
t)
= forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(forall p. EndValues p => p -> Codomain p (N p)
atStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
(forall p. EndValues p => p -> Codomain p (N p)
atStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
Trail v n
t
atEnd :: GetSegment (Trail v n)
-> Codomain (GetSegment (Trail v n)) (N (GetSegment (Trail v n)))
atEnd (GetSegment Trail v n
t)
= forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(forall p. EndValues p => p -> Codomain p (N p)
atEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
(forall p. EndValues p => p -> Codomain p (N p)
atEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. t -> GetSegment t
GetSegment)
Trail v n
t
data Trail v n where
Trail :: Trail' l v n -> Trail v n
deriving instance Show (v n) => Show (Trail v n)
instance Eq (v n) => Eq (Trail v n) where
Trail v n
t1 == :: Trail v n -> Trail v n -> Bool
== Trail v n
t2 =
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(\Trail' Line v n
ln1 -> forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (\Trail' Line v n
ln2 -> Trail' Line v n
ln1 forall a. Eq a => a -> a -> Bool
== Trail' Line v n
ln2) (forall a b. a -> b -> a
const Bool
False) Trail v n
t2)
(\Trail' Loop v n
lp1 -> forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall a b. a -> b -> a
const Bool
False) (\Trail' Loop v n
lp2 -> Trail' Loop v n
lp1 forall a. Eq a => a -> a -> Bool
== Trail' Loop v n
lp2) Trail v n
t2)
Trail v n
t1
instance Ord (v n) => Ord (Trail v n) where
compare :: Trail v n -> Trail v n -> Ordering
compare Trail v n
t1 Trail v n
t2 =
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(\Trail' Line v n
ln1 -> forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall a. Ord a => a -> a -> Ordering
compare Trail' Line v n
ln1) (forall a b. a -> b -> a
const Ordering
LT) Trail v n
t2)
(\Trail' Loop v n
lp1 -> forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall a b. a -> b -> a
const Ordering
GT) (forall a. Ord a => a -> a -> Ordering
compare Trail' Loop v n
lp1) Trail v n
t2)
Trail v n
t1
instance (OrderedField n, Metric v) => Semigroup (Trail v n) where
(Trail (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft))) <> :: Trail v n -> Trail v n -> Trail v n
<> Trail v n
t2 | forall v a. FingerTree v a -> Bool
FT.null FingerTree (SegMeasure v n) (Segment Closed v n)
ft = Trail v n
t2
Trail v n
t1 <> (Trail (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
ft))) | forall v a. FingerTree v a -> Bool
FT.null FingerTree (SegMeasure v n) (Segment Closed v n)
ft = Trail v n
t1
Trail v n
t1 <> Trail v n
t2 = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail v n
t1 forall a b. (a -> b) -> a -> b
$ \Trail' Line v n
l1 ->
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail v n
t2 forall a b. (a -> b) -> a -> b
$ \Trail' Line v n
l2 ->
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine (Trail' Line v n
l1 forall a. Semigroup a => a -> a -> a
<> Trail' Line v n
l2)
instance (Metric v, OrderedField n) => Monoid (Trail v n) where
mempty :: Trail v n
mempty = forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
mappend :: Trail v n -> Trail v n -> Trail v n
mappend = forall a. Semigroup a => a -> a -> a
(<>)
instance (Metric v, OrderedField n) => AsEmpty (Trail v n) where
_Empty :: Prism' (Trail v n) ()
_Empty = forall a. a -> (a -> Bool) -> Prism' a ()
nearly forall (v :: * -> *) n. (Metric v, OrderedField n) => Trail v n
emptyTrail forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Bool
isTrailEmpty
type instance V (Trail v n) = v
type instance N (Trail v n) = n
type instance Codomain (Trail v n) = v
instance (HasLinearMap v, Metric v, OrderedField n)
=> Transformable (Trail v n) where
transform :: Transformation (V (Trail v n)) (N (Trail v n))
-> Trail v n -> Trail v n
transform Transformation (V (Trail v n)) (N (Trail v n))
t = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail v n)) (N (Trail v n))
t) (forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail v n)) (N (Trail v n))
t)
instance (Metric v, OrderedField n) => Enveloped (Trail v n) where
getEnvelope :: Trail v n -> Envelope (V (Trail v n)) (N (Trail v n))
getEnvelope = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope
instance (Metric v, OrderedField n, Real n)
=> Parametric (Trail v n) where
atParam :: Trail v n -> N (Trail v n) -> Codomain (Trail v n) (N (Trail v n))
atParam Trail v n
t N (Trail v n)
p = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail v n)
p) (forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail v n)
p) Trail v n
t
instance Num n => DomainBounds (Trail v n)
instance (Metric v, OrderedField n, Real n) => EndValues (Trail v n)
instance (Metric v, OrderedField n, Real n) => Sectionable (Trail v n) where
splitAtParam :: Trail v n -> N (Trail v n) -> (Trail v n, Trail v n)
splitAtParam Trail v n
t N (Trail v n)
p = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine ((forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall p. Sectionable p => p -> N p -> (p, p)
`splitAtParam` N (Trail v n)
p)) Trail v n
t
section :: Trail v n -> N (Trail v n) -> N (Trail v n) -> Trail v n
section Trail v n
t N (Trail v n)
p1 N (Trail v n)
p2 = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine (forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Trail' Line v n
l -> forall p. Sectionable p => p -> N p -> N p -> p
section Trail' Line v n
l N (Trail v n)
p1 N (Trail v n)
p2)) Trail v n
t
reverseDomain :: Trail v n -> Trail v n
reverseDomain = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
reverseTrail
instance (Metric v, OrderedField n, Real n)
=> HasArcLength (Trail v n) where
arcLengthBounded :: N (Trail v n) -> Trail v n -> Interval (N (Trail v n))
arcLengthBounded = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall p. HasArcLength p => N p -> p -> Interval (N p)
arcLengthBounded
arcLengthToParam :: N (Trail v n) -> Trail v n -> N (Trail v n) -> N (Trail v n)
arcLengthToParam N (Trail v n)
eps Trail v n
tr N (Trail v n)
al = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine (\Trail' Line v n
ln -> forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail v n)
eps Trail' Line v n
ln N (Trail v n)
al) Trail v n
tr
_Line :: Prism' (Trail v n) (Trail' Line v n)
_Line :: forall (v :: * -> *) n. Prism' (Trail v n) (Trail' Line v n)
_Line = forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a c b. Prism (Either a c) (Either b c) a b
_Left
_Loop :: Prism' (Trail v n) (Trail' Loop v n)
_Loop :: forall (v :: * -> *) n. Prism' (Trail v n) (Trail' Loop v n)
_Loop = forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c a b. Prism (Either c a) (Either c b) a b
_Right
_LocLine :: Prism' (Located (Trail v n)) (Located (Trail' Line v n))
_LocLine :: forall (v :: * -> *) n.
Prism' (Located (Trail v n)) (Located (Trail' Line v n))
_LocLine = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail) forall a b. (a -> b) -> a -> b
$ forall a b. SameSpace a b => Lens (Located a) (Located b) a b
located (forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview forall (v :: * -> *) n. Prism' (Trail v n) (Trail' Line v n)
_Line)
_LocLoop :: Prism' (Located (Trail v n)) (Located (Trail' Loop v n))
_LocLoop :: forall (v :: * -> *) n.
Prism' (Located (Trail v n)) (Located (Trail' Loop v n))
_LocLoop = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail) forall a b. (a -> b) -> a -> b
$ forall a b. SameSpace a b => Lens (Located a) (Located b) a b
located (forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview forall (v :: * -> *) n. Prism' (Trail v n) (Trail' Loop v n)
_Loop)
instance Rewrapped (Trail v n) (Trail v' n')
instance Wrapped (Trail v n) where
type Unwrapped (Trail v n) = Either (Trail' Line v n) (Trail' Loop v n)
_Wrapped' :: Iso' (Trail v n) (Unwrapped (Trail v n))
_Wrapped' = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Trail v n -> Either (Trail' Line v n) (Trail' Loop v n)
getTrail (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail)
where
getTrail :: Trail v n -> Either (Trail' Line v n) (Trail' Loop v n)
getTrail :: Trail v n -> Either (Trail' Line v n) (Trail' Loop v n)
getTrail (Trail t :: Trail' l v n
t@(Line {})) = forall a b. a -> Either a b
Left Trail' l v n
t
getTrail (Trail t :: Trail' l v n
t@(Loop {})) = forall a b. b -> Either a b
Right Trail' l v n
t
withTrail :: (Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail :: forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail Trail' Line v n -> r
line Trail' Loop v n -> r
loop (Trail Trail' l v n
t) = forall (v :: * -> *) n r l.
(Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
withTrail' Trail' Line v n -> r
line Trail' Loop v n -> r
loop Trail' l v n
t
onTrail :: (Trail' Line v n -> Trail' l1 v n) -> (Trail' Loop v n -> Trail' l2 v n)
-> Trail v n -> Trail v n
onTrail :: forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail Trail' Line v n -> Trail' l1 v n
o Trail' Loop v n -> Trail' l2 v n
c = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' l1 v n
o) (forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' l2 v n
c)
withLine :: (Metric v, OrderedField n)
=> (Trail' Line v n -> r) -> Trail v n -> r
withLine :: forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail' Line v n -> r
f = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail Trail' Line v n -> r
f (Trail' Line v n -> r
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop)
onLine :: (Metric v, OrderedField n)
=> (Trail' Line v n -> Trail' Line v n) -> Trail v n -> Trail v n
onLine :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
(Trail' Line v n -> Trail' Line v n) -> Trail v n -> Trail v n
onLine Trail' Line v n -> Trail' Line v n
f = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail Trail' Line v n -> Trail' Line v n
f (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' Line v n
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop)
wrapTrail :: Trail' l v n -> Trail v n
wrapTrail :: forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail
wrapLine :: Trail' Line v n -> Trail v n
wrapLine :: forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail
wrapLoop :: Trail' Loop v n -> Trail v n
wrapLoop :: forall (v :: * -> *) n. Trail' Loop v n -> Trail v n
wrapLoop = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail
emptyLine :: (Metric v, OrderedField n) => Trail' Line v n
emptyLine :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine = forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line forall a. Monoid a => a
mempty
emptyTrail :: (Metric v, OrderedField n) => Trail v n
emptyTrail :: forall (v :: * -> *) n. (Metric v, OrderedField n) => Trail v n
emptyTrail = forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
lineFromSegments :: (Metric v, OrderedField n)
=> [Segment Closed v n] -> Trail' Line v n
lineFromSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments = forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v a. Measured v a => [a] -> FingerTree v a
FT.fromList
loopFromSegments :: (Metric v, OrderedField n)
=> [Segment Closed v n] -> Segment Open v n -> Trail' Loop v n
loopFromSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Segment Open v n -> Trail' Loop v n
loopFromSegments [Segment Closed v n]
segs = forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (forall v a. Measured v a => [a] -> FingerTree v a
FT.fromList [Segment Closed v n]
segs))
trailFromSegments :: (Metric v, OrderedField n)
=> [Segment Closed v n] -> Trail v n
trailFromSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments
lineFromOffsets :: (Metric v, OrderedField n) => [v n] -> Trail' Line v n
lineFromOffsets :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[v n] -> Trail' Line v n
lineFromOffsets = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. v n -> Segment Closed v n
straight
trailFromOffsets :: (Metric v, OrderedField n) => [v n] -> Trail v n
trailFromOffsets :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[v n] -> Trail v n
trailFromOffsets = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[v n] -> Trail' Line v n
lineFromOffsets
lineFromVertices :: (Metric v, OrderedField n)
=> [Point v n] -> Trail' Line v n
lineFromVertices :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Point v n] -> Trail' Line v n
lineFromVertices [] = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
lineFromVertices [Point v n
_] = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
lineFromVertices [Point v n]
ps = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. v n -> Segment Closed v n
straight forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
(.-.) (forall a. [a] -> [a]
tail [Point v n]
ps) [Point v n]
ps
trailFromVertices :: (Metric v, OrderedField n)
=> [Point v n] -> Trail v n
trailFromVertices :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Point v n] -> Trail v n
trailFromVertices = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Point v n] -> Trail' Line v n
lineFromVertices
glueLine :: (Metric v, OrderedField n) => Trail' Line v n -> Trail' Loop v n
glueLine :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) =
case forall v a.
Measured v a =>
FingerTree v a -> ViewR (FingerTree v) a
FT.viewr FingerTree (SegMeasure v n) (Segment Closed v n)
t of
ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
FT.EmptyR -> forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop forall a. Monoid a => a
mempty (forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
FingerTree (SegMeasure v n) (Segment Closed v n)
t' FT.:> Linear Offset Closed v n
_ -> forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t') (forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
FingerTree (SegMeasure v n) (Segment Closed v n)
t' FT.:> Cubic v n
c1 v n
c2 Offset Closed v n
_ -> forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t') (forall c (v :: * -> *) n.
v n -> v n -> Offset c v n -> Segment c v n
Cubic v n
c1 v n
c2 forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
glueTrail :: (Metric v, OrderedField n) => Trail v n -> Trail v n
glueTrail :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
glueTrail = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine forall a. a -> a
id
closeLine :: Trail' Line v n -> Trail' Loop v n
closeLine :: forall (v :: * -> *) n. Trail' Line v n -> Trail' Loop v n
closeLine (Line SegTree v n
t) = forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop SegTree v n
t (forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
closeTrail :: Trail v n -> Trail v n
closeTrail :: forall (v :: * -> *) n. Trail v n -> Trail v n
closeTrail = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail forall (v :: * -> *) n. Trail' Line v n -> Trail' Loop v n
closeLine forall a. a -> a
id
cutLoop :: forall v n. (Metric v, OrderedField n)
=> Trail' Loop v n -> Trail' Line v n
cutLoop :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop (Loop (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) Segment Open v n
c) =
case (forall v a. FingerTree v a -> Bool
FT.null FingerTree (SegMeasure v n) (Segment Closed v n)
t, Segment Open v n
c) of
(Bool
True, Linear Offset Open v n
OffsetOpen) -> forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
(Bool
_ , Linear Offset Open v n
OffsetOpen) -> forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n)
t forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear Offset Closed v n
off))
(Bool
_ , Cubic v n
c1 v n
c2 Offset Open v n
OffsetOpen) -> forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n)
t forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> forall c (v :: * -> *) n.
v n -> v n -> Offset c v n -> Segment c v n
Cubic v n
c1 v n
c2 Offset Closed v n
off))
where
offV :: v n
offV :: v n
offV = forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure forall (f :: * -> *) a. (Additive f, Num a) => f a
zero (forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset 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 (v :: * -> *) n.
Lens' (OffsetEnvelope v n) (TotalOffset v n)
oeOffset) forall a b. (a -> b) -> a -> b
$ FingerTree (SegMeasure v n) (Segment Closed v n)
t
off :: Offset Closed v n
off = forall (v :: * -> *) n. v n -> Offset Closed v n
OffsetClosed v n
offV
cutTrail :: (Metric v, OrderedField n)
=> Trail v n -> Trail v n
cutTrail :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
cutTrail = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail forall a. a -> a
id forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop
isLineEmpty :: (Metric v, OrderedField n) => Trail' Line v n -> Bool
isLineEmpty :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Bool
isLineEmpty (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) = forall v a. FingerTree v a -> Bool
FT.null FingerTree (SegMeasure v n) (Segment Closed v n)
t
isTrailEmpty :: (Metric v, OrderedField n) => Trail v n -> Bool
isTrailEmpty :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Bool
isTrailEmpty = 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 -> Bool
isLineEmpty (forall a b. a -> b -> a
const Bool
False)
isLine :: Trail v n -> Bool
isLine :: forall (v :: * -> *) n. Trail v n -> Bool
isLine = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. Trail v n -> Bool
isLoop
isLoop :: Trail v n -> Bool
isLoop :: forall (v :: * -> *) n. Trail v n -> Bool
isLoop = forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (forall a b. a -> b -> a
const Bool
False) (forall a b. a -> b -> a
const Bool
True)
lineSegments :: Trail' Line v n -> [Segment Closed v n]
lineSegments :: forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) = forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
t
onLineSegments
:: (Metric v, OrderedField n)
=> ([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line v n
onLineSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line v n
onLineSegments [Segment Closed v n] -> [Segment Closed v n]
f = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> [Segment Closed v n]
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments
loopSegments :: Trail' Loop v n -> ([Segment Closed v n], Segment Open v n)
loopSegments :: forall (v :: * -> *) n.
Trail' Loop v n -> ([Segment Closed v n], Segment Open v n)
loopSegments (Loop (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) Segment Open v n
c) = (forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
t, Segment Open v n
c)
trailSegments :: (Metric v, OrderedField n)
=> Trail v n -> [Segment Closed v n]
trailSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> [Segment Closed v n]
trailSegments = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments
trailOffsets :: (Metric v, OrderedField n) => Trail v n -> [v n]
trailOffsets :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> [v n]
trailOffsets = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine forall (v :: * -> *) n. Trail' Line v n -> [v n]
lineOffsets
trailOffset :: (Metric v, OrderedField n) => Trail v n -> v n
trailOffset :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> v n
trailOffset = forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> v n
lineOffset
lineOffsets :: Trail' Line v n -> [v n]
lineOffsets :: forall (v :: * -> *) n. Trail' Line v n -> [v n]
lineOffsets = forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments
loopOffsets :: (Metric v, OrderedField n) => Trail' Loop v n -> [v n]
loopOffsets :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> [v n]
loopOffsets = forall (v :: * -> *) n. Trail' Line v n -> [v n]
lineOffsets forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop
lineOffset :: (Metric v, OrderedField n) => Trail' Line v n -> v n
lineOffset :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> v n
lineOffset (Line SegTree v n
t) = forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure forall (f :: * -> *) a. (Additive f, Num a) => f a
zero (forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset 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 (v :: * -> *) n.
Lens' (OffsetEnvelope v n) (TotalOffset v n)
oeOffset) SegTree v n
t
trailPoints :: (Metric v, OrderedField n)
=> Located (Trail v n) -> [Point v n]
trailPoints :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailPoints (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))
= 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) =>
Located (Trail' Line v n) -> [Point v n]
linePoints forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
p)) (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> [Point v n]
loopPoints forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
p)) Trail v n
t
linePoints :: (Metric v, OrderedField n)
=> Located (Trail' Line v n) -> [Point v n]
linePoints :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> [Point v n]
linePoints (forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail' Line v n)) (N (Trail' Line v n))
p,Trail' Line v n
t))
= forall (v :: * -> *) n.
(Additive v, Num n) =>
Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point (V (Trail' Line v n)) (N (Trail' Line v n))
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments forall a b. (a -> b) -> a -> b
$ Trail' Line v n
t
loopPoints :: (Metric v, OrderedField n)
=> Located (Trail' Loop v n) -> [Point v n]
loopPoints :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> [Point v n]
loopPoints (forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p,Trail' Loop v n
t))
= forall (v :: * -> *) n.
(Additive v, Num n) =>
Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
Trail' Loop v n -> ([Segment Closed v n], Segment Open v n)
loopSegments forall a b. (a -> b) -> a -> b
$ Trail' Loop v n
t
segmentPoints :: (Additive v, Num n) => Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints :: forall (v :: * -> *) n.
(Additive v, Num n) =>
Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point v n
p = forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
(.+^) Point v n
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset
tolerance :: OrderedField a => a
tolerance :: forall a. OrderedField a => a
tolerance = a
10e-16
trailVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail v n) -> [Point v n]
trailVertices' :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail v n) -> [Point v n]
trailVertices' n
toler (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))
= 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) =>
n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' n
toler forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
p)) (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' n
toler forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
p)) Trail v n
t
trailVertices :: (Metric v, OrderedField n)
=> Located (Trail v n) -> [Point v n]
trailVertices :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailVertices = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail v n) -> [Point v n]
trailVertices' forall a. OrderedField a => a
tolerance
lineVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' n
toler (forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail' Line v n)) (N (Trail' Line v n))
p,Trail' Line v n
t))
= forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' n
toler Point (V (Trail' Line v n)) (N (Trail' Line v n))
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments forall a b. (a -> b) -> a -> b
$ Trail' Line v n
t
lineVertices :: (Metric v, OrderedField n)
=> Located (Trail' Line v n) -> [Point v n]
lineVertices :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> [Point v n]
lineVertices = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' forall a. OrderedField a => a
tolerance
loopVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' n
toler (forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p,Trail' Loop v n
t))
| forall (t :: * -> *) a. Foldable t => t a -> Int
length [Segment Closed v n]
segs forall a. Ord a => a -> a -> Bool
> Int
1 = if n
far forall a. Ord a => a -> a -> Bool
> n
toler then forall a. [a] -> [a]
init [Point v n]
ps else forall a. [a] -> [a]
init forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
drop Int
1 forall a b. (a -> b) -> a -> b
$ [Point v n]
ps
| Bool
otherwise = [Point v n]
ps
where
far :: n
far = forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance ((forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. EndValues (Tangent t) => t -> Vn t
tangentAtStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ [Segment Closed v n]
segs) forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^
(forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. EndValues (Tangent t) => t -> Vn t
tangentAtEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
last forall a b. (a -> b) -> a -> b
$ [Segment Closed v n]
segs))
segs :: [Segment Closed v n]
segs = forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop forall a b. (a -> b) -> a -> b
$ Trail' Loop v n
t
ps :: [Point v n]
ps = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' n
toler Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p [Segment Closed v n]
segs
loopVertices :: (Metric v, OrderedField n)
=> Located (Trail' Loop v n) -> [Point v n]
loopVertices :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> [Point v n]
loopVertices = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' forall a. OrderedField a => a
tolerance
segmentVertices' :: (Metric v, OrderedField n)
=> n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' n
toler Point v n
p [Segment Closed v n]
ts =
case [Point v n]
ps of
(Point v n
x:Point v n
_:[Point v n]
_) -> Point v n
x forall a. a -> [a] -> [a]
: forall a. [a] -> [Bool] -> [a]
select (forall a. Int -> [a] -> [a]
drop Int
1 [Point v n]
ps) [Bool]
ds forall a. [a] -> [a] -> [a]
++ [forall a. [a] -> a
last [Point v n]
ps]
[Point v n]
_ -> [Point v n]
ps
where
ds :: [Bool]
ds = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (v n, v n) -> (v n, v n) -> Bool
far [(v n, v n)]
tans (forall a. Int -> [a] -> [a]
drop Int
1 [(v n, v n)]
tans)
tans :: [(v n, v n)]
tans = [(forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. EndValues (Tangent t) => t -> Vn t
tangentAtStart forall a b. (a -> b) -> a -> b
$ Segment Closed v n
s
,forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. EndValues (Tangent t) => t -> Vn t
tangentAtEnd forall a b. (a -> b) -> a -> b
$ Segment Closed v n
s) | Segment Closed v n
s <- [Segment Closed v n]
ts]
ps :: [Point v n]
ps = forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
(.+^) Point v n
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset forall a b. (a -> b) -> a -> b
$ [Segment Closed v n]
ts
far :: (v n, v n) -> (v n, v n) -> Bool
far (v n, v n)
p2 (v n, v n)
q2 = forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance (forall a b. (a, b) -> b
snd (v n, v n)
p2 forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ forall a b. (a, b) -> a
fst (v n, v n)
q2) forall a. Ord a => a -> a -> Bool
> n
toler
select :: [a] -> [Bool] -> [a]
select :: forall a. [a] -> [Bool] -> [a]
select [a]
xs [Bool]
bs = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter forall a b. (a, b) -> b
snd (forall a b. [a] -> [b] -> [(a, b)]
zip [a]
xs [Bool]
bs)
fixTrail :: (Metric v, OrderedField n)
=> Located (Trail v n) -> [FixedSegment v n]
fixTrail :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [FixedSegment v n]
fixTrail Located (Trail v n)
t = forall a b. (a -> b) -> [a] -> [b]
map forall n (v :: * -> *).
(Num n, Additive v) =>
Located (Segment Closed v n) -> FixedSegment v n
mkFixedSeg (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments Located (Trail v n)
t)
unfixTrail
:: (Metric v, Ord n, Floating n)
=> [FixedSegment v n] -> Located (Trail v n)
unfixTrail :: forall (v :: * -> *) n.
(Metric v, Ord n, Floating n) =>
[FixedSegment v n] -> Located (Trail v n)
unfixTrail = 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}.
(Additive (V a), Num (N a)) =>
[Located a] -> Located [a]
takeLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall n (v :: * -> *).
(Num n, Additive v) =>
FixedSegment v n -> Located (Segment Closed v n)
fromFixedSeg
where
takeLoc :: [Located a] -> Located [a]
takeLoc [] = [] forall a. a -> Point (V a) (N a) -> Located a
`at` forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin
takeLoc xs :: [Located a]
xs@(Located a
x:[Located a]
_) = forall a b. (a -> b) -> [a] -> [b]
map forall a. Located a -> a
unLoc [Located a]
xs forall a. a -> Point (V a) (N a) -> Located a
`at` forall a. Located a -> Point (V a) (N a)
loc Located a
x
trailLocSegments :: (Metric v, OrderedField n)
=> Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments Located (Trail v n)
t = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. a -> Point (V a) (N a) -> Located a
at (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> [Segment Closed v n]
trailSegments (forall a. Located a -> a
unLoc Located (Trail v n)
t)) (forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailPoints Located (Trail v n)
t)
reverseTrail :: (Metric v, OrderedField n) => Trail v n -> Trail v n
reverseTrail :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
reverseTrail = forall (v :: * -> *) n l1 l2.
(Trail' Line v n -> Trail' l1 v n)
-> (Trail' Loop v n -> Trail' l2 v n) -> Trail v n -> Trail v n
onTrail forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Loop v n
reverseLoop
reverseLocTrail :: (Metric v, OrderedField n)
=> Located (Trail v n) -> Located (Trail v n)
reverseLocTrail :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Located (Trail v n)
reverseLocTrail (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)) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
reverseTrail Trail v n
t forall a. a -> Point (V a) (N a) -> Located a
`at` (Point (V (Trail v n)) (N (Trail v n))
p forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> v n
trailOffset Trail v n
t)
reverseLine :: (Metric v, OrderedField n)
=> Trail' Line v n -> Trail' Line v n
reverseLine :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line v n
onLineSegments (forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall n (v :: * -> *).
(Num n, Additive v) =>
Segment Closed v n -> Segment Closed v n
reverseSegment)
reverseLocLine :: (Metric v, OrderedField n)
=> Located (Trail' Line v n) -> Located (Trail' Line v n)
reverseLocLine :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> Located (Trail' Line v n)
reverseLocLine (forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail' Line v n)) (N (Trail' Line v n))
p,Trail' Line v n
l)) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine Trail' Line v n
l forall a. a -> Point (V a) (N a) -> Located a
`at` (Point (V (Trail' Line v n)) (N (Trail' Line v n))
p forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> v n
lineOffset Trail' Line v n
l)
reverseLoop :: (Metric v, OrderedField n)
=> Trail' Loop v n -> Trail' Loop v n
reverseLoop :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Loop v n
reverseLoop = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop
reverseLocLoop :: (Metric v, OrderedField n)
=> Located (Trail' Loop v n) -> Located (Trail' Loop v n)
reverseLocLoop :: forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> Located (Trail' Loop v n)
reverseLocLoop = forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Loop v n
reverseLoop
instance (Metric v, OrderedField n) => Reversing (Trail' l v n) where
reversing :: Trail' l v n -> Trail' l v n
reversing t :: Trail' l v n
t@(Line SegTree v n
_) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line v n
onLineSegments (forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall t. Reversing t => t -> t
reversing) Trail' l v n
t
reversing t :: Trail' l v n
t@(Loop SegTree v n
_ Segment Open v n
_) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Reversing t => t -> t
reversing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop forall a b. (a -> b) -> a -> b
$ Trail' l v n
t
instance (Metric v, OrderedField n) => Reversing (Trail v n) where
reversing :: Trail v n -> Trail v n
reversing (Trail Trail' l v n
t) = forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (forall t. Reversing t => t -> t
reversing Trail' l v n
t)
instance (Metric v, OrderedField n) => Reversing (Located (Trail' l v n)) where
reversing :: Located (Trail' l v n) -> Located (Trail' l v n)
reversing l :: Located (Trail' l v n)
l@(Loc Point (V (Trail' l v n)) (N (Trail' l v n))
_ Line {}) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> Located (Trail' Line v n)
reverseLocLine Located (Trail' l v n)
l
reversing l :: Located (Trail' l v n)
l@(Loc Point (V (Trail' l v n)) (N (Trail' l v n))
_ Loop {}) = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> Located (Trail' Loop v n)
reverseLocLoop Located (Trail' l v n)
l
instance (Metric v, OrderedField n) => Reversing (Located (Trail v n)) where
reversing :: Located (Trail v n) -> Located (Trail v n)
reversing = forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Located (Trail v n)
reverseLocTrail
instance (Serialize (v n), OrderedField n, Metric v) => Serialize (Trail v n) where
{-# INLINE get #-}
get :: Get (Trail v n)
get = do
Bool
isLine <- forall t. Serialize t => Get t
Serialize.get
case Bool
isLine of
Bool
True -> do
SegTree v n
segTree <- forall t. Serialize t => Get t
Serialize.get
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
segTree))
Bool
False -> do
SegTree v n
segTree <- forall t. Serialize t => Get t
Serialize.get
Segment Open v n
segment <- forall t. Serialize t => Get t
Serialize.get
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop SegTree v n
segTree Segment Open v n
segment))
{-# INLINE put #-}
put :: Putter (Trail v n)
put (Trail (Line SegTree v n
segTree)) = do
forall t. Serialize t => Putter t
Serialize.put Bool
True
forall t. Serialize t => Putter t
Serialize.put SegTree v n
segTree
put (Trail (Loop SegTree v n
segTree Segment Open v n
segment)) = do
forall t. Serialize t => Putter t
Serialize.put Bool
False
forall t. Serialize t => Putter t
Serialize.put SegTree v n
segTree
forall t. Serialize t => Putter t
Serialize.put Segment Open v n
segment
instance (OrderedField n, Metric v, Serialize (v n)) => Serialize (SegTree v n) where
{-# INLINE put #-}
put :: Putter (SegTree v n)
put (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
fingerTree) = forall t. Serialize t => Putter t
Serialize.put (forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
fingerTree)
{-# INLINE get #-}
get :: Get (SegTree v n)
get = do
[Segment Closed v n]
fingerTree <- forall t. Serialize t => Get t
Serialize.get
forall (m :: * -> *) a. Monad m => a -> m a
return (forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (forall v a. Measured v a => [a] -> FingerTree v a
FT.fromList [Segment Closed v n]
fingerTree))