{-# LANGUAGE CApiFFI #-}
module OpenCascade.BRepPrimAPI.MakeSphere
( fromRadius
, fromPntAndRadius
) where

import qualified OpenCascade.GP as GP
import qualified OpenCascade.TopoDS as TopoDS
import qualified OpenCascade.TopoDS.Internal.Destructors as TopoDS.Destructors
import Foreign.C
import Foreign.Ptr
import Data.Acquire 
import Data.Coerce (coerce)

foreign import capi unsafe "hs_BRepPrimAPI_MakeSphere.h hs_BRepPrimAPI_MakeSphere_fromRadius" rawFromRadius :: CDouble -> IO (Ptr TopoDS.Solid)

fromRadius :: Double -> Acquire (Ptr TopoDS.Solid)
fromRadius :: Double -> Acquire (Ptr Solid)
fromRadius Double
r = IO (Ptr Solid) -> (Ptr Solid -> IO ()) -> Acquire (Ptr Solid)
forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire (CDouble -> IO (Ptr Solid)
rawFromRadius (Double -> CDouble
forall a b. Coercible a b => a -> b
coerce Double
r)) (Ptr Shape -> IO ()
TopoDS.Destructors.deleteShape (Ptr Shape -> IO ())
-> (Ptr Solid -> Ptr Shape) -> Ptr Solid -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr Solid -> Ptr Shape
forall a b. Ptr a -> Ptr b
castPtr)

foreign import capi unsafe "hs_BRepPrimAPI_MakeSphere.h hs_BRepPrimAPI_MakeSphere_fromPntAndRadius" rawFromPntAndRadius :: Ptr GP.Pnt -> CDouble -> IO (Ptr TopoDS.Solid)

fromPntAndRadius :: Ptr GP.Pnt -> Double -> Acquire (Ptr TopoDS.Solid)
fromPntAndRadius :: Ptr Pnt -> Double -> Acquire (Ptr Solid)
fromPntAndRadius Ptr Pnt
center Double
radius = IO (Ptr Solid) -> (Ptr Solid -> IO ()) -> Acquire (Ptr Solid)
forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire (Ptr Pnt -> CDouble -> IO (Ptr Solid)
rawFromPntAndRadius Ptr Pnt
center (Double -> CDouble
forall a b. Coercible a b => a -> b
coerce Double
radius)) (Ptr Shape -> IO ()
TopoDS.Destructors.deleteShape (Ptr Shape -> IO ())
-> (Ptr Solid -> Ptr Shape) -> Ptr Solid -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr Solid -> Ptr Shape
forall a b. Ptr a -> Ptr b
castPtr)