{-# LANGUAGE DerivingVia #-}
{-# OPTIONS_HADDOCK not-home #-}
module Waterfall.Internal.Path
( Path (..)
, allPathEndpoints
) where

import Waterfall.Internal.Finalizers (toAcquire, unsafeFromAcquire) 
import Control.Monad.IO.Class (liftIO)
import Linear (V3 (..))
import Waterfall.Internal.Path.Common (RawPath (..))
import Waterfall.Internal.Edges (allWireEndpoints)
-- | A Path in 3D Space 
--
-- Under the hood, this is represented by an OpenCascade `TopoDS.Wire`.
--
-- The monoid instance  Joins `Path`s, @ a <> b @ connects the end point of @ a @ to the start of @ b @, if these points are not coincident, a line is created between them.
--
newtype Path = Path { Path -> RawPath
rawPath :: RawPath } deriving (NonEmpty Path -> Path
Path -> Path -> Path
(Path -> Path -> Path)
-> (NonEmpty Path -> Path)
-> (forall b. Integral b => b -> Path -> Path)
-> Semigroup Path
forall b. Integral b => b -> Path -> Path
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: Path -> Path -> Path
<> :: Path -> Path -> Path
$csconcat :: NonEmpty Path -> Path
sconcat :: NonEmpty Path -> Path
$cstimes :: forall b. Integral b => b -> Path -> Path
stimes :: forall b. Integral b => b -> Path -> Path
Semigroup, Semigroup Path
Path
Semigroup Path =>
Path -> (Path -> Path -> Path) -> ([Path] -> Path) -> Monoid Path
[Path] -> Path
Path -> Path -> Path
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: Path
mempty :: Path
$cmappend :: Path -> Path -> Path
mappend :: Path -> Path -> Path
$cmconcat :: [Path] -> Path
mconcat :: [Path] -> Path
Monoid) via RawPath

-- | Exposing this because I found it useful for debugging
allPathEndpoints :: Path -> [(V3 Double, V3 Double)]
allPathEndpoints :: Path -> [(V3 Double, V3 Double)]
allPathEndpoints (Path (ComplexRawPath Ptr Wire
raw)) = Acquire [(V3 Double, V3 Double)] -> [(V3 Double, V3 Double)]
forall a. Acquire a -> a
unsafeFromAcquire (Acquire [(V3 Double, V3 Double)] -> [(V3 Double, V3 Double)])
-> Acquire [(V3 Double, V3 Double)] -> [(V3 Double, V3 Double)]
forall a b. (a -> b) -> a -> b
$ do
    Ptr Wire
wire <- Ptr Wire -> Acquire (Ptr Wire)
forall a. a -> Acquire a
toAcquire Ptr Wire
raw
    IO [(V3 Double, V3 Double)] -> Acquire [(V3 Double, V3 Double)]
forall a. IO a -> Acquire a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [(V3 Double, V3 Double)] -> Acquire [(V3 Double, V3 Double)])
-> IO [(V3 Double, V3 Double)] -> Acquire [(V3 Double, V3 Double)]
forall a b. (a -> b) -> a -> b
$ Ptr Wire -> IO [(V3 Double, V3 Double)]
allWireEndpoints Ptr Wire
wire
allPathEndpoints (Path (SinglePointRawPath V3 Double
point)) = (V3 Double, V3 Double) -> [(V3 Double, V3 Double)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (V3 Double
point, V3 Double
point)
allPathEndpoints (Path RawPath
EmptyRawPath) = []