{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UnicodeSyntax #-}
--------------------------------------------------------------------------------
-- |
-- Module      :  Data.Geometry.Line
-- Copyright   :  (C) Frank Staals
-- License     :  see the LICENSE file
-- Maintainer  :  Frank Staals
--
-- \(d\)-dimensional lines.
--
--------------------------------------------------------------------------------
module Data.Geometry.Line( module Data.Geometry.Line.Internal
                         ) where

import           Control.Lens
import           Data.Ext
import           Data.Geometry.Boundary
import           Data.Geometry.Box
import           Data.Geometry.Line.Internal
import           Data.Geometry.LineSegment
import           Data.Geometry.Point
import           Data.Geometry.Properties
import           Data.Geometry.SubLine
import           Data.Geometry.Transformation
import           Data.Geometry.Vector
import qualified Data.List as L
import           Data.Maybe (mapMaybe)
import           Data.Proxy
import           Data.UnBounded
import           Data.Vinyl.CoRec
import           Data.Vinyl.Core
import           Data.Vinyl.Lens
import           GHC.TypeLits

--------------------------------------------------------------------------------


-- | Lines are transformable, via line segments
instance (Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Line d r) where
  transformBy :: Transformation (Dimension (Line d r)) (NumType (Line d r))
-> Line d r -> Line d r
transformBy Transformation (Dimension (Line d r)) (NumType (Line d r))
t = LineSegment d () r -> Line d r
forall t.
HasSupportingLine t =>
t -> Line (Dimension t) (NumType t)
supportingLine (LineSegment d () r -> Line d r)
-> (Line d r -> LineSegment d () r) -> Line d r -> Line d r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transformation d r -> LineSegment d () r -> LineSegment d () r
forall (g :: * -> *) r (d :: Nat).
(PointFunctor g, Fractional r, d ~ Dimension (g r), Arity d,
 Arity (d + 1)) =>
Transformation d r -> g r -> g r
transformPointFunctor Transformation d r
Transformation (Dimension (Line d r)) (NumType (Line d r))
t (LineSegment d () r -> LineSegment d () r)
-> (Line d r -> LineSegment d () r)
-> Line d r
-> LineSegment d () r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Num r, Arity d) => Line d r -> LineSegment d () r
Line d r -> LineSegment d () r
toLineSegment'
    where
      toLineSegment' :: (Num r, Arity d) => Line d r -> LineSegment d () r
      toLineSegment' :: Line d r -> LineSegment d () r
toLineSegment' = Line d r -> LineSegment d () r
forall p r (d :: Nat).
(Monoid p, Num r, Arity d) =>
Line d r -> LineSegment d p r
toLineSegment

type instance IntersectionOf (Point d r) (Line d r) = [NoIntersection, Point d r]


instance (Eq r, Fractional r, Arity d) => Point d r `IsIntersectableWith` Line d r where
  nonEmptyIntersection :: proxy (Point d r)
-> proxy (Line d r) -> Intersection (Point d r) (Line d r) -> Bool
nonEmptyIntersection = proxy (Point d r)
-> proxy (Line d r) -> Intersection (Point d r) (Line d r) -> Bool
forall g h (proxy :: * -> *).
(NoIntersection ∈ IntersectionOf g h,
 RecApplicative (IntersectionOf g h)) =>
proxy g -> proxy h -> Intersection g h -> Bool
defaultNonEmptyIntersection
  intersects :: Point d r -> Line d r -> Bool
intersects = Point d r -> Line d r -> Bool
forall r (d :: Nat).
(Eq r, Fractional r, Arity d) =>
Point d r -> Line d r -> Bool
onLine
  Point d r
p intersect :: Point d r -> Line d r -> Intersection (Point d r) (Line d r)
`intersect` Line d r
l | Point d r
p Point d r -> Line d r -> Bool
forall g h. IsIntersectableWith g h => g -> h -> Bool
`intersects` Line d r
l = Point d r -> CoRec Identity '[NoIntersection, Point d r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec Point d r
p
                  | Bool
otherwise        = NoIntersection -> CoRec Identity '[NoIntersection, Point d r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec NoIntersection
NoIntersection

instance {-# OVERLAPPING #-} (Ord r, Num r)
        => Point 2 r `IsIntersectableWith` Line 2 r where
  nonEmptyIntersection :: proxy (Point 2 r)
-> proxy (Line 2 r) -> Intersection (Point 2 r) (Line 2 r) -> Bool
nonEmptyIntersection = proxy (Point 2 r)
-> proxy (Line 2 r) -> Intersection (Point 2 r) (Line 2 r) -> Bool
forall g h (proxy :: * -> *).
(NoIntersection ∈ IntersectionOf g h,
 RecApplicative (IntersectionOf g h)) =>
proxy g -> proxy h -> Intersection g h -> Bool
defaultNonEmptyIntersection
  intersects :: Point 2 r -> Line 2 r -> Bool
intersects = Point 2 r -> Line 2 r -> Bool
forall r. (Ord r, Num r) => Point 2 r -> Line 2 r -> Bool
onLine2
  Point 2 r
p intersect :: Point 2 r -> Line 2 r -> Intersection (Point 2 r) (Line 2 r)
`intersect` Line 2 r
l | Point 2 r
p Point 2 r -> Line 2 r -> Bool
forall g h. IsIntersectableWith g h => g -> h -> Bool
`intersects` Line 2 r
l = Point 2 r -> CoRec Identity '[NoIntersection, Point 2 r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec Point 2 r
p
                  | Bool
otherwise        = NoIntersection -> CoRec Identity '[NoIntersection, Point 2 r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec NoIntersection
NoIntersection


type instance IntersectionOf (Line 2 r) (Boundary (Rectangle p r)) =
  [ NoIntersection, Point 2 r, (Point 2 r, Point 2 r) , LineSegment 2 () r]


instance (Ord r, Fractional r)
         => Line 2 r `IsIntersectableWith` Boundary (Rectangle p r) where
  nonEmptyIntersection :: proxy (Line 2 r)
-> proxy (Boundary (Rectangle p r))
-> Intersection (Line 2 r) (Boundary (Rectangle p r))
-> Bool
nonEmptyIntersection = proxy (Line 2 r)
-> proxy (Boundary (Rectangle p r))
-> Intersection (Line 2 r) (Boundary (Rectangle p r))
-> Bool
forall g h (proxy :: * -> *).
(NoIntersection ∈ IntersectionOf g h,
 RecApplicative (IntersectionOf g h)) =>
proxy g -> proxy h -> Intersection g h -> Bool
defaultNonEmptyIntersection

  Line 2 r
line' intersect :: Line 2 r
-> Boundary (Rectangle p r)
-> Intersection (Line 2 r) (Boundary (Rectangle p r))
`intersect` (Boundary Rectangle p r
rect)  = case Proxy (SubLine 2 () (UnBounded r) r)
-> [SubLine 2 () (UnBounded r) r]
forall (proxy :: * -> *) t.
(t
 ∈ IntersectionOf
     (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r)) =>
proxy t -> [t]
asAP Proxy (SubLine 2 () (UnBounded r) r)
segP of
      [SubLine 2 () (UnBounded r) r
sl'] -> case SubLine 2 () (UnBounded r) r -> Maybe (SubLine 2 () r r)
forall (d :: Nat) p r.
SubLine d p (UnBounded r) r -> Maybe (SubLine d p r r)
fromUnbounded SubLine 2 () (UnBounded r) r
sl' of
        Maybe (SubLine 2 () r r)
Nothing   -> [Char]
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a. HasCallStack => [Char] -> a
error [Char]
"intersect: line x boundary rect; unbounded line? absurd"
        Just SubLine 2 () r r
sl'' -> LineSegment 2 () r
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec (LineSegment 2 () r
 -> CoRec
      Identity
      '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
        LineSegment 2 () r])
-> LineSegment 2 () r
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a b. (a -> b) -> a -> b
$ SubLine 2 () r r
sl''SubLine 2 () r r
-> Getting
     (LineSegment 2 () r) (SubLine 2 () r r) (LineSegment 2 () r)
-> LineSegment 2 () r
forall s a. s -> Getting a s a -> a
^.AReview (LineSegment 2 () r) (SubLine 2 () r r)
-> Getter (SubLine 2 () r r) (LineSegment 2 () r)
forall t b. AReview t b -> Getter b t
re AReview (LineSegment 2 () r) (SubLine 2 () r r)
forall r (d :: Nat) p.
(Num r, Arity d) =>
Iso' (LineSegment d p r) (SubLine d p r r)
_SubLine
      []    -> case [Point 2 r] -> [Point 2 r]
nub' ([Point 2 r] -> [Point 2 r]) -> [Point 2 r] -> [Point 2 r]
forall a b. (a -> b) -> a -> b
$ Proxy (Point 2 r) -> [Point 2 r]
forall (proxy :: * -> *) t.
(t
 ∈ IntersectionOf
     (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r)) =>
proxy t -> [t]
asAP Proxy (Point 2 r)
pointP of
        [Point 2 r
p]   -> Point 2 r
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec Point 2 r
p
        [Point 2 r
p,Point 2 r
q] -> (Point 2 r, Point 2 r)
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec (Point 2 r
p,Point 2 r
q)
        [Point 2 r]
_     -> NoIntersection
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec NoIntersection
NoIntersection
      [SubLine 2 () (UnBounded r) r]
_     -> [Char]
-> CoRec
     Identity
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
forall a. HasCallStack => [Char] -> a
error [Char]
"intersect; line x boundary rect; absurd"
    where
      Sides LineSegment 2 p r
t LineSegment 2 p r
r LineSegment 2 p r
b LineSegment 2 p r
l = Rectangle p r -> Sides (LineSegment 2 p r)
forall r p. Num r => Rectangle p r -> Sides (LineSegment 2 p r)
sides' Rectangle p r
rect
      ints :: [CoRec
   Identity
   '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r]]
ints = (LineSegment 2 p r
 -> CoRec
      Identity
      '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r])
-> [LineSegment 2 p r]
-> [CoRec
      Identity
      '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r]]
forall a b. (a -> b) -> [a] -> [b]
map (\LineSegment 2 p r
s -> SubLine 2 () (UnBounded r) r
sl SubLine 2 () (UnBounded r) r
-> SubLine 2 () (UnBounded r) r
-> Intersection
     (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r)
forall g h. IsIntersectableWith g h => g -> h -> Intersection g h
`intersect` LineSegment 2 p r -> SubLine 2 () (UnBounded r) r
toSL LineSegment 2 p r
s) [LineSegment 2 p r
t,LineSegment 2 p r
r,LineSegment 2 p r
b,LineSegment 2 p r
l]

      nub' :: [Point 2 r] -> [Point 2 r]
nub' = ([Point 2 r] -> Point 2 r) -> [[Point 2 r]] -> [Point 2 r]
forall a b. (a -> b) -> [a] -> [b]
map [Point 2 r] -> Point 2 r
forall a. [a] -> a
L.head ([[Point 2 r]] -> [Point 2 r])
-> ([Point 2 r] -> [[Point 2 r]]) -> [Point 2 r] -> [Point 2 r]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Point 2 r] -> [[Point 2 r]]
forall a. Eq a => [a] -> [[a]]
L.group ([Point 2 r] -> [[Point 2 r]])
-> ([Point 2 r] -> [Point 2 r]) -> [Point 2 r] -> [[Point 2 r]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Point 2 r] -> [Point 2 r]
forall a. Ord a => [a] -> [a]
L.sort

      sl :: SubLine 2 () (UnBounded r) r
sl = Line 2 r -> SubLine 2 () (UnBounded r) r
forall (d :: Nat) r.
Arity d =>
Line d r -> SubLine d () (UnBounded r) r
fromLine Line 2 r
line'
      -- wrap a segment into an potentially unbounded subline
      toSL  :: LineSegment 2 p r -> SubLine 2 () (UnBounded r) r
      toSL :: LineSegment 2 p r -> SubLine 2 () (UnBounded r) r
toSL LineSegment 2 p r
s = LineSegment 2 p r
sLineSegment 2 p r
-> Getting
     (SubLine 2 () (UnBounded r) r)
     (LineSegment 2 p r)
     (SubLine 2 () (UnBounded r) r)
-> SubLine 2 () (UnBounded r) r
forall s a. s -> Getting a s a -> a
^.(SubLine 2 p r r
 -> Const (SubLine 2 () (UnBounded r) r) (SubLine 2 p r r))
-> LineSegment 2 p r
-> Const (SubLine 2 () (UnBounded r) r) (LineSegment 2 p r)
forall r (d :: Nat) p.
(Num r, Arity d) =>
Iso' (LineSegment d p r) (SubLine d p r r)
_SubLine((SubLine 2 p r r
  -> Const (SubLine 2 () (UnBounded r) r) (SubLine 2 p r r))
 -> LineSegment 2 p r
 -> Const (SubLine 2 () (UnBounded r) r) (LineSegment 2 p r))
-> ((SubLine 2 () (UnBounded r) r
     -> Const
          (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r))
    -> SubLine 2 p r r
    -> Const (SubLine 2 () (UnBounded r) r) (SubLine 2 p r r))
-> Getting
     (SubLine 2 () (UnBounded r) r)
     (LineSegment 2 p r)
     (SubLine 2 () (UnBounded r) r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.AReview (SubLine 2 p (UnBounded r) r) (SubLine 2 p r r)
-> Getter (SubLine 2 p r r) (SubLine 2 p (UnBounded r) r)
forall t b. AReview t b -> Getter b t
re AReview (SubLine 2 p (UnBounded r) r) (SubLine 2 p r r)
forall (d :: Nat) p r.
Prism' (SubLine d p (UnBounded r) r) (SubLine d p r r)
_unBounded((SubLine 2 p (UnBounded r) r
  -> Const
       (SubLine 2 () (UnBounded r) r) (SubLine 2 p (UnBounded r) r))
 -> SubLine 2 p r r
 -> Const (SubLine 2 () (UnBounded r) r) (SubLine 2 p r r))
-> ((SubLine 2 () (UnBounded r) r
     -> Const
          (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r))
    -> SubLine 2 p (UnBounded r) r
    -> Const
         (SubLine 2 () (UnBounded r) r) (SubLine 2 p (UnBounded r) r))
-> (SubLine 2 () (UnBounded r) r
    -> Const
         (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r))
-> SubLine 2 p r r
-> Const (SubLine 2 () (UnBounded r) r) (SubLine 2 p r r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(SubLine 2 p (UnBounded r) r -> SubLine 2 () (UnBounded r) r)
-> (SubLine 2 () (UnBounded r) r
    -> Const
         (SubLine 2 () (UnBounded r) r) (SubLine 2 () (UnBounded r) r))
-> SubLine 2 p (UnBounded r) r
-> Const
     (SubLine 2 () (UnBounded r) r) (SubLine 2 p (UnBounded r) r)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to SubLine 2 p (UnBounded r) r -> SubLine 2 () (UnBounded r) r
forall (d :: Nat) p s r. SubLine d p s r -> SubLine d () s r
dropExtra

      asAP  :: forall proxy t. (t  IntersectionOf (SubLine 2 () (UnBounded r) r)
                                                   (SubLine 2 () (UnBounded r) r))
             => proxy t -> [t]
      asAP :: proxy t -> [t]
asAP proxy t
_ = (CoRec
   Identity '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r]
 -> Maybe t)
-> [CoRec
      Identity
      '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r]]
-> [t]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (forall (ts :: [*]).
NatToInt (RIndex t ts) =>
CoRec Identity ts -> Maybe t
forall t (ts :: [*]).
NatToInt (RIndex t ts) =>
CoRec Identity ts -> Maybe t
asA @t) [CoRec
   Identity
   '[NoIntersection, Point 2 r, SubLine 2 () (UnBounded r) r]]
ints

      segP :: Proxy (SubLine 2 () (UnBounded r) r)
segP   = Proxy (SubLine 2 () (UnBounded r) r)
forall k (t :: k). Proxy t
Proxy :: Proxy (SubLine 2 () (UnBounded r) r)
      pointP :: Proxy (Point 2 r)
pointP = Proxy (Point 2 r)
forall k (t :: k). Proxy t
Proxy :: Proxy (Point 2 r)


type instance IntersectionOf (Line 2 r) (Rectangle p r) =
  [ NoIntersection, Point 2 r, LineSegment 2 () r]


instance (Ord r, Fractional r)
         => Line 2 r `IsIntersectableWith` Rectangle p r where
  nonEmptyIntersection :: proxy (Line 2 r)
-> proxy (Rectangle p r)
-> Intersection (Line 2 r) (Rectangle p r)
-> Bool
nonEmptyIntersection = proxy (Line 2 r)
-> proxy (Rectangle p r)
-> Intersection (Line 2 r) (Rectangle p r)
-> Bool
forall g h (proxy :: * -> *).
(NoIntersection ∈ IntersectionOf g h,
 RecApplicative (IntersectionOf g h)) =>
proxy g -> proxy h -> Intersection g h -> Bool
defaultNonEmptyIntersection

  Line 2 r
line' intersect :: Line 2 r
-> Rectangle p r -> Intersection (Line 2 r) (Rectangle p r)
`intersect` Rectangle p r
rect  = CoRec
  Identity
  '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
    LineSegment 2 () r]
-> Handlers
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall (ts :: [*]) b. CoRec Identity ts -> Handlers ts b -> b
match (Line 2 r
line' Line 2 r
-> Boundary (Rectangle p r)
-> Intersection (Line 2 r) (Boundary (Rectangle p r))
forall g h. IsIntersectableWith g h => g -> h -> Intersection g h
`intersect` Rectangle p r -> Boundary (Rectangle p r)
forall g. g -> Boundary g
Boundary Rectangle p r
rect) (Handlers
   '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
     LineSegment 2 () r]
   (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> Handlers
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a b. (a -> b) -> a -> b
$
       (NoIntersection
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> Handler
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
     NoIntersection
forall b a. (a -> b) -> Handler b a
H NoIntersection
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec -- NoIntersection
    Handler
  (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
  NoIntersection
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[Point 2 r, (Point 2 r, Point 2 r), LineSegment 2 () r]
-> Handlers
     '[NoIntersection, Point 2 r, (Point 2 r, Point 2 r),
       LineSegment 2 () r]
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (Point 2 r
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> Handler
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
     (Point 2 r)
forall b a. (a -> b) -> Handler b a
H Point 2 r
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec -- Point2
    Handler
  (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
  (Point 2 r)
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[(Point 2 r, Point 2 r), LineSegment 2 () r]
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[Point 2 r, (Point 2 r, Point 2 r), LineSegment 2 () r]
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& ((Point 2 r, Point 2 r)
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> Handler
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
     (Point 2 r, Point 2 r)
forall b a. (a -> b) -> Handler b a
H (\(Point 2 r
p,Point 2 r
q)          -> LineSegment 2 () r
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec (LineSegment 2 () r
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> LineSegment 2 () r
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a b. (a -> b) -> a -> b
$ (Point 2 r :+ ()) -> (Point 2 r :+ ()) -> LineSegment 2 () r
forall (d :: Nat) r p.
(Point d r :+ p) -> (Point d r :+ p) -> LineSegment d p r
ClosedLineSegment (Point 2 r -> Point 2 r :+ ()
forall a. a -> a :+ ()
ext Point 2 r
p) (Point 2 r -> Point 2 r :+ ()
forall a. a -> a :+ ()
ext Point 2 r
q))
    Handler
  (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
  (Point 2 r, Point 2 r)
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[LineSegment 2 () r]
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[(Point 2 r, Point 2 r), LineSegment 2 () r]
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (LineSegment 2 () r
 -> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
-> Handler
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
     (LineSegment 2 () r)
forall b a. (a -> b) -> Handler b a
H LineSegment 2 () r
-> CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]
forall a (as :: [*]). (a ∈ as) => a -> CoRec Identity as
coRec -- LineSegment
    Handler
  (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r])
  (LineSegment 2 () r)
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[]
-> Rec
     (Handler
        (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
     '[LineSegment 2 () r]
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& Rec
  (Handler
     (CoRec Identity '[NoIntersection, Point 2 r, LineSegment 2 () r]))
  '[]
forall u (a :: u -> *). Rec a '[]
RNil