{-# 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 = (a -> a) -> FingerTree m a -> FingerTree m a
forall v1 a1 v2 a2.
(Measured v1 a1, Measured v2 a2) =>
(a1 -> a2) -> FingerTree v1 a1 -> FingerTree v2 a2
FT.fmap' ((a -> a) -> FingerTree m a -> FingerTree m a)
-> (Transformation (V a) (N a) -> a -> a)
-> Transformation (V a) (N a)
-> FingerTree m a
-> FingerTree m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transformation (V a) (N a) -> a -> a
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 :: p (a, FingerTree m a) (f (b, FingerTree n b))
-> p (FingerTree m a) (f (FingerTree n b))
_Cons = ((b, FingerTree n b) -> FingerTree n b)
-> (FingerTree m a -> Either (FingerTree n b) (a, FingerTree m a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(a, FingerTree m a)
(b, FingerTree n b)
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism ((b -> FingerTree n b -> FingerTree n b)
-> (b, FingerTree n b) -> FingerTree n b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry b -> FingerTree n b -> FingerTree n b
forall v a. Measured v a => a -> FingerTree v a -> FingerTree v a
(FT.<|)) ((FingerTree m a -> Either (FingerTree n b) (a, FingerTree m a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(a, FingerTree m a)
(b, FingerTree n b))
-> (FingerTree m a -> Either (FingerTree n b) (a, FingerTree m a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(a, FingerTree m a)
(b, FingerTree n b)
forall a b. (a -> b) -> a -> b
$ \FingerTree m a
aas -> case FingerTree m a -> ViewL (FingerTree m) a
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 -> (a, FingerTree m a) -> Either (FingerTree n b) (a, FingerTree m a)
forall a b. b -> Either a b
Right (a
a, FingerTree m a
as)
ViewL (FingerTree m) a
EmptyL -> FingerTree n b -> Either (FingerTree n b) (a, FingerTree m a)
forall a b. a -> Either a b
Left FingerTree n b
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 :: p (FingerTree m a, a) (f (FingerTree n b, b))
-> p (FingerTree m a) (f (FingerTree n b))
_Snoc = ((FingerTree n b, b) -> FingerTree n b)
-> (FingerTree m a -> Either (FingerTree n b) (FingerTree m a, a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(FingerTree m a, a)
(FingerTree n b, b)
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism ((FingerTree n b -> b -> FingerTree n b)
-> (FingerTree n b, b) -> FingerTree n b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry FingerTree n b -> b -> FingerTree n b
forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
(FT.|>)) ((FingerTree m a -> Either (FingerTree n b) (FingerTree m a, a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(FingerTree m a, a)
(FingerTree n b, b))
-> (FingerTree m a -> Either (FingerTree n b) (FingerTree m a, a))
-> Prism
(FingerTree m a)
(FingerTree n b)
(FingerTree m a, a)
(FingerTree n b, b)
forall a b. (a -> b) -> a -> b
$ \FingerTree m a
aas -> case FingerTree m a -> ViewR (FingerTree m) a
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 -> (FingerTree m a, a) -> Either (FingerTree n b) (FingerTree m a, a)
forall a b. b -> Either a b
Right (FingerTree m a
as, a
a)
ViewR (FingerTree m) a
EmptyR -> FingerTree n b -> Either (FingerTree n b) (FingerTree m a, a)
forall a b. a -> Either a b
Left FingerTree n b
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
(SegTree v n -> SegTree v n -> Bool)
-> (SegTree v n -> SegTree v n -> Bool) -> Eq (SegTree v n)
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, Eq (SegTree v n)
Eq (SegTree v n)
-> (SegTree v n -> SegTree v n -> Ordering)
-> (SegTree v n -> SegTree v n -> Bool)
-> (SegTree v n -> SegTree v n -> Bool)
-> (SegTree v n -> SegTree v n -> Bool)
-> (SegTree v n -> SegTree v n -> Bool)
-> (SegTree v n -> SegTree v n -> SegTree v n)
-> (SegTree v n -> SegTree v n -> SegTree v n)
-> Ord (SegTree v n)
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
$cp1Ord :: forall (v :: * -> *) n. Ord (v n) => Eq (SegTree v n)
Ord, Int -> SegTree v n -> ShowS
[SegTree v n] -> ShowS
SegTree v n -> String
(Int -> SegTree v n -> ShowS)
-> (SegTree v n -> String)
-> ([SegTree v n] -> ShowS)
-> Show (SegTree v n)
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, Semigroup (SegTree v n)
SegTree v n
Semigroup (SegTree v n)
-> SegTree v n
-> (SegTree v n -> SegTree v n -> SegTree v n)
-> ([SegTree v n] -> SegTree v n)
-> Monoid (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
$cp1Monoid :: forall (v :: * -> *) n.
(Ord n, Floating n, Metric v) =>
Semigroup (SegTree v n)
Monoid, Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
(Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n)
-> Transformable (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' :: p (Unwrapped (SegTree v n)) (f (Unwrapped (SegTree v n)))
-> p (SegTree v n) (f (SegTree v n))
_Wrapped' = (SegTree v n -> FingerTree (SegMeasure v n) (Segment Closed v n))
-> (FingerTree (SegMeasure v n) (Segment Closed v n)
-> SegTree v n)
-> Iso
(SegTree v n)
(SegTree v n)
(FingerTree (SegMeasure v n) (Segment Closed v n))
(FingerTree (SegMeasure v n) (Segment Closed v n))
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) FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
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 :: p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (SegTree v n) (f (SegTree u n'))
_Cons = p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (SegTree v n) (f (SegTree u n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (SegTree v n) (f (SegTree u n')))
-> (p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n'))))
-> p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Segment Closed v n,
FingerTree (SegMeasure v n) (Segment Closed v n))
(f (Segment Closed u n',
FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
_Cons (p (Segment Closed v n,
FingerTree (SegMeasure v n) (Segment Closed v n))
(f (Segment Closed u n',
FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n'))))
-> (p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (Segment Closed v n,
FingerTree (SegMeasure v n) (Segment Closed v n))
(f (Segment Closed u n',
FingerTree (SegMeasure u n') (Segment Closed u n'))))
-> p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
-> AnIso
(FingerTree (SegMeasure v n) (Segment Closed v n))
(FingerTree (SegMeasure u n') (Segment Closed u n'))
(SegTree v n)
(SegTree u n')
-> Iso
(Segment Closed v n,
FingerTree (SegMeasure v n) (Segment Closed v n))
(Segment Closed u n',
FingerTree (SegMeasure u n') (Segment Closed u n'))
(Segment Closed v n, SegTree v n)
(Segment Closed u n', SegTree u n')
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
forall a. a -> a
id AnIso
(FingerTree (SegMeasure v n) (Segment Closed v n))
(FingerTree (SegMeasure u n') (Segment Closed u n'))
(SegTree v n)
(SegTree u n')
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 :: p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n'))
_Snoc = p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (SegTree v n) (f (SegTree u n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
-> p (SegTree v n) (f (SegTree u n')))
-> (p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n'))))
-> p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (FingerTree (SegMeasure v n) (Segment Closed v n),
Segment Closed v n)
(f (FingerTree (SegMeasure u n') (Segment Closed u n'),
Segment Closed u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
forall s t a b. Snoc s t a b => Prism s t (s, a) (t, b)
_Snoc (p (FingerTree (SegMeasure v n) (Segment Closed v n),
Segment Closed v n)
(f (FingerTree (SegMeasure u n') (Segment Closed u n'),
Segment Closed u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n'))))
-> (p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n),
Segment Closed v n)
(f (FingerTree (SegMeasure u n') (Segment Closed u n'),
Segment Closed u n')))
-> p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (FingerTree (SegMeasure v n) (Segment Closed v n))
(f (FingerTree (SegMeasure u n') (Segment Closed u n')))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
(FingerTree (SegMeasure v n) (Segment Closed v n))
(FingerTree (SegMeasure u n') (Segment Closed u n'))
(SegTree v n)
(SegTree u n')
-> AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
-> Iso
(FingerTree (SegMeasure v n) (Segment Closed v n),
Segment Closed v n)
(FingerTree (SegMeasure u n') (Segment Closed u n'),
Segment Closed u n')
(SegTree v n, Segment Closed v n)
(SegTree u n', Segment Closed u n')
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
(FingerTree (SegMeasure v n) (Segment Closed v n))
(FingerTree (SegMeasure u n') (Segment Closed u n'))
(SegTree v n)
(SegTree u n')
forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
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 = SegTree v n -> v n
forall n (v :: * -> *) t.
(OrderedField n, Metric v, Measured (SegMeasure v n) t) =>
t -> v n
offset (SegTree v n -> v n)
-> ((SegTree v n, SegTree v n) -> SegTree v n)
-> (SegTree v n, SegTree v n)
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SegTree v n, SegTree v n) -> SegTree v n
forall a b. (a, b) -> a
fst ((SegTree v n, SegTree v n) -> v n)
-> (SegTree v n, SegTree v n) -> v n
forall a b. (a -> b) -> a -> b
$ SegTree v n -> N (SegTree v n) -> (SegTree v n, SegTree v n)
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' :: 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 n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
0 = ((SegTree v n
forall a. Monoid a => a
mempty , SegTree v n
forall a. Monoid a => a
mempty ), n -> n
forall a. a -> a
id)
| Bool
otherwise = ((FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
treeL, FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
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 = FingerTree (SegMeasure v n) (Segment Closed v 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)
t
splitParam :: n -> (n, n)
splitParam n
q | n
q n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
0 = (n
0 , n
q n -> n -> n
forall a. Num a => a -> a -> a
* n
tSegs)
| n
q n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
1 = (n
tSegs n -> n -> n
forall a. Num a => a -> a -> a
- n
1, n
1 n -> n -> n
forall a. Num a => a -> a -> a
+ (n
q n -> n -> n
forall a. Num a => a -> a -> a
- n
1) n -> n -> n
forall a. Num a => a -> a -> a
* n
tSegs)
| Bool
otherwise = n -> (n, n)
forall b. Real b => b -> (b, b)
propFrac (n -> (n, n)) -> n -> (n, n)
forall a b. (a -> b) -> a -> b
$ n
q n -> n -> n
forall a. Num a => a -> a -> a
* n
tSegs
where propFrac :: b -> (b, b)
propFrac b
x = let m :: b
m = b -> b
forall a. Real a => a -> a
mod1 b
x in (b
x b -> b -> b
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, FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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) = (SegMeasure v n -> Bool)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> (FingerTree (SegMeasure v n) (Segment Closed v n),
FingerTree (SegMeasure v n) (Segment Closed v n))
forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((n
pSegs n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<) (n -> Bool) -> (SegMeasure v n -> n) -> SegMeasure v n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SegMeasure v 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)
t
(Segment Closed v n
segL, Segment Closed v n
segR) = Segment Closed v n
seg Segment Closed v n
-> N (Segment Closed v n)
-> (Segment Closed v n, Segment Closed v n)
forall p. Sectionable p => p -> N p -> (p, p)
`splitAtParam` n
N (Segment Closed v n)
pParam
(FingerTree (SegMeasure v n) (Segment Closed v n)
treeL, FingerTree (SegMeasure v n) (Segment Closed v n)
treeR) | n
pParam n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
0 = (FingerTree (SegMeasure v n) (Segment Closed v n)
before , Segment Closed v n
seg Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v a. Measured v a => a -> FingerTree v a -> FingerTree v a
<| FingerTree (SegMeasure v n) (Segment Closed v n)
after)
| n
pParam n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
1 = (FingerTree (SegMeasure v n) (Segment Closed v n)
before FingerTree (SegMeasure v n) (Segment Closed v n)
-> Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
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 FingerTree (SegMeasure v n) (Segment Closed v n)
-> Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> Segment Closed v n
segL, Segment Closed v n
segR Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
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' n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
uSegs = (n
uSegs n -> n -> n
forall a. Num a => a -> a -> a
+ n
uParam n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
pParam' ) n -> n -> n
forall a. Fractional a => a -> a -> a
/ (n
pSegs' n -> n -> n
forall a. Num a => a -> a -> a
+ n
1)
| Bool
otherwise = n
u n -> n -> n
forall a. Num a => a -> a -> a
* n
tSegs n -> n -> n
forall a. Fractional a => a -> a -> a
/ (n
pSegs' n -> n -> n
forall a. Num a => a -> a -> a
+ n
1)
where
(n
pSegs', n
pParam') | n
pParam n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
0 = (n
pSegsn -> n -> n
forall 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 = ((SegTree v n, SegTree v n), n -> n) -> (SegTree v n, SegTree v n)
forall a b. (a, b) -> a
fst (((SegTree v n, SegTree v n), n -> n)
-> (SegTree v n, SegTree v n))
-> ((SegTree v n, SegTree v n), n -> n)
-> (SegTree v n, SegTree v n)
forall a b. (a -> b) -> a -> b
$ SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
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
N (SegTree v n)
p
reverseDomain :: SegTree v n -> SegTree v n
reverseDomain (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t) = FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall a b. (a -> b) -> a -> b
$ FingerTree (SegMeasure v n) (Segment Closed v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
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' = (Segment Closed v n -> Segment Closed v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v1 a1 v2 a2.
(Measured v1 a1, Measured v2 a2) =>
(a1 -> a2) -> FingerTree v1 a1 -> FingerTree v2 a2
FT.fmap' Segment Closed v n -> Segment Closed v n
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
N (SegTree v n)
p2 n -> n -> Bool
forall a. Eq a => a -> a -> Bool
== n
0 = SegTree v n -> SegTree v n
forall p. Sectionable p => p -> p
reverseDomain (SegTree v n -> SegTree v n)
-> ((SegTree v n, SegTree v n) -> SegTree v n)
-> (SegTree v n, SegTree v n)
-> SegTree v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SegTree v n, SegTree v n) -> SegTree v n
forall a b. (a, b) -> a
fst ((SegTree v n, SegTree v n) -> SegTree v n)
-> (SegTree v n, SegTree v n) -> SegTree v n
forall a b. (a -> b) -> a -> b
$ SegTree v n -> N (SegTree v n) -> (SegTree v n, SegTree v n)
forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
x N (SegTree v n)
p1
| n
N (SegTree v n)
p1 n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
N (SegTree v n)
p2 = let ((SegTree v n
a, SegTree v n
_), n -> n
rescale) = SegTree v n -> n -> ((SegTree v n, SegTree v n), n -> n)
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
N (SegTree v n)
p2
in (SegTree v n, SegTree v n) -> SegTree v n
forall a b. (a, b) -> b
snd ((SegTree v n, SegTree v n) -> SegTree v n)
-> (SegTree v n, SegTree v n) -> SegTree v n
forall a b. (a -> b) -> a -> b
$ SegTree v n -> N (SegTree v n) -> (SegTree v n, SegTree v n)
forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
a (n -> n
rescale n
N (SegTree v n)
p1)
| Bool
otherwise = SegTree v n -> SegTree v n
forall p. Sectionable p => p -> p
reverseDomain (SegTree v n -> SegTree v n) -> SegTree v n -> SegTree v n
forall a b. (a -> b) -> a -> b
$ SegTree v n -> N (SegTree v n) -> N (SegTree v n) -> SegTree v n
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
| Interval n -> n
forall a. Num a => Interval a -> a
I.width Interval n
i n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
N (SegTree v n)
eps = Interval n
Interval (N (SegTree v n))
i
| Bool
otherwise = n -> Interval n
fun (n
N (SegTree v n)
eps n -> n -> n
forall a. Fractional a => a -> a -> a
/ SegTree v n -> n
forall c (v :: * -> *) n a.
(Num c, Measured (SegMeasure v n) a) =>
a -> c
numSegs SegTree v n
t)
where
i :: Interval n
i = Interval n
-> (ArcLength n -> Interval n) -> SegTree v n -> Interval n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure (n -> Interval n
forall a. a -> Interval a
I.singleton n
0)
ArcLength n -> Interval n
forall n. ArcLength n -> Interval n
getArcLengthCached
SegTree v n
t
fun :: n -> Interval n
fun = (n -> Interval n)
-> (ArcLength n -> n -> Interval n)
-> SegTree v n
-> n
-> Interval n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure (Interval n -> n -> Interval n
forall a b. a -> b -> a
const Interval n
0)
ArcLength n -> n -> Interval n
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
N (SegTree v n)
l n -> n -> Bool
forall a. Ord a => a -> a -> Bool
< n
0 = case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 (SegTree v n)
0
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> N (Segment Closed v n)
-> Segment Closed v n
-> N (Segment Closed v n)
-> N (Segment Closed v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Segment Closed v n)
N (SegTree v n)
eps Segment Closed v n
seg N (Segment Closed v n)
N (SegTree v n)
l n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
tSegs
| n
N (SegTree v n)
l n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
N (SegTree v n)
totalAL = case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 (SegTree v 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 = N (Segment Closed v n)
-> Segment Closed v n
-> N (Segment Closed v n)
-> N (Segment Closed v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam (n
N (SegTree v n)
epsn -> n -> n
forall a. Fractional a => a -> a -> a
/n
2) Segment Closed v n
seg
(n
N (SegTree v n)
l n -> n -> n
forall a. Num a => a -> a -> a
- N (SegTree v n) -> SegTree v n -> N (SegTree v n)
forall p. HasArcLength p => N p -> p -> N p
arcLength (n
N (SegTree v n)
epsn -> n -> n
forall a. Fractional a => a -> a -> a
/n
2) (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
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
N (Segment Closed v n)
p n -> n -> n
forall a. Num a => a -> a -> a
- n
1)n -> n -> n
forall a. Fractional a => a -> a -> a
/n
tSegs n -> n -> n
forall a. Num a => a -> a -> a
+ n
1
| Bool
otherwise = case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 (SegTree v n)
0
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ ->
let p :: N (Segment Closed v n)
p = N (Segment Closed v n)
-> Segment Closed v n
-> N (Segment Closed v n)
-> N (Segment Closed v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam (n
N (SegTree v n)
epsn -> n -> n
forall a. Fractional a => a -> a -> a
/n
2) Segment Closed v n
seg
(n
N (SegTree v n)
l n -> n -> n
forall a. Num a => a -> a -> a
- N (SegTree v n) -> SegTree v n -> N (SegTree v n)
forall p. HasArcLength p => N p -> p -> N p
arcLength (n
N (SegTree v n)
epsn -> n -> n
forall a. Fractional a => a -> a -> a
/n
2) (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
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 (FingerTree (SegMeasure v n) (Segment Closed v 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)
before n -> n -> n
forall a. Num a => a -> a -> a
+ n
N (Segment Closed v n)
p) n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
tSegs
where
totalAL :: N (SegTree v n)
totalAL = N (SegTree v n) -> SegTree v n -> N (SegTree v n)
forall p. HasArcLength p => N p -> p -> N p
arcLength N (SegTree v n)
eps SegTree v n
st
tSegs :: n
tSegs = FingerTree (SegMeasure v n) (Segment Closed v 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)
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) =
(SegMeasure v n -> Bool)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> (FingerTree (SegMeasure v n) (Segment Closed v n),
FingerTree (SegMeasure v n) (Segment Closed v n))
forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
N (SegTree v n)
l)
(n -> Bool) -> (SegMeasure v n -> n) -> SegMeasure v n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. n -> (ArcLength n -> n) -> SegMeasure v n -> n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure
n
0
(Interval n -> n
forall a. Fractional a => Interval a -> a
I.midpoint (Interval n -> n)
-> (ArcLength n -> Interval n) -> ArcLength n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. n -> ArcLength n -> Interval n
forall n. (Num n, Ord n) => n -> ArcLength n -> Interval n
getArcLengthBounded n
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 :: a -> (m -> a) -> t -> a
trailMeasure a
d m -> a
f = a -> (m -> a) -> Maybe m -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
d m -> a
f (Maybe m -> a) -> (t -> Maybe m) -> t -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SegMeasure v n -> Maybe m
forall l a. (l :>: a) => l -> Maybe a
get (SegMeasure v n -> Maybe m)
-> (t -> SegMeasure v n) -> t -> Maybe m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> SegMeasure v n
forall v a. Measured v a => a -> v
FT.measure
numSegs :: (Num c, FT.Measured (SegMeasure v n) a)
=> a -> c
numSegs :: a -> c
numSegs = Int -> c
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> c) -> (a -> Int) -> a -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (SegCount -> Int) -> a -> Int
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure Int
0 (Sum Int -> Int
forall a. Sum a -> a
getSum (Sum Int -> Int) -> (SegCount -> Sum Int) -> SegCount -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Unwrapped SegCount -> SegCount) -> SegCount -> Unwrapped SegCount
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Sum Int -> SegCount
Unwrapped SegCount -> SegCount
SegCount)
offset :: ( OrderedField n, Metric v,
FT.Measured (SegMeasure v n) t
)
=> t -> v n
offset :: t -> v n
offset = v n -> (OffsetEnvelope v n -> v n) -> t -> v n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero ((Unwrapped (TotalOffset v n) -> TotalOffset v n)
-> TotalOffset v n -> Unwrapped (TotalOffset v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (TotalOffset v n) -> TotalOffset v n
forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset (TotalOffset v n -> v n)
-> (OffsetEnvelope v n -> TotalOffset v n)
-> OffsetEnvelope v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
-> OffsetEnvelope v n -> TotalOffset v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
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' :: (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
Trail' Line 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
Trail' Loop 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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"lineFromSegments " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> ShowS
forall a. Show a => [a] -> ShowS
showList (FingerTree (SegMeasure v n) (Segment Closed v n)
-> [Segment Closed v n]
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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"loopFromSegments " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> ShowS
forall a. Show a => [a] -> ShowS
showList (FingerTree (SegMeasure v n) (Segment Closed v n)
-> [Segment Closed v n]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList FingerTree (SegMeasure v n) (Segment Closed v n)
ft) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Segment Open v n -> ShowS
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) = SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (SegTree v n
t1 SegTree v n -> SegTree v n -> SegTree v n
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 = Trail' Line v n
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 = Trail' Line v n -> Trail' Line v n -> Trail' Line v n
forall a. Semigroup a => a -> a -> a
(<>)
instance (Metric v, OrderedField n) => AsEmpty (Trail' Line v n) where
_Empty :: p () (f ()) -> p (Trail' Line v n) (f (Trail' Line v n))
_Empty = Trail' Line v n
-> (Trail' Line v n -> Bool) -> Prism' (Trail' Line v n) ()
forall a. a -> (a -> Bool) -> Prism' a ()
nearly Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine Trail' Line v n -> Bool
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 ) = SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
Transformation (V (SegTree v n)) (N (SegTree 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) = SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (Transformation (V (SegTree v n)) (N (SegTree v n))
-> SegTree v n -> SegTree v n
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail' l v n)) (N (Trail' l v n))
Transformation (V (SegTree v n)) (N (SegTree v n))
tr SegTree v n
t) (Transformation (V (Segment Open v n)) (N (Segment Open v n))
-> Segment Open v n -> Segment Open v n
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Segment Open v n)) (N (Segment Open v n))
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 = (Trail' Line v n -> Envelope v n)
-> (Trail' Loop v n -> Envelope v n)
-> Trail' l v n
-> Envelope v n
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 (Trail' Line v n -> Envelope v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Envelope v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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) = Envelope v n
-> (OffsetEnvelope v n -> Envelope v n)
-> SegTree v n
-> Envelope v n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure Envelope v n
forall a. Monoid a => a
mempty (Getting (Envelope v n) (OffsetEnvelope v n) (Envelope v n)
-> OffsetEnvelope v n -> Envelope v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Envelope v n) (OffsetEnvelope v n) (Envelope v n)
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
_ = Render NullBackend (V (Trail' o v n)) (N (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 = (Trail' Line v n -> v n)
-> (Trail' Loop v n -> v n) -> Trail' l v n -> v n
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 SegTree v n
-> N (SegTree v n) -> Codomain (SegTree v n) (N (SegTree v n))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail' l v n)
N (SegTree v n)
p)
(\Trail' Loop v n
l -> Trail' Loop v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l Trail' Line v n
-> N (Trail' Line v n)
-> Codomain (Trail' Line v n) (N (Trail' Line v n))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` n -> n
forall a. Real a => a -> a
mod1 n
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 Trail' c v n -> GetSegment (Trail' c v n)
forall t. t -> GetSegment t
GetSegment Trail' c v n
tr GetSegment (Trail' c v n)
-> N (GetSegment (Trail' c v n))
-> Codomain
(GetSegment (Trail' c v n)) (N (GetSegment (Trail' c v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail' c v n))
N (GetSegment (Trail' c v n))
p of
GetSegmentCodomain Nothing -> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (_, seg, reparam)) -> Segment Closed v n -> Tangent (Segment Closed v n)
forall t. t -> Tangent t
Tangent Segment Closed v n
seg Tangent (Segment Closed v n)
-> N (Tangent (Segment Closed v n))
-> Codomain
(Tangent (Segment Closed v n)) (N (Tangent (Segment Closed v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` (n
N (Tangent (Trail' c v n))
p n -> Getting n n n -> n
forall s a. s -> Getting a s a -> a
^. AnIso n n n n -> Iso n n n n
forall s t a b. AnIso s t a b -> Iso s t a b
cloneIso AnIso n n 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 GetSegment (Trail' c v n)
-> Codomain
(GetSegment (Trail' c v n)) (N (GetSegment (Trail' c v n)))
forall p. EndValues p => p -> Codomain p (N p)
atStart (Trail' c v n -> GetSegment (Trail' c v n)
forall t. t -> GetSegment t
GetSegment Trail' c v n
tr) of
GetSegmentCodomain Nothing -> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (_, seg, _)) -> Tangent (Segment Closed v n)
-> Codomain
(Tangent (Segment Closed v n)) (N (Tangent (Segment Closed v n)))
forall p. EndValues p => p -> Codomain p (N p)
atStart (Segment Closed v n -> Tangent (Segment Closed v n)
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 GetSegment (Trail' c v n)
-> Codomain
(GetSegment (Trail' c v n)) (N (GetSegment (Trail' c v n)))
forall p. EndValues p => p -> Codomain p (N p)
atEnd (Trail' c v n -> GetSegment (Trail' c v n)
forall t. t -> GetSegment t
GetSegment Trail' c v n
tr) of
GetSegmentCodomain Nothing -> Codomain (Tangent (Trail' c v n)) (N (Tangent (Trail' c v n)))
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero
GetSegmentCodomain (Just (_, seg, _)) -> Tangent (Segment Closed v n)
-> Codomain
(Tangent (Segment Closed v n)) (N (Tangent (Segment Closed v n)))
forall p. EndValues p => p -> Codomain p (N p)
atEnd (Segment Closed v n -> Tangent (Segment Closed v n)
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
= (Trail' Line v n -> v n)
-> (Trail' Loop v n -> v n) -> Trail v n -> v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
((Tangent (Trail' Line v n)
-> N (Tangent (Trail' Line v n))
-> Codomain
(Tangent (Trail' Line v n)) (N (Tangent (Trail' Line v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail v n))
N (Tangent (Trail' Line v n))
p) (Tangent (Trail' Line v n) -> v n)
-> (Trail' Line v n -> Tangent (Trail' Line v n))
-> Trail' Line v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Tangent (Trail' Line v n)
forall t. t -> Tangent t
Tangent)
((Tangent (Trail' Loop v n)
-> N (Tangent (Trail' Loop v n))
-> Codomain
(Tangent (Trail' Loop v n)) (N (Tangent (Trail' Loop v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Tangent (Trail v n))
N (Tangent (Trail' Loop v n))
p) (Tangent (Trail' Loop v n) -> v n)
-> (Trail' Loop v n -> Tangent (Trail' Loop v n))
-> Trail' Loop v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Tangent (Trail' Loop v n)
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) = (Trail' Line v n -> v n)
-> (Trail' Loop v n -> v n) -> Trail v n -> v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Tangent (Trail' Line v n) -> v n
forall p. EndValues p => p -> Codomain p (N p)
atStart (Tangent (Trail' Line v n) -> v n)
-> (Trail' Line v n -> Tangent (Trail' Line v n))
-> Trail' Line v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Tangent (Trail' Line v n)
forall t. t -> Tangent t
Tangent) (Tangent (Trail' Loop v n) -> v n
forall p. EndValues p => p -> Codomain p (N p)
atStart (Tangent (Trail' Loop v n) -> v n)
-> (Trail' Loop v n -> Tangent (Trail' Loop v n))
-> Trail' Loop v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Tangent (Trail' Loop v n)
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) = (Trail' Line v n -> v n)
-> (Trail' Loop v n -> v n) -> Trail v n -> v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Tangent (Trail' Line v n) -> v n
forall p. EndValues p => p -> Codomain p (N p)
atEnd (Tangent (Trail' Line v n) -> v n)
-> (Trail' Line v n -> Tangent (Trail' Line v n))
-> Trail' Line v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Tangent (Trail' Line v n)
forall t. t -> Tangent t
Tangent) (Tangent (Trail' Loop v n) -> v n
forall p. EndValues p => p -> Codomain p (N p)
atEnd (Tangent (Trail' Loop v n) -> v n)
-> (Trail' Loop v n -> Tangent (Trail' Loop v n))
-> Trail' Loop v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Tangent (Trail' Loop v n)
forall t. t -> Tangent t
Tangent) Trail v n
tr
mod1 :: Real a => a -> a
mod1 :: a -> a
mod1 = (a -> a -> a
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 = (SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
t1, SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
t2)
where
(SegTree v n
t1, SegTree v n
t2) = SegTree v n -> N (SegTree v n) -> (SegTree v n, SegTree v n)
forall p. Sectionable p => p -> N p -> (p, p)
splitAtParam SegTree v n
t N (Trail' Line v n)
N (SegTree 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 = SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (SegTree v n -> N (SegTree v n) -> N (SegTree v n) -> SegTree v n
forall p. Sectionable p => p -> N p -> N p -> p
section SegTree v n
t N (Trail' Line v n)
N (SegTree v n)
p1 N (Trail' Line v n)
N (SegTree v n)
p2)
reverseDomain :: Trail' Line v n -> Trail' Line v n
reverseDomain = Trail' Line v n -> Trail' Line v n
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 =
(Trail' Line v n -> Interval n)
-> (Trail' Loop v n -> Interval n) -> Trail' l v n -> Interval n
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) -> N (SegTree v n) -> SegTree v n -> Interval (N (SegTree v n))
forall p. HasArcLength p => N p -> p -> Interval (N p)
arcLengthBounded N (Trail' l v n)
N (SegTree v n)
eps SegTree v n
t)
(N (Trail' Line v n)
-> Trail' Line v n -> Interval (N (Trail' Line v n))
forall p. HasArcLength p => N p -> p -> Interval (N p)
arcLengthBounded N (Trail' l v n)
N (Trail' Line v n)
eps (Trail' Line v n -> Interval n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Interval n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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 =
(Trail' Line v n -> n)
-> (Trail' Loop v n -> n) -> Trail' l v n -> n
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) -> N (SegTree v n)
-> SegTree v n -> N (SegTree v n) -> N (SegTree v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail' l v n)
N (SegTree v n)
eps SegTree v n
t N (Trail' l v n)
N (SegTree v n)
l)
(\Trail' Loop v n
lp -> N (Trail' Line v n)
-> Trail' Line v n -> N (Trail' Line v n) -> N (Trail' Line v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail' l v n)
N (Trail' Line v n)
eps (Trail' Loop v n -> Trail' Line v n
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)
N (Trail' Line 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' :: p (Unwrapped (Trail' Line v n)) (f (Unwrapped (Trail' Line v n)))
-> p (Trail' Line v n) (f (Trail' Line v n))
_Wrapped' = (Trail' Line v n -> SegTree v n)
-> (SegTree v n -> Trail' Line v n)
-> Iso
(Trail' Line v n) (Trail' Line v n) (SegTree v n) (SegTree v n)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(Line SegTree v n
x) -> SegTree v n
x) SegTree v n -> Trail' Line v n
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 :: p (Segment Closed v n, Trail' Line v n)
(f (Segment Closed u n', Trail' Line u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
_Cons = p (SegTree v n) (f (SegTree u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p (SegTree v n) (f (SegTree u n'))
-> p (Trail' Line v n) (f (Trail' Line u n')))
-> (p (Segment Closed v n, Trail' Line v n)
(f (Segment Closed u n', Trail' Line u n'))
-> p (SegTree v n) (f (SegTree u n')))
-> p (Segment Closed v n, Trail' Line v n)
(f (Segment Closed u n', Trail' Line u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
_Cons (p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n'))
-> p (SegTree v n) (f (SegTree u n')))
-> (p (Segment Closed v n, Trail' Line v n)
(f (Segment Closed u n', Trail' Line u n'))
-> p (Segment Closed v n, SegTree v n)
(f (Segment Closed u n', SegTree u n')))
-> p (Segment Closed v n, Trail' Line v n)
(f (Segment Closed u n', Trail' Line u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
-> AnIso
(SegTree v n) (SegTree u n') (Trail' Line v n) (Trail' Line u n')
-> Iso
(Segment Closed v n, SegTree v n)
(Segment Closed u n', SegTree u n')
(Segment Closed v n, Trail' Line v n)
(Segment Closed u n', Trail' Line u n')
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
forall a. a -> a
id AnIso
(SegTree v n) (SegTree u n') (Trail' Line v n) (Trail' Line u n')
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 :: p (Trail' Line v n, Segment Closed v n)
(f (Trail' Line u n', Segment Closed u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
_Snoc = p (SegTree v n) (f (SegTree u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (p (SegTree v n) (f (SegTree u n'))
-> p (Trail' Line v n) (f (Trail' Line u n')))
-> (p (Trail' Line v n, Segment Closed v n)
(f (Trail' Line u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n')))
-> p (Trail' Line v n, Segment Closed v n)
(f (Trail' Line u n', Segment Closed u n'))
-> p (Trail' Line v n) (f (Trail' Line u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall s t a b. Snoc s t a b => Prism s t (s, a) (t, b)
_Snoc (p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n')))
-> (p (Trail' Line v n, Segment Closed v n)
(f (Trail' Line u n', Segment Closed u n'))
-> p (SegTree v n, Segment Closed v n)
(f (SegTree u n', Segment Closed u n')))
-> p (Trail' Line v n, Segment Closed v n)
(f (Trail' Line u n', Segment Closed u n'))
-> p (SegTree v n) (f (SegTree u n'))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIso
(SegTree v n) (SegTree u n') (Trail' Line v n) (Trail' Line u n')
-> AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
-> Iso
(SegTree v n, Segment Closed v n)
(SegTree u n', Segment Closed u n')
(Trail' Line v n, Segment Closed v n)
(Trail' Line u n', Segment Closed u n')
forall (f :: * -> * -> *) (g :: * -> * -> *) s t a b s' t' a' b'.
(Bifunctor f, Bifunctor g) =>
AnIso s t a b
-> AnIso s' t' a' b' -> Iso (f s s') (g t t') (f a a') (g b b')
bimapping AnIso
(SegTree v n) (SegTree u n') (Trail' Line v n) (Trail' Line u n')
forall s t. Rewrapping s t => Iso (Unwrapped t) (Unwrapped s) t s
_Unwrapped AnIso
(Segment Closed v n)
(Segment Closed u n')
(Segment Closed v n)
(Segment Closed u n')
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 :: t -> GetSegment t
getSegment = t -> GetSegment t
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
N (GetSegment (Trail' Line v n))
p n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
0 = case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain (Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall a b. (a -> b) -> a -> b
$ (v n, Segment Closed v n, AnIso' n n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. a -> Maybe a
Just (v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero, Segment Closed v n
seg, n -> AnIso' n n
reparam n
0)
| n
N (GetSegment (Trail' Line v n))
p n -> n -> Bool
forall a. Ord a => a -> a -> Bool
>= n
1 = case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. Maybe a
Nothing
FingerTree (SegMeasure v n) (Segment Closed v n)
ft' FT.:> Segment Closed v n
seg -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain (Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall a b. (a -> b) -> a -> b
$ (v n, Segment Closed v n, AnIso' n n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. a -> Maybe a
Just (FingerTree (SegMeasure v n) (Segment Closed v n) -> v n
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 -> AnIso' n n
reparam (n
nn -> n -> n
forall 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) = (SegMeasure v n -> Bool)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> (FingerTree (SegMeasure v n) (Segment Closed v n),
FingerTree (SegMeasure v n) (Segment Closed v n))
forall v a.
Measured v a =>
(v -> Bool) -> FingerTree v a -> (FingerTree v a, FingerTree v a)
FT.split ((n
N (GetSegment (Trail' Line v n))
pn -> n -> n
forall a. Num a => a -> a -> a
*n
n n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<) (n -> Bool) -> (SegMeasure v n -> n) -> SegMeasure v n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SegMeasure v 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 case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain (Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall a b. (a -> b) -> a -> b
$ (v n, Segment Closed v n, AnIso' n n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. a -> Maybe a
Just (FingerTree (SegMeasure v n) (Segment Closed v n) -> v n
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 -> AnIso' n n
reparam (FingerTree (SegMeasure v n) (Segment Closed v 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)
before))
where
n :: n
n = FingerTree (SegMeasure v n) (Segment Closed v 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 -> AnIso' n n
reparam n
k = (n -> n) -> (n -> n) -> Iso n n n n
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (n -> n -> n
forall a. Num a => a -> a -> a
subtract n
k (n -> n) -> (n -> n) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> n -> n
forall a. Num a => a -> a -> a
*n
n))
((n -> n -> n
forall a. Fractional a => a -> a -> a
/n
n) (n -> n) -> (n -> n) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> n -> n
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 = GetSegment (Trail' Line v n)
-> N (GetSegment (Trail' Line v n))
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
atParam (Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment (Trail' Loop v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop Trail' Loop v n
l)) (n -> n
forall a. Real a => a -> a
mod1 n
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
= (Trail' Line v n -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegmentCodomain v n)
-> Trail v n
-> GetSegmentCodomain v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
((GetSegment (Trail' Line v n)
-> N (GetSegment (Trail' Line v n))
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (GetSegment (Trail v n))
N (GetSegment (Trail' Line v n))
p) (GetSegment (Trail' Line v n) -> GetSegmentCodomain v n)
-> (Trail' Line v n -> GetSegment (Trail' Line v n))
-> Trail' Line v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment)
((GetSegment (Trail' Loop v n)
-> N (GetSegment (Trail' Loop v n))
-> Codomain
(GetSegment (Trail' Loop v n)) (N (GetSegment (Trail' Loop v n)))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (GetSegment (Trail v n))
N (GetSegment (Trail' Loop v n))
p) (GetSegment (Trail' Loop v n) -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegment (Trail' Loop v n))
-> Trail' Loop v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> GetSegment (Trail' Loop v n)
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) = t -> N t
forall p. DomainBounds p => p -> N p
domainLower t
t
domainUpper :: GetSegment t -> N (GetSegment t)
domainUpper (GetSegment t
t) = t -> N 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 FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewL (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. Maybe a
Nothing
Segment Closed v n
seg FT.:< FingerTree (SegMeasure v n) (Segment Closed v n)
_ ->
let n :: n
n = FingerTree (SegMeasure v n) (Segment Closed v 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 Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain (Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall a b. (a -> b) -> a -> b
$ (v n, Segment Closed v n, AnIso' n n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. a -> Maybe a
Just (v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero, Segment Closed v n
seg, (n -> n) -> (n -> n) -> Iso n n n n
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (n -> n -> n
forall a. Num a => a -> a -> a
*n
n) (n -> 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 FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. Maybe a
Nothing
FingerTree (SegMeasure v n) (Segment Closed v n)
ft' FT.:> Segment Closed v n
seg ->
let n :: n
n = FingerTree (SegMeasure v n) (Segment Closed v 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 Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall (v :: * -> *) n.
Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
GetSegmentCodomain (Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
-> GetSegmentCodomain v n
forall a b. (a -> b) -> a -> b
$
(v n, Segment Closed v n, AnIso' n n)
-> Maybe (v n, Segment Closed v n, AnIso' n n)
forall a. a -> Maybe a
Just (FingerTree (SegMeasure v n) (Segment Closed v n) -> v n
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 -> n) -> (n -> n) -> Iso n n n n
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (n -> n -> n
forall a. Num a => a -> a -> a
subtract (n
nn -> n -> n
forall a. Num a => a -> a -> a
-n
1) (n -> n) -> (n -> n) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> n -> n
forall a. Num a => a -> a -> a
*n
n))
((n -> n -> n
forall a. Fractional a => a -> a -> a
/n
n) (n -> n) -> (n -> n) -> n -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n -> n -> n
forall a. Num a => a -> a -> a
+ (n
nn -> n -> n
forall 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) = GetSegment (Trail' Line v n)
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
forall p. EndValues p => p -> Codomain p (N p)
atStart (Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment (Trail' Loop v n -> Trail' Line v n
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) = GetSegment (Trail' Line v n)
-> Codomain
(GetSegment (Trail' Line v n)) (N (GetSegment (Trail' Line v n)))
forall p. EndValues p => p -> Codomain p (N p)
atEnd (Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment (Trail' Loop v n -> Trail' Line v n
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)
= (Trail' Line v n -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegmentCodomain v n)
-> Trail v n
-> GetSegmentCodomain v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(GetSegment (Trail' Line v n) -> GetSegmentCodomain v n
forall p. EndValues p => p -> Codomain p (N p)
atStart (GetSegment (Trail' Line v n) -> GetSegmentCodomain v n)
-> (Trail' Line v n -> GetSegment (Trail' Line v n))
-> Trail' Line v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment)
(GetSegment (Trail' Loop v n) -> GetSegmentCodomain v n
forall p. EndValues p => p -> Codomain p (N p)
atStart (GetSegment (Trail' Loop v n) -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegment (Trail' Loop v n))
-> Trail' Loop v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> GetSegment (Trail' Loop v n)
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)
= (Trail' Line v n -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegmentCodomain v n)
-> Trail v n
-> GetSegmentCodomain v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(GetSegment (Trail' Line v n) -> GetSegmentCodomain v n
forall p. EndValues p => p -> Codomain p (N p)
atEnd (GetSegment (Trail' Line v n) -> GetSegmentCodomain v n)
-> (Trail' Line v n -> GetSegment (Trail' Line v n))
-> Trail' Line v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> GetSegment (Trail' Line v n)
forall t. t -> GetSegment t
GetSegment)
(GetSegment (Trail' Loop v n) -> GetSegmentCodomain v n
forall p. EndValues p => p -> Codomain p (N p)
atEnd (GetSegment (Trail' Loop v n) -> GetSegmentCodomain v n)
-> (Trail' Loop v n -> GetSegment (Trail' Loop v n))
-> Trail' Loop v n
-> GetSegmentCodomain v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> GetSegment (Trail' Loop v n)
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 =
(Trail' Line v n -> Bool)
-> (Trail' Loop v n -> Bool) -> Trail v n -> Bool
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(\Trail' Line v n
ln1 -> (Trail' Line v n -> Bool)
-> (Trail' Loop v n -> Bool) -> Trail v n -> Bool
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 Trail' Line v n -> Trail' Line v n -> Bool
forall a. Eq a => a -> a -> Bool
== Trail' Line v n
ln2) (Bool -> Trail' Loop v n -> Bool
forall a b. a -> b -> a
const Bool
False) Trail v n
t2)
(\Trail' Loop v n
lp1 -> (Trail' Line v n -> Bool)
-> (Trail' Loop v n -> Bool) -> Trail v n -> Bool
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Bool -> Trail' Line v n -> Bool
forall a b. a -> b -> a
const Bool
False) (\Trail' Loop v n
lp2 -> Trail' Loop v n
lp1 Trail' Loop v n -> Trail' Loop v n -> Bool
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 =
(Trail' Line v n -> Ordering)
-> (Trail' Loop v n -> Ordering) -> Trail v n -> Ordering
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail
(\Trail' Line v n
ln1 -> (Trail' Line v n -> Ordering)
-> (Trail' Loop v n -> Ordering) -> Trail v n -> Ordering
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Trail' Line v n -> Trail' Line v n -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Trail' Line v n
ln1) (Ordering -> Trail' Loop v n -> Ordering
forall a b. a -> b -> a
const Ordering
LT) Trail v n
t2)
(\Trail' Loop v n
lp1 -> (Trail' Line v n -> Ordering)
-> (Trail' Loop v n -> Ordering) -> Trail v n -> Ordering
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Ordering -> Trail' Line v n -> Ordering
forall a b. a -> b -> a
const Ordering
GT) (Trail' Loop v n -> Trail' Loop v n -> Ordering
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 | FingerTree (SegMeasure v n) (Segment Closed v n) -> Bool
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))) | FingerTree (SegMeasure v n) (Segment Closed v n) -> Bool
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 = ((Trail' Line v n -> Trail v n) -> Trail v n -> Trail v n)
-> Trail v n -> (Trail' Line v n -> Trail v n) -> Trail v n
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Trail' Line v n -> Trail v n) -> Trail v n -> Trail v n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail v n
t1 ((Trail' Line v n -> Trail v n) -> Trail v n)
-> (Trail' Line v n -> Trail v n) -> Trail v n
forall a b. (a -> b) -> a -> b
$ \Trail' Line v n
l1 ->
((Trail' Line v n -> Trail v n) -> Trail v n -> Trail v n)
-> Trail v n -> (Trail' Line v n -> Trail v n) -> Trail v n
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Trail' Line v n -> Trail v n) -> Trail v n -> Trail v n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail v n
t2 ((Trail' Line v n -> Trail v n) -> Trail v n)
-> (Trail' Line v n -> Trail v n) -> Trail v n
forall a b. (a -> b) -> a -> b
$ \Trail' Line v n
l2 ->
Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine (Trail' Line v n
l1 Trail' Line v n -> Trail' Line v n -> Trail' Line v n
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 = Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
mappend :: Trail v n -> Trail v n -> Trail v n
mappend = Trail v n -> Trail v n -> Trail v n
forall a. Semigroup a => a -> a -> a
(<>)
instance (Metric v, OrderedField n) => AsEmpty (Trail v n) where
_Empty :: p () (f ()) -> p (Trail v n) (f (Trail v n))
_Empty = Trail v n -> (Trail v n -> Bool) -> Prism' (Trail v n) ()
forall a. a -> (a -> Bool) -> Prism' a ()
nearly Trail v n
forall (v :: * -> *) n. (Metric v, OrderedField n) => Trail v n
emptyTrail Trail v n -> Bool
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 = (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Loop v n) -> Trail v n -> Trail v n
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 (Transformation (V (Trail' Line v n)) (N (Trail' Line v n))
-> Trail' Line v n -> Trail' Line v n
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail v n)) (N (Trail v n))
Transformation (V (Trail' Line v n)) (N (Trail' Line v n))
t) (Transformation (V (Trail' Loop v n)) (N (Trail' Loop v n))
-> Trail' Loop v n -> Trail' Loop v n
forall t. Transformable t => Transformation (V t) (N t) -> t -> t
transform Transformation (V (Trail v n)) (N (Trail v n))
Transformation (V (Trail' Loop v n)) (N (Trail' Loop 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 = (Trail' Line v n -> Envelope v n)
-> (Trail' Loop v n -> Envelope v n) -> Trail v n -> Envelope v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail Trail' Line v n -> Envelope v n
forall a. Enveloped a => a -> Envelope (V a) (N a)
getEnvelope Trail' Loop v n -> Envelope v n
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 = (Trail' Line v n -> v n)
-> (Trail' Loop v n -> v n) -> Trail v n -> v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Trail' Line v n
-> N (Trail' Line v n)
-> Codomain (Trail' Line v n) (N (Trail' Line v n))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail v n)
N (Trail' Line v n)
p) (Trail' Loop v n
-> N (Trail' Loop v n)
-> Codomain (Trail' Loop v n) (N (Trail' Loop v n))
forall p. Parametric p => p -> N p -> Codomain p (N p)
`atParam` N (Trail v n)
N (Trail' Loop 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 = (Trail' Line v n -> (Trail v n, Trail v n))
-> Trail v n -> (Trail v n, Trail v n)
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine ((Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine (Trail' Line v n -> Trail v n)
-> (Trail' Line v n -> Trail v n)
-> (Trail' Line v n, Trail' Line v n)
-> (Trail v n, Trail v n)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine) ((Trail' Line v n, Trail' Line v n) -> (Trail v n, Trail v n))
-> (Trail' Line v n -> (Trail' Line v n, Trail' Line v n))
-> Trail' Line v n
-> (Trail v n, Trail v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' Line v n
-> N (Trail' Line v n) -> (Trail' Line v n, Trail' Line v n)
forall p. Sectionable p => p -> N p -> (p, p)
`splitAtParam` N (Trail v n)
N (Trail' Line 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 = (Trail' Line v n -> Trail v n) -> Trail v n -> Trail v n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine (Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine (Trail' Line v n -> Trail v n)
-> (Trail' Line v n -> Trail' Line v n)
-> Trail' Line v n
-> Trail v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Trail' Line v n
l -> Trail' Line v n
-> N (Trail' Line v n) -> N (Trail' Line v n) -> Trail' Line v n
forall p. Sectionable p => p -> N p -> N p -> p
section Trail' Line v n
l N (Trail v n)
N (Trail' Line v n)
p1 N (Trail v n)
N (Trail' Line v n)
p2)) Trail v n
t
reverseDomain :: Trail v n -> Trail v n
reverseDomain = Trail v n -> Trail v n
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 = (Trail' Line v n -> Interval n) -> Trail v n -> Interval n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine ((Trail' Line v n -> Interval n) -> Trail v n -> Interval n)
-> (n -> Trail' Line v n -> Interval n)
-> n
-> Trail v n
-> Interval n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. n -> Trail' Line v n -> Interval n
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 = (Trail' Line v n -> n) -> Trail v n -> n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine (\Trail' Line v n
ln -> N (Trail' Line v n)
-> Trail' Line v n -> N (Trail' Line v n) -> N (Trail' Line v n)
forall p. HasArcLength p => N p -> p -> N p -> N p
arcLengthToParam N (Trail v n)
N (Trail' Line v n)
eps Trail' Line v n
ln N (Trail v n)
N (Trail' Line v n)
al) Trail v n
tr
_Line :: Prism' (Trail v n) (Trail' Line v n)
_Line :: p (Trail' Line v n) (f (Trail' Line v n))
-> p (Trail v n) (f (Trail v n))
_Line = p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
-> p (Trail v n) (f (Trail v n))
forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' (p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
-> p (Trail v n) (f (Trail v n)))
-> (p (Trail' Line v n) (f (Trail' Line v n))
-> p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n))))
-> p (Trail' Line v n) (f (Trail' Line v n))
-> p (Trail v n) (f (Trail v n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Trail' Line v n) (f (Trail' Line v n))
-> p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
forall a c b. Prism (Either a c) (Either b c) a b
_Left
_Loop :: Prism' (Trail v n) (Trail' Loop v n)
_Loop :: p (Trail' Loop v n) (f (Trail' Loop v n))
-> p (Trail v n) (f (Trail v n))
_Loop = p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
-> p (Trail v n) (f (Trail v n))
forall s. Wrapped s => Iso' s (Unwrapped s)
_Wrapped' (p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
-> p (Trail v n) (f (Trail v n)))
-> (p (Trail' Loop v n) (f (Trail' Loop v n))
-> p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n))))
-> p (Trail' Loop v n) (f (Trail' Loop v n))
-> p (Trail v n) (f (Trail v n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (Trail' Loop v n) (f (Trail' Loop v n))
-> p (Either (Trail' Line v n) (Trail' Loop v n))
(f (Either (Trail' Line v n) (Trail' Loop v n)))
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 :: p (Located (Trail' Line v n)) (f (Located (Trail' Line v n)))
-> p (Located (Trail v n)) (f (Located (Trail v n)))
_LocLine = (Located (Trail' Line v n) -> Located (Trail v n))
-> (Located (Trail v n) -> Maybe (Located (Trail' Line v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Line v n))
(Located (Trail' Line v n))
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((Trail' Line v n -> Trail v n)
-> Located (Trail' Line v n) -> Located (Trail v n)
forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail) ((Located (Trail v n) -> Maybe (Located (Trail' Line v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Line v n))
(Located (Trail' Line v n)))
-> (Located (Trail v n) -> Maybe (Located (Trail' Line v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Line v n))
(Located (Trail' Line v n))
forall a b. (a -> b) -> a -> b
$ (Trail v n -> Maybe (Trail' Line v n))
-> Located (Trail v n) -> Maybe (Located (Trail' Line v n))
forall a b. SameSpace a b => Lens (Located a) (Located b) a b
located (Getting (First (Trail' Line v n)) (Trail v n) (Trail' Line v n)
-> Trail v n -> Maybe (Trail' Line v n)
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First (Trail' Line v n)) (Trail v n) (Trail' Line v n)
forall (v :: * -> *) n. Prism' (Trail v n) (Trail' Line v n)
_Line)
_LocLoop :: Prism' (Located (Trail v n)) (Located (Trail' Loop v n))
_LocLoop :: p (Located (Trail' Loop v n)) (f (Located (Trail' Loop v n)))
-> p (Located (Trail v n)) (f (Located (Trail v n)))
_LocLoop = (Located (Trail' Loop v n) -> Located (Trail v n))
-> (Located (Trail v n) -> Maybe (Located (Trail' Loop v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Loop v n))
(Located (Trail' Loop v n))
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((Trail' Loop v n -> Trail v n)
-> Located (Trail' Loop v n) -> Located (Trail v n)
forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc Trail' Loop v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail) ((Located (Trail v n) -> Maybe (Located (Trail' Loop v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Loop v n))
(Located (Trail' Loop v n)))
-> (Located (Trail v n) -> Maybe (Located (Trail' Loop v n)))
-> Prism
(Located (Trail v n))
(Located (Trail v n))
(Located (Trail' Loop v n))
(Located (Trail' Loop v n))
forall a b. (a -> b) -> a -> b
$ (Trail v n -> Maybe (Trail' Loop v n))
-> Located (Trail v n) -> Maybe (Located (Trail' Loop v n))
forall a b. SameSpace a b => Lens (Located a) (Located b) a b
located (Getting (First (Trail' Loop v n)) (Trail v n) (Trail' Loop v n)
-> Trail v n -> Maybe (Trail' Loop v n)
forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First (Trail' Loop v n)) (Trail v n) (Trail' Loop v n)
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' :: p (Unwrapped (Trail v n)) (f (Unwrapped (Trail v n)))
-> p (Trail v n) (f (Trail v n))
_Wrapped' = (Trail v n -> Either (Trail' Line v n) (Trail' Loop v n))
-> (Either (Trail' Line v n) (Trail' Loop v n) -> Trail v n)
-> Iso
(Trail v n)
(Trail v n)
(Either (Trail' Line v n) (Trail' Loop v n))
(Either (Trail' Line v n) (Trail' Loop v n))
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 ((Trail' Line v n -> Trail v n)
-> (Trail' Loop v n -> Trail v n)
-> Either (Trail' Line v n) (Trail' Loop v n)
-> Trail v n
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail Trail' Loop v n -> Trail v n
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 {})) = Trail' l v n -> Either (Trail' l v n) (Trail' Loop v n)
forall a b. a -> Either a b
Left Trail' l v n
t
getTrail (Trail t :: Trail' l v n
t@(Loop {})) = Trail' l v n -> Either (Trail' Line v n) (Trail' l v n)
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 :: (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) = (Trail' Line v n -> r)
-> (Trail' Loop v n -> r) -> Trail' l v n -> r
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 :: (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 = (Trail' Line v n -> Trail v n)
-> (Trail' Loop v n -> Trail v n) -> Trail v n -> Trail v n
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Trail' l1 v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail (Trail' l1 v n -> Trail v n)
-> (Trail' Line v n -> Trail' l1 v n)
-> Trail' Line v n
-> Trail v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' l1 v n
o) (Trail' l2 v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail (Trail' l2 v n -> Trail v n)
-> (Trail' Loop v n -> Trail' l2 v n)
-> Trail' Loop v n
-> Trail v n
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 :: (Trail' Line v n -> r) -> Trail v n -> r
withLine Trail' Line v n -> r
f = (Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
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 (Trail' Line v n -> r)
-> (Trail' Loop v n -> Trail' Line v n) -> Trail' Loop v n -> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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 :: (Trail' Line v n -> Trail' Line v n) -> Trail v n -> Trail v n
onLine Trail' Line v n -> Trail' Line v n
f = (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Loop v n) -> Trail v n -> Trail v n
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 (Trail' Line v n -> Trail' Loop v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine (Trail' Line v n -> Trail' Loop v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Loop v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' Line v n
f (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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 :: Trail' l v n -> Trail v n
wrapTrail = Trail' l v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail
wrapLine :: Trail' Line v n -> Trail v n
wrapLine :: Trail' Line v n -> Trail v n
wrapLine = Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail
wrapLoop :: Trail' Loop v n -> Trail v n
wrapLoop :: Trail' Loop v n -> Trail v n
wrapLoop = Trail' Loop v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail
emptyLine :: (Metric v, OrderedField n) => Trail' Line v n
emptyLine :: Trail' Line v n
emptyLine = SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
forall a. Monoid a => a
mempty
emptyTrail :: (Metric v, OrderedField n) => Trail v n
emptyTrail :: Trail v n
emptyTrail = Trail' Line v n -> Trail v n
forall (v :: * -> *) n. Trail' Line v n -> Trail v n
wrapLine Trail' Line v n
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 :: [Segment Closed v n] -> Trail' Line v n
lineFromSegments = SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (SegTree v n -> Trail' Line v n)
-> ([Segment Closed v n] -> SegTree v n)
-> [Segment Closed v n]
-> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n)
-> ([Segment Closed v n]
-> FingerTree (SegMeasure v n) (Segment Closed v n))
-> [Segment Closed v n]
-> SegTree v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n]
-> FingerTree (SegMeasure v n) (Segment Closed v n)
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 :: [Segment Closed v n] -> Segment Open v n -> Trail' Loop v n
loopFromSegments [Segment Closed v n]
segs = SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree ([Segment Closed v n]
-> FingerTree (SegMeasure v n) (Segment Closed v n)
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 :: [Segment Closed v n] -> Trail v n
trailFromSegments = Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail (Trail' Line v n -> Trail v n)
-> ([Segment Closed v n] -> Trail' Line v n)
-> [Segment Closed v n]
-> Trail v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> Trail' Line v n
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 :: [v n] -> Trail' Line v n
lineFromOffsets = [Segment Closed v n] -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments ([Segment Closed v n] -> Trail' Line v n)
-> ([v n] -> [Segment Closed v n]) -> [v n] -> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v n -> Segment Closed v n) -> [v n] -> [Segment Closed v n]
forall a b. (a -> b) -> [a] -> [b]
map v n -> Segment Closed v n
forall (v :: * -> *) n. v n -> Segment Closed v n
straight
trailFromOffsets :: (Metric v, OrderedField n) => [v n] -> Trail v n
trailFromOffsets :: [v n] -> Trail v n
trailFromOffsets = Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail (Trail' Line v n -> Trail v n)
-> ([v n] -> Trail' Line v n) -> [v n] -> Trail v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [v n] -> Trail' Line v n
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 :: [Point v n] -> Trail' Line v n
lineFromVertices [] = Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
lineFromVertices [Point v n
_] = Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
lineFromVertices [Point v n]
ps = [Segment Closed v n] -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments ([Segment Closed v n] -> Trail' Line v n)
-> ([v n] -> [Segment Closed v n]) -> [v n] -> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v n -> Segment Closed v n) -> [v n] -> [Segment Closed v n]
forall a b. (a -> b) -> [a] -> [b]
map v n -> Segment Closed v n
forall (v :: * -> *) n. v n -> Segment Closed v n
straight ([v n] -> Trail' Line v n) -> [v n] -> Trail' Line v n
forall a b. (a -> b) -> a -> b
$ (Point v n -> Point v n -> v n)
-> [Point v n] -> [Point v n] -> [v n]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Point v n -> Point v n -> v n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> p a -> Diff p a
(.-.) ([Point v n] -> [Point v n]
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 :: [Point v n] -> Trail v n
trailFromVertices = Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
wrapTrail (Trail' Line v n -> Trail v n)
-> ([Point v n] -> Trail' Line v n) -> [Point v n] -> Trail v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Point v n] -> Trail' Line v n
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 :: Trail' Line v n -> Trail' Loop v n
glueLine (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) =
case FingerTree (SegMeasure v n) (Segment Closed v n)
-> ViewR (FingerTree (SegMeasure v n)) (Segment Closed v n)
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 -> SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop SegTree v n
forall a. Monoid a => a
mempty (Offset Open v n -> Segment Open v n
forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear Offset Open v n
forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
FingerTree (SegMeasure v n) (Segment Closed v n)
t' FT.:> Linear Offset Closed v n
_ -> SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t') (Offset Open v n -> Segment Open v n
forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear Offset Open v n
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
_ -> SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t') (v n -> v n -> Offset Open v n -> Segment Open v n
forall c (v :: * -> *) n.
v n -> v n -> Offset c v n -> Segment c v n
Cubic v n
c1 v n
c2 Offset Open v n
forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
glueTrail :: (Metric v, OrderedField n) => Trail v n -> Trail v n
glueTrail :: Trail v n -> Trail v n
glueTrail = (Trail' Line v n -> Trail' Loop v n)
-> (Trail' Loop v n -> Trail' Loop v n) -> Trail v n -> Trail v n
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' Loop v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine Trail' Loop v n -> Trail' Loop v n
forall a. a -> a
id
closeLine :: Trail' Line v n -> Trail' Loop v n
closeLine :: Trail' Line v n -> Trail' Loop v n
closeLine (Line SegTree v n
t) = SegTree v n -> Segment Open v n -> Trail' Loop v n
forall (v :: * -> *) n.
SegTree v n -> Segment Open v n -> Trail' Loop v n
Loop SegTree v n
t (Offset Open v n -> Segment Open v n
forall c (v :: * -> *) n. Offset c v n -> Segment c v n
Linear Offset Open v n
forall (v :: * -> *) n. Offset Open v n
OffsetOpen)
closeTrail :: Trail v n -> Trail v n
closeTrail :: Trail v n -> Trail v n
closeTrail = (Trail' Line v n -> Trail' Loop v n)
-> (Trail' Loop v n -> Trail' Loop v n) -> Trail v n -> Trail v n
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' Loop v n
forall (v :: * -> *) n. Trail' Line v n -> Trail' Loop v n
closeLine Trail' Loop v n -> Trail' Loop v n
forall a. a -> a
id
cutLoop :: forall v n. (Metric v, OrderedField n)
=> Trail' Loop v n -> Trail' Line v n
cutLoop :: 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 (FingerTree (SegMeasure v n) (Segment Closed v n) -> Bool
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) -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n
emptyLine
(Bool
_ , Linear Offset Open v n
OffsetOpen) -> SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n)
t FingerTree (SegMeasure v n) (Segment Closed v n)
-> Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> Offset Closed v n -> Segment Closed v n
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) -> SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree (FingerTree (SegMeasure v n) (Segment Closed v n)
t FingerTree (SegMeasure v n) (Segment Closed v n)
-> Segment Closed v n
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v a. Measured v a => FingerTree v a -> a -> FingerTree v a
|> v n -> v n -> Offset Closed v n -> Segment Closed v n
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 = v n -> v n
forall (f :: * -> *) a. (Functor f, Num a) => f a -> f a
negated (v n -> v n)
-> (FingerTree (SegMeasure v n) (Segment Closed v n) -> v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v n
-> (OffsetEnvelope v n -> v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n)
-> v n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero ((Unwrapped (TotalOffset v n) -> TotalOffset v n)
-> TotalOffset v n -> Unwrapped (TotalOffset v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (TotalOffset v n) -> TotalOffset v n
forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset (TotalOffset v n -> v n)
-> (OffsetEnvelope v n -> TotalOffset v n)
-> OffsetEnvelope v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
-> OffsetEnvelope v n -> TotalOffset v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
forall (v :: * -> *) n.
Lens' (OffsetEnvelope v n) (TotalOffset v n)
oeOffset) (FingerTree (SegMeasure v n) (Segment Closed v n) -> v n)
-> FingerTree (SegMeasure v n) (Segment Closed v n) -> v n
forall a b. (a -> b) -> a -> b
$ FingerTree (SegMeasure v n) (Segment Closed v n)
t
off :: Offset Closed v n
off = v n -> Offset Closed v n
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 :: Trail v n -> Trail v n
cutTrail = (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Line v n) -> Trail v n -> Trail v n
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
forall a. a -> a
id Trail' Loop v n -> Trail' Line v n
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 :: Trail' Line v n -> Bool
isLineEmpty (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) = FingerTree (SegMeasure v n) (Segment Closed v n) -> Bool
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 :: Trail v n -> Bool
isTrailEmpty = (Trail' Line v n -> Bool)
-> (Trail' Loop v n -> Bool) -> Trail v n -> Bool
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail Trail' Line v n -> Bool
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Bool
isLineEmpty (Bool -> Trail' Loop v n -> Bool
forall a b. a -> b -> a
const Bool
False)
isLine :: Trail v n -> Bool
isLine :: Trail v n -> Bool
isLine = Bool -> Bool
not (Bool -> Bool) -> (Trail v n -> Bool) -> Trail v n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail v n -> Bool
forall (v :: * -> *) n. Trail v n -> Bool
isLoop
isLoop :: Trail v n -> Bool
isLoop :: Trail v n -> Bool
isLoop = (Trail' Line v n -> Bool)
-> (Trail' Loop v n -> Bool) -> Trail v n -> Bool
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Bool -> Trail' Line v n -> Bool
forall a b. a -> b -> a
const Bool
False) (Bool -> Trail' Loop v n -> Bool
forall a b. a -> b -> a
const Bool
True)
lineSegments :: Trail' Line v n -> [Segment Closed v n]
lineSegments :: Trail' Line v n -> [Segment Closed v n]
lineSegments (Line (SegTree FingerTree (SegMeasure v n) (Segment Closed v n)
t)) = FingerTree (SegMeasure v n) (Segment Closed v n)
-> [Segment Closed v n]
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 :: ([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 = [Segment Closed v n] -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail' Line v n
lineFromSegments ([Segment Closed v n] -> Trail' Line v n)
-> (Trail' Line v n -> [Segment Closed v n])
-> Trail' Line v n
-> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> [Segment Closed v n]
f ([Segment Closed v n] -> [Segment Closed v n])
-> (Trail' Line v n -> [Segment Closed v n])
-> Trail' Line v n
-> [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> [Segment Closed v n]
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 :: 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) = (FingerTree (SegMeasure v n) (Segment Closed v n)
-> [Segment Closed v n]
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 :: Trail v n -> [Segment Closed v n]
trailSegments = (Trail' Line v n -> [Segment Closed v n])
-> Trail v n -> [Segment Closed v n]
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail' Line v n -> [Segment Closed v n]
forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments
trailOffsets :: (Metric v, OrderedField n) => Trail v n -> [v n]
trailOffsets :: Trail v n -> [v n]
trailOffsets = (Trail' Line v n -> [v n]) -> Trail v n -> [v n]
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail' Line v n -> [v n]
forall (v :: * -> *) n. Trail' Line v n -> [v n]
lineOffsets
trailOffset :: (Metric v, OrderedField n) => Trail v n -> v n
trailOffset :: Trail v n -> v n
trailOffset = (Trail' Line v n -> v n) -> Trail v n -> v n
forall (v :: * -> *) n r.
(Metric v, OrderedField n) =>
(Trail' Line v n -> r) -> Trail v n -> r
withLine Trail' Line v n -> v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> v n
lineOffset
lineOffsets :: Trail' Line v n -> [v n]
lineOffsets :: Trail' Line v n -> [v n]
lineOffsets = (Segment Closed v n -> v n) -> [Segment Closed v n] -> [v n]
forall a b. (a -> b) -> [a] -> [b]
map Segment Closed v n -> v n
forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset ([Segment Closed v n] -> [v n])
-> (Trail' Line v n -> [Segment Closed v n])
-> Trail' Line v n
-> [v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> [Segment Closed v n]
forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments
loopOffsets :: (Metric v, OrderedField n) => Trail' Loop v n -> [v n]
loopOffsets :: Trail' Loop v n -> [v n]
loopOffsets = Trail' Line v n -> [v n]
forall (v :: * -> *) n. Trail' Line v n -> [v n]
lineOffsets (Trail' Line v n -> [v n])
-> (Trail' Loop v n -> Trail' Line v n) -> Trail' Loop v n -> [v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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 :: Trail' Line v n -> v n
lineOffset (Line SegTree v n
t) = v n -> (OffsetEnvelope v n -> v n) -> SegTree v n -> v n
forall (v :: * -> *) n m t a.
(SegMeasure v n :>: m, Measured (SegMeasure v n) t) =>
a -> (m -> a) -> t -> a
trailMeasure v n
forall (f :: * -> *) a. (Additive f, Num a) => f a
zero ((Unwrapped (TotalOffset v n) -> TotalOffset v n)
-> TotalOffset v n -> Unwrapped (TotalOffset v n)
forall s. Wrapped s => (Unwrapped s -> s) -> s -> Unwrapped s
op Unwrapped (TotalOffset v n) -> TotalOffset v n
forall (v :: * -> *) n. v n -> TotalOffset v n
TotalOffset (TotalOffset v n -> v n)
-> (OffsetEnvelope v n -> TotalOffset v n)
-> OffsetEnvelope v n
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
-> OffsetEnvelope v n -> TotalOffset v n
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (TotalOffset v n) (OffsetEnvelope v n) (TotalOffset v n)
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 :: Located (Trail v n) -> [Point v n]
trailPoints (Located (Trail v n)
-> (Point (V (Trail v n)) (N (Trail v n)), Trail v n)
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail v n)) (N (Trail v n))
p,Trail v n
t))
= (Trail' Line v n -> [Point v n])
-> (Trail' Loop v n -> [Point v n]) -> Trail v n -> [Point v n]
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (Located (Trail' Line v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> [Point v n]
linePoints (Located (Trail' Line v n) -> [Point v n])
-> (Trail' Line v n -> Located (Trail' Line v n))
-> Trail' Line v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' Line v n
-> Point (V (Trail' Line v n)) (N (Trail' Line v n))
-> Located (Trail' Line v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
Point (V (Trail' Line v n)) (N (Trail' Line v n))
p)) (Located (Trail' Loop v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> [Point v n]
loopPoints (Located (Trail' Loop v n) -> [Point v n])
-> (Trail' Loop v n -> Located (Trail' Loop v n))
-> Trail' Loop v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' Loop v n
-> Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
-> Located (Trail' Loop v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p)) Trail v n
t
linePoints :: (Metric v, OrderedField n)
=> Located (Trail' Line v n) -> [Point v n]
linePoints :: Located (Trail' Line v n) -> [Point v n]
linePoints (Located (Trail' Line v n)
-> (Point (V (Trail' Line v n)) (N (Trail' Line v n)),
Trail' Line v n)
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))
= Point v n -> [Segment Closed v n] -> [Point v n]
forall (v :: * -> *) n.
(Additive v, Num n) =>
Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point v n
Point (V (Trail' Line v n)) (N (Trail' Line v n))
p ([Segment Closed v n] -> [Point v n])
-> (Trail' Line v n -> [Segment Closed v n])
-> Trail' Line v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> [Segment Closed v n]
forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments (Trail' Line v n -> [Point v n]) -> Trail' Line v n -> [Point v n]
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 :: Located (Trail' Loop v n) -> [Point v n]
loopPoints (Located (Trail' Loop v n)
-> (Point (V (Trail' Loop v n)) (N (Trail' Loop v n)),
Trail' Loop v n)
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))
= Point v n -> [Segment Closed v n] -> [Point v n]
forall (v :: * -> *) n.
(Additive v, Num n) =>
Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point v n
Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p ([Segment Closed v n] -> [Point v n])
-> (Trail' Loop v n -> [Segment Closed v n])
-> Trail' Loop v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Segment Closed v n], Segment Open v n) -> [Segment Closed v n]
forall a b. (a, b) -> a
fst (([Segment Closed v n], Segment Open v n) -> [Segment Closed v n])
-> (Trail' Loop v n -> ([Segment Closed v n], Segment Open v n))
-> Trail' Loop v n
-> [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> ([Segment Closed v n], Segment Open v n)
forall (v :: * -> *) n.
Trail' Loop v n -> ([Segment Closed v n], Segment Open v n)
loopSegments (Trail' Loop v n -> [Point v n]) -> Trail' Loop v n -> [Point v n]
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 :: Point v n -> [Segment Closed v n] -> [Point v n]
segmentPoints Point v n
p = (Point v n -> v n -> Point v n)
-> Point v n -> [v n] -> [Point v n]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl Point v n -> v n -> Point v n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
(.+^) Point v n
p ([v n] -> [Point v n])
-> ([Segment Closed v n] -> [v n])
-> [Segment Closed v n]
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Segment Closed v n -> v n) -> [Segment Closed v n] -> [v n]
forall a b. (a -> b) -> [a] -> [b]
map Segment Closed v n -> v n
forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset
tolerance :: OrderedField a => a
tolerance :: a
tolerance = a
10e-16
trailVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail v n) -> [Point v n]
trailVertices' :: n -> Located (Trail v n) -> [Point v n]
trailVertices' n
toler (Located (Trail v n)
-> (Point (V (Trail v n)) (N (Trail v n)), Trail v n)
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail v n)) (N (Trail v n))
p,Trail v n
t))
= (Trail' Line v n -> [Point v n])
-> (Trail' Loop v n -> [Point v n]) -> Trail v n -> [Point v n]
forall (v :: * -> *) n r.
(Trail' Line v n -> r) -> (Trail' Loop v n -> r) -> Trail v n -> r
withTrail (n -> Located (Trail' Line v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' n
toler (Located (Trail' Line v n) -> [Point v n])
-> (Trail' Line v n -> Located (Trail' Line v n))
-> Trail' Line v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' Line v n
-> Point (V (Trail' Line v n)) (N (Trail' Line v n))
-> Located (Trail' Line v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
Point (V (Trail' Line v n)) (N (Trail' Line v n))
p)) (n -> Located (Trail' Loop v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' n
toler (Located (Trail' Loop v n) -> [Point v n])
-> (Trail' Loop v n -> Located (Trail' Loop v n))
-> Trail' Loop v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Trail' Loop v n
-> Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
-> Located (Trail' Loop v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V (Trail v n)) (N (Trail v n))
Point (V (Trail' Loop v n)) (N (Trail' Loop v n))
p)) Trail v n
t
trailVertices :: (Metric v, OrderedField n)
=> Located (Trail v n) -> [Point v n]
trailVertices :: Located (Trail v n) -> [Point v n]
trailVertices = n -> Located (Trail v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail v n) -> [Point v n]
trailVertices' n
forall a. OrderedField a => a
tolerance
lineVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' :: n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' n
toler (Located (Trail' Line v n)
-> (Point (V (Trail' Line v n)) (N (Trail' Line v n)),
Trail' Line v n)
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))
= n -> Point v n -> [Segment Closed v n] -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' n
toler Point v n
Point (V (Trail' Line v n)) (N (Trail' Line v n))
p ([Segment Closed v n] -> [Point v n])
-> (Trail' Line v n -> [Segment Closed v n])
-> Trail' Line v n
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> [Segment Closed v n]
forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments (Trail' Line v n -> [Point v n]) -> Trail' Line v n -> [Point v n]
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 :: Located (Trail' Line v n) -> [Point v n]
lineVertices = n -> Located (Trail' Line v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Line v n) -> [Point v n]
lineVertices' n
forall a. OrderedField a => a
tolerance
loopVertices' :: (Metric v, OrderedField n)
=> n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' :: n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' n
toler (Located (Trail' Loop v n)
-> (Point (V (Trail' Loop v n)) (N (Trail' Loop v n)),
Trail' Loop v n)
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))
| [Segment Closed v n] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Segment Closed v n]
segs Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 = if n
far n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
toler then [Point v n] -> [Point v n]
forall a. [a] -> [a]
init [Point v n]
ps else [Point v n] -> [Point v n]
forall a. [a] -> [a]
init ([Point v n] -> [Point v n])
-> ([Point v n] -> [Point v n]) -> [Point v n] -> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Point v n] -> [Point v n]
forall a. Int -> [a] -> [a]
drop Int
1 ([Point v n] -> [Point v n]) -> [Point v n] -> [Point v n]
forall a b. (a -> b) -> a -> b
$ [Point v n]
ps
| Bool
otherwise = [Point v n]
ps
where
far :: n
far = v n -> n
forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance ((v n -> v n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n)
-> ([Segment Closed v n] -> v n) -> [Segment Closed v n] -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Segment Closed v n -> v n
forall t. EndValues (Tangent t) => t -> Vn t
tangentAtStart (Segment Closed v n -> v n)
-> ([Segment Closed v n] -> Segment Closed v n)
-> [Segment Closed v n]
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> Segment Closed v n
forall a. [a] -> a
head ([Segment Closed v n] -> v n) -> [Segment Closed v n] -> v n
forall a b. (a -> b) -> a -> b
$ [Segment Closed v n]
segs) v n -> v n -> v n
forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^
(v n -> v n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n)
-> ([Segment Closed v n] -> v n) -> [Segment Closed v n] -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Segment Closed v n -> v n
forall t. EndValues (Tangent t) => t -> Vn t
tangentAtEnd (Segment Closed v n -> v n)
-> ([Segment Closed v n] -> Segment Closed v n)
-> [Segment Closed v n]
-> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Segment Closed v n] -> Segment Closed v n
forall a. [a] -> a
last ([Segment Closed v n] -> v n) -> [Segment Closed v n] -> v n
forall a b. (a -> b) -> a -> b
$ [Segment Closed v n]
segs))
segs :: [Segment Closed v n]
segs = Trail' Line v n -> [Segment Closed v n]
forall (v :: * -> *) n. Trail' Line v n -> [Segment Closed v n]
lineSegments (Trail' Line v n -> [Segment Closed v n])
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop (Trail' Loop v n -> [Segment Closed v n])
-> Trail' Loop v n -> [Segment Closed v n]
forall a b. (a -> b) -> a -> b
$ Trail' Loop v n
t
ps :: [Point v n]
ps = n -> Point v n -> [Segment Closed v n] -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' n
toler Point v n
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 :: Located (Trail' Loop v n) -> [Point v n]
loopVertices = n -> Located (Trail' Loop v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
n -> Located (Trail' Loop v n) -> [Point v n]
loopVertices' n
forall a. OrderedField a => a
tolerance
segmentVertices' :: (Metric v, OrderedField n)
=> n -> Point v n -> [Segment Closed v n] -> [Point v n]
segmentVertices' :: 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 Point v n -> [Point v n] -> [Point v n]
forall a. a -> [a] -> [a]
: [Point v n] -> [Bool] -> [Point v n]
forall a. [a] -> [Bool] -> [a]
select (Int -> [Point v n] -> [Point v n]
forall a. Int -> [a] -> [a]
drop Int
1 [Point v n]
ps) [Bool]
ds [Point v n] -> [Point v n] -> [Point v n]
forall a. [a] -> [a] -> [a]
++ [[Point v n] -> Point v n
forall a. [a] -> a
last [Point v n]
ps]
[Point v n]
_ -> [Point v n]
ps
where
ds :: [Bool]
ds = ((v n, v n) -> (v n, v n) -> Bool)
-> [(v n, v n)] -> [(v n, v n)] -> [Bool]
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 (Int -> [(v n, v n)] -> [(v n, v n)]
forall a. Int -> [a] -> [a]
drop Int
1 [(v n, v n)]
tans)
tans :: [(v n, v n)]
tans = [(v n -> v n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n)
-> (Segment Closed v n -> v n) -> Segment Closed v n -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Segment Closed v n -> v n
forall t. EndValues (Tangent t) => t -> Vn t
tangentAtStart (Segment Closed v n -> v n) -> Segment Closed v n -> v n
forall a b. (a -> b) -> a -> b
$ Segment Closed v n
s
,v n -> v n
forall (f :: * -> *) a. (Metric f, Floating a) => f a -> f a
signorm (v n -> v n)
-> (Segment Closed v n -> v n) -> Segment Closed v n -> v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Segment Closed v n -> v n
forall t. EndValues (Tangent t) => t -> Vn t
tangentAtEnd (Segment Closed v n -> v n) -> Segment Closed v n -> v n
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 = (Point v n -> v n -> Point v n)
-> Point v n -> [v n] -> [Point v n]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl Point v n -> v n -> Point v n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
(.+^) Point v n
p ([v n] -> [Point v n])
-> ([Segment Closed v n] -> [v n])
-> [Segment Closed v n]
-> [Point v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Segment Closed v n -> v n) -> [Segment Closed v n] -> [v n]
forall a b. (a -> b) -> [a] -> [b]
map Segment Closed v n -> v n
forall (v :: * -> *) n. Segment Closed v n -> v n
segOffset ([Segment Closed v n] -> [Point v n])
-> [Segment Closed v n] -> [Point v n]
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 = v n -> n
forall (f :: * -> *) a. (Metric f, Num a) => f a -> a
quadrance ((v n, v n) -> v n
forall a b. (a, b) -> b
snd (v n, v n)
p2 v n -> v n -> v n
forall (f :: * -> *) a. (Additive f, Num a) => f a -> f a -> f a
^-^ (v n, v n) -> v n
forall a b. (a, b) -> a
fst (v n, v n)
q2) n -> n -> Bool
forall a. Ord a => a -> a -> Bool
> n
toler
select :: [a] -> [Bool] -> [a]
select :: [a] -> [Bool] -> [a]
select [a]
xs [Bool]
bs = ((a, Bool) -> a) -> [(a, Bool)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a, Bool) -> a
forall a b. (a, b) -> a
fst ([(a, Bool)] -> [a]) -> [(a, Bool)] -> [a]
forall a b. (a -> b) -> a -> b
$ ((a, Bool) -> Bool) -> [(a, Bool)] -> [(a, Bool)]
forall a. (a -> Bool) -> [a] -> [a]
filter (a, Bool) -> Bool
forall a b. (a, b) -> b
snd ([a] -> [Bool] -> [(a, Bool)]
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 :: Located (Trail v n) -> [FixedSegment v n]
fixTrail Located (Trail v n)
t = (Located (Segment Closed v n) -> FixedSegment v n)
-> [Located (Segment Closed v n)] -> [FixedSegment v n]
forall a b. (a -> b) -> [a] -> [b]
map Located (Segment Closed v n) -> FixedSegment v n
forall n (v :: * -> *).
(Num n, Additive v) =>
Located (Segment Closed v n) -> FixedSegment v n
mkFixedSeg (Located (Trail v n) -> [Located (Segment Closed v n)]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments Located (Trail v n)
t)
unfixTrail
:: (Metric v, Ord n, Floating n)
=> [FixedSegment v n] -> Located (Trail v n)
unfixTrail :: [FixedSegment v n] -> Located (Trail v n)
unfixTrail = ([Segment Closed v n] -> Trail v n)
-> Located [Segment Closed v n] -> Located (Trail v n)
forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc [Segment Closed v n] -> Trail v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
[Segment Closed v n] -> Trail v n
trailFromSegments (Located [Segment Closed v n] -> Located (Trail v n))
-> ([FixedSegment v n] -> Located [Segment Closed v n])
-> [FixedSegment v n]
-> Located (Trail v n)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Located (Segment Closed v n)] -> Located [Segment Closed v n]
forall a. (Additive (V a), Num (N a)) => [Located a] -> Located [a]
takeLoc ([Located (Segment Closed v n)] -> Located [Segment Closed v n])
-> ([FixedSegment v n] -> [Located (Segment Closed v n)])
-> [FixedSegment v n]
-> Located [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FixedSegment v n -> Located (Segment Closed v n))
-> [FixedSegment v n] -> [Located (Segment Closed v n)]
forall a b. (a -> b) -> [a] -> [b]
map FixedSegment v n -> Located (Segment Closed v n)
forall n (v :: * -> *).
(Num n, Additive v) =>
FixedSegment v n -> Located (Segment Closed v n)
fromFixedSeg
where
takeLoc :: [Located a] -> Located [a]
takeLoc [] = [] [a] -> Point (V [a]) (N [a]) -> Located [a]
forall a. a -> Point (V a) (N a) -> Located a
`at` Point (V [a]) (N [a])
forall (f :: * -> *) a. (Additive f, Num a) => Point f a
origin
takeLoc xs :: [Located a]
xs@(Located a
x:[Located a]
_) = (Located a -> a) -> [Located a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Located a -> a
forall a. Located a -> a
unLoc [Located a]
xs [a] -> Point (V [a]) (N [a]) -> Located [a]
forall a. a -> Point (V a) (N a) -> Located a
`at` Located a -> Point (V a) (N a)
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 :: Located (Trail v n) -> [Located (Segment Closed v n)]
trailLocSegments Located (Trail v n)
t = (Segment Closed v n -> Point v n -> Located (Segment Closed v n))
-> [Segment Closed v n]
-> [Point v n]
-> [Located (Segment Closed v n)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Segment Closed v n -> Point v n -> Located (Segment Closed v n)
forall a. a -> Point (V a) (N a) -> Located a
at (Trail v n -> [Segment Closed v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> [Segment Closed v n]
trailSegments (Located (Trail v n) -> Trail v n
forall a. Located a -> a
unLoc Located (Trail v n)
t)) (Located (Trail v n) -> [Point v n]
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> [Point v n]
trailPoints Located (Trail v n)
t)
reverseTrail :: (Metric v, OrderedField n) => Trail v n -> Trail v n
reverseTrail :: Trail v n -> Trail v n
reverseTrail = (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Loop v n) -> Trail v n -> Trail v n
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
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine Trail' Loop v n -> Trail' Loop v n
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 :: Located (Trail v n) -> Located (Trail v n)
reverseLocTrail (Located (Trail v n)
-> (Point (V (Trail v n)) (N (Trail v n)), Trail v n)
forall a. Located a -> (Point (V a) (N a), a)
viewLoc -> (Point (V (Trail v n)) (N (Trail v n))
p, Trail v n
t)) = Trail v n -> Trail v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail v n -> Trail v n
reverseTrail Trail v n
t Trail v n
-> Point (V (Trail v n)) (N (Trail v n)) -> Located (Trail v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` (Point v n
Point (V (Trail v n)) (N (Trail v n))
p Point v n -> Diff (Point v) n -> Point v n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Trail v n -> v n
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 :: Trail' Line v n -> Trail' Line v n
reverseLine = ([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line 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 ([Segment Closed v n] -> [Segment Closed v n]
forall a. [a] -> [a]
reverse ([Segment Closed v n] -> [Segment Closed v n])
-> ([Segment Closed v n] -> [Segment Closed v n])
-> [Segment Closed v n]
-> [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Segment Closed v n -> Segment Closed v n)
-> [Segment Closed v n] -> [Segment Closed v n]
forall a b. (a -> b) -> [a] -> [b]
map Segment Closed v n -> Segment Closed v n
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 :: Located (Trail' Line v n) -> Located (Trail' Line v n)
reverseLocLine (Located (Trail' Line v n)
-> (Point (V (Trail' Line v n)) (N (Trail' Line v n)),
Trail' Line v n)
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)) = Trail' Line v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine Trail' Line v n
l Trail' Line v n
-> Point (V (Trail' Line v n)) (N (Trail' Line v n))
-> Located (Trail' Line v n)
forall a. a -> Point (V a) (N a) -> Located a
`at` (Point v n
Point (V (Trail' Line v n)) (N (Trail' Line v n))
p Point v n -> Diff (Point v) n -> Point v n
forall (p :: * -> *) a. (Affine p, Num a) => p a -> Diff p a -> p a
.+^ Trail' Line v n -> v n
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 :: Trail' Loop v n -> Trail' Loop v n
reverseLoop = Trail' Line v n -> Trail' Loop v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine (Trail' Line v n -> Trail' Loop v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Loop v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Line v n
reverseLine (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
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 :: Located (Trail' Loop v n) -> Located (Trail' Loop v n)
reverseLocLoop = (Trail' Loop v n -> Trail' Loop v n)
-> Located (Trail' Loop v n) -> Located (Trail' Loop v n)
forall a b. SameSpace a b => (a -> b) -> Located a -> Located b
mapLoc Trail' Loop v n -> Trail' Loop v n
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
_) = ([Segment Closed v n] -> [Segment Closed v n])
-> Trail' Line v n -> Trail' Line 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 ([Segment Closed v n] -> [Segment Closed v n]
forall a. [a] -> [a]
reverse ([Segment Closed v n] -> [Segment Closed v n])
-> ([Segment Closed v n] -> [Segment Closed v n])
-> [Segment Closed v n]
-> [Segment Closed v n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Segment Closed v n -> Segment Closed v n)
-> [Segment Closed v n] -> [Segment Closed v n]
forall a b. (a -> b) -> [a] -> [b]
map Segment Closed v n -> Segment Closed v n
forall t. Reversing t => t -> t
reversing) Trail' l v n
Trail' Line v n
t
reversing t :: Trail' l v n
t@(Loop SegTree v n
_ Segment Open v n
_) = Trail' Line v n -> Trail' Loop v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Line v n -> Trail' Loop v n
glueLine (Trail' Line v n -> Trail' Loop v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Loop v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Line v n -> Trail' Line v n
forall t. Reversing t => t -> t
reversing (Trail' Line v n -> Trail' Line v n)
-> (Trail' Loop v n -> Trail' Line v n)
-> Trail' Loop v n
-> Trail' Line v n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Trail' Loop v n -> Trail' Line v n
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Trail' Loop v n -> Trail' Line v n
cutLoop (Trail' Loop v n -> Trail' Loop v n)
-> Trail' Loop v n -> Trail' Loop v n
forall a b. (a -> b) -> a -> b
$ Trail' l v n
Trail' Loop 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) = Trail' l v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (Trail' l v n -> Trail' l v n
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 {}) = Located (Trail' Line v n) -> Located (Trail' Line v n)
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Line v n) -> Located (Trail' Line v n)
reverseLocLine Located (Trail' l v n)
Located (Trail' Line v n)
l
reversing l :: Located (Trail' l v n)
l@(Loc Point (V (Trail' l v n)) (N (Trail' l v n))
_ Loop {}) = Located (Trail' Loop v n) -> Located (Trail' Loop v n)
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail' Loop v n) -> Located (Trail' Loop v n)
reverseLocLoop Located (Trail' l v n)
Located (Trail' Loop v n)
l
instance (Metric v, OrderedField n) => Reversing (Located (Trail v n)) where
reversing :: Located (Trail v n) -> Located (Trail v n)
reversing = Located (Trail v n) -> Located (Trail v n)
forall (v :: * -> *) n.
(Metric v, OrderedField n) =>
Located (Trail v n) -> Located (Trail v n)
reverseLocTrail
instance (Serialize (v n), OrderedField n, Metric v) => Serialize (Trail v n) where
{-# INLINE get #-}
get :: Get (Trail v n)
get = do
Bool
isLine <- Get Bool
forall t. Serialize t => Get t
Serialize.get
case Bool
isLine of
Bool
True -> do
SegTree v n
segTree <- Get (SegTree v n)
forall t. Serialize t => Get t
Serialize.get
Trail v n -> Get (Trail v n)
forall (m :: * -> *) a. Monad m => a -> m a
return (Trail' Line v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (SegTree v n -> Trail' Line v n
forall (v :: * -> *) n. SegTree v n -> Trail' Line v n
Line SegTree v n
segTree))
Bool
False -> do
SegTree v n
segTree <- Get (SegTree v n)
forall t. Serialize t => Get t
Serialize.get
Segment Open v n
segment <- Get (Segment Open v n)
forall t. Serialize t => Get t
Serialize.get
Trail v n -> Get (Trail v n)
forall (m :: * -> *) a. Monad m => a -> m a
return (Trail' Loop v n -> Trail v n
forall l (v :: * -> *) n. Trail' l v n -> Trail v n
Trail (SegTree v n -> Segment Open v n -> Trail' Loop v n
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
Putter Bool
forall t. Serialize t => Putter t
Serialize.put Bool
True
Putter (SegTree v n)
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
Putter Bool
forall t. Serialize t => Putter t
Serialize.put Bool
False
Putter (SegTree v n)
forall t. Serialize t => Putter t
Serialize.put SegTree v n
segTree
Putter (Segment Open v n)
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) = Putter [Segment Closed v n]
forall t. Serialize t => Putter t
Serialize.put (FingerTree (SegMeasure v n) (Segment Closed v n)
-> [Segment Closed v n]
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 <- Get [Segment Closed v n]
forall t. Serialize t => Get t
Serialize.get
SegTree v n -> Get (SegTree v n)
forall (m :: * -> *) a. Monad m => a -> m a
return (FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
forall (v :: * -> *) n.
FingerTree (SegMeasure v n) (Segment Closed v n) -> SegTree v n
SegTree ([Segment Closed v n]
-> FingerTree (SegMeasure v n) (Segment Closed v n)
forall v a. Measured v a => [a] -> FingerTree v a
FT.fromList [Segment Closed v n]
fingerTree))