module Waterfall.TwoD.Shape
( Shape
, fromPath
) where

import Waterfall.TwoD.Internal.Shape (Shape (..))
import Waterfall.TwoD.Internal.Path2D (Path2D (..))
import qualified OpenCascade.BRepBuilderAPI.MakeFace as MakeFace
import OpenCascade.Inheritance (upcast)

-- | Construct a 2D Shape from a closed path 
fromPath :: Path2D -> Shape
fromPath :: Path2D -> Shape
fromPath (Path2D Acquire (Ptr Wire)
run)= Acquire (Ptr Shape) -> Shape
Shape (Acquire (Ptr Shape) -> Shape) -> Acquire (Ptr Shape) -> Shape
forall a b. (a -> b) -> a -> b
$ do
    Ptr Wire
p <- Acquire (Ptr Wire)
run
    Ptr Face -> Ptr Shape
forall a b. SubTypeOf a b => Ptr b -> Ptr a
upcast (Ptr Face -> Ptr Shape)
-> Acquire (Ptr Face) -> Acquire (Ptr Shape)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr MakeFace -> Acquire (Ptr Face)
MakeFace.face (Ptr MakeFace -> Acquire (Ptr Face))
-> Acquire (Ptr MakeFace) -> Acquire (Ptr Face)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Wire -> Bool -> Acquire (Ptr MakeFace)
MakeFace.fromWire Ptr Wire
p Bool
False)