-- Produced by boxnd-gen; edit the generator, not this file.

module Box3D.DynamicTree
  ( create
  , destroy
  , createProxy
  , destroyProxy
  , moveProxy
  , enlargeProxy
  , setCategoryBits
  , getCategoryBits
  , query
  , queryClosest
  , rayCast
  , boxCast
  , boxCastInto
  , validate
  , getHeight
  , getAreaRatio
  , getRootBounds
  , getRootBoundsInto
  , getProxyCount
  , rebuild
  , getByteCount
  , validateNoEnlarged
  , save
  , load
  )

  where

import Foreign
import Foreign.C.Types (CInt(..), CBool(..))
import Foreign.C.String (CString)
import Box3D.MathTypes (AABB, Vec3)
import Box3D.Tags (BoxCastInput, DynamicTree, TreeBoxCastCallbackFcn, TreeQueryCallbackFcn, TreeQueryClosestCallbackFcn, TreeRayCastCallbackFcn)
import Box3D.Types (RayCastInput, TreeStats)

foreign import ccall unsafe "hsg_b3DynamicTree_Create"
  c_b3DynamicTree_Create :: CInt -> Ptr DynamicTree -> IO ()

foreign import ccall unsafe "b3DynamicTree_Destroy"
  c_b3DynamicTree_Destroy :: Ptr DynamicTree -> IO ()

foreign import ccall unsafe "hsg_b3DynamicTree_CreateProxy"
  c_b3DynamicTree_CreateProxy :: Ptr DynamicTree -> Ptr AABB -> Word64 -> Word64 -> IO CInt

foreign import ccall unsafe "b3DynamicTree_DestroyProxy"
  c_b3DynamicTree_DestroyProxy :: Ptr DynamicTree -> CInt -> IO ()

foreign import ccall unsafe "hsg_b3DynamicTree_MoveProxy"
  c_b3DynamicTree_MoveProxy :: Ptr DynamicTree -> CInt -> Ptr AABB -> IO ()

foreign import ccall unsafe "hsg_b3DynamicTree_EnlargeProxy"
  c_b3DynamicTree_EnlargeProxy :: Ptr DynamicTree -> CInt -> Ptr AABB -> IO ()

foreign import ccall unsafe "b3DynamicTree_SetCategoryBits"
  c_b3DynamicTree_SetCategoryBits :: Ptr DynamicTree -> CInt -> Word64 -> IO ()

foreign import ccall unsafe "b3DynamicTree_GetCategoryBits"
  c_b3DynamicTree_GetCategoryBits :: Ptr DynamicTree -> CInt -> IO Word64

foreign import ccall safe "hsg_b3DynamicTree_Query"
  c_b3DynamicTree_Query :: Ptr DynamicTree -> Ptr AABB -> Word64 -> CBool -> FunPtr TreeQueryCallbackFcn -> Ptr () -> Ptr TreeStats -> IO ()

foreign import ccall safe "hsg_b3DynamicTree_QueryClosest"
  c_b3DynamicTree_QueryClosest :: Ptr DynamicTree -> Ptr Vec3 -> Word64 -> CBool -> FunPtr TreeQueryClosestCallbackFcn -> Ptr () -> Ptr Float -> Ptr TreeStats -> IO ()

foreign import ccall safe "hsg_b3DynamicTree_RayCast"
  c_b3DynamicTree_RayCast :: Ptr DynamicTree -> Ptr RayCastInput -> Word64 -> CBool -> FunPtr TreeRayCastCallbackFcn -> Ptr () -> Ptr TreeStats -> IO ()

foreign import ccall safe "hsg_b3DynamicTree_BoxCast"
  c_b3DynamicTree_BoxCast :: Ptr DynamicTree -> Ptr BoxCastInput -> Word64 -> CBool -> FunPtr TreeBoxCastCallbackFcn -> Ptr () -> Ptr TreeStats -> IO ()

foreign import ccall unsafe "b3DynamicTree_Validate"
  c_b3DynamicTree_Validate :: Ptr DynamicTree -> IO ()

foreign import ccall unsafe "b3DynamicTree_GetHeight"
  c_b3DynamicTree_GetHeight :: Ptr DynamicTree -> IO CInt

foreign import ccall unsafe "b3DynamicTree_GetAreaRatio"
  c_b3DynamicTree_GetAreaRatio :: Ptr DynamicTree -> IO Float

foreign import ccall unsafe "hsg_b3DynamicTree_GetRootBounds"
  c_b3DynamicTree_GetRootBounds :: Ptr DynamicTree -> Ptr AABB -> IO ()

foreign import ccall unsafe "b3DynamicTree_GetProxyCount"
  c_b3DynamicTree_GetProxyCount :: Ptr DynamicTree -> IO CInt

foreign import ccall unsafe "b3DynamicTree_Rebuild"
  c_b3DynamicTree_Rebuild :: Ptr DynamicTree -> CBool -> IO CInt

foreign import ccall unsafe "b3DynamicTree_GetByteCount"
  c_b3DynamicTree_GetByteCount :: Ptr DynamicTree -> IO CInt

foreign import ccall unsafe "b3DynamicTree_ValidateNoEnlarged"
  c_b3DynamicTree_ValidateNoEnlarged :: Ptr DynamicTree -> IO ()

foreign import ccall unsafe "b3DynamicTree_Save"
  c_b3DynamicTree_Save :: Ptr DynamicTree -> CString -> IO ()

foreign import ccall unsafe "hsg_b3DynamicTree_Load"
  c_b3DynamicTree_Load :: CString -> Float -> Ptr DynamicTree -> IO ()

{- | Constructing the tree initializes the node pool.

Binds @b3DynamicTree_Create@.
-}
create
  :: Int
  -- ^ @proxyCapacity@
  -> Ptr DynamicTree
  -- ^ Result buffer.
  -> IO ()
create :: Int -> Ptr DynamicTree -> IO ()
create Int
a0 Ptr DynamicTree
out =
  CInt -> Ptr DynamicTree -> IO ()
c_b3DynamicTree_Create (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a0) Ptr DynamicTree
out

{- | Destroy the tree, freeing the node pool.

Binds @b3DynamicTree_Destroy@.
-}
destroy
  :: Ptr DynamicTree
  -> IO ()
destroy :: Ptr DynamicTree -> IO ()
destroy Ptr DynamicTree
a0 =
  Ptr DynamicTree -> IO ()
c_b3DynamicTree_Destroy Ptr DynamicTree
a0

{- | Create a proxy. Provide an AABB and a userData value.

Binds @b3DynamicTree_CreateProxy@.
-}
createProxy
  :: Ptr DynamicTree
  -> AABB
  -> Word64
  -- ^ @categoryBits@
  -> Word64
  -- ^ @userData@
  -> IO Int
createProxy :: Ptr DynamicTree -> AABB -> Word64 -> Word64 -> IO Int
createProxy Ptr DynamicTree
a0 AABB
a1 Word64
a2 Word64
a3 =
  AABB -> (Ptr AABB -> IO Int) -> IO Int
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with AABB
a1 ((Ptr AABB -> IO Int) -> IO Int) -> (Ptr AABB -> IO Int) -> IO Int
forall a b. (a -> b) -> a -> b
$ \Ptr AABB
p1 ->
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr DynamicTree -> Ptr AABB -> Word64 -> Word64 -> IO CInt
c_b3DynamicTree_CreateProxy Ptr DynamicTree
a0 Ptr AABB
p1 Word64
a2 Word64
a3)

{- | Destroy a proxy. This asserts if the id is invalid.

Binds @b3DynamicTree_DestroyProxy@.
-}
destroyProxy
  :: Ptr DynamicTree
  -> Int
  -- ^ @proxyId@
  -> IO ()
destroyProxy :: Ptr DynamicTree -> Int -> IO ()
destroyProxy Ptr DynamicTree
a0 Int
a1 =
  Ptr DynamicTree -> CInt -> IO ()
c_b3DynamicTree_DestroyProxy Ptr DynamicTree
a0 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1)

{- | Move a proxy to a new AABB by removing and reinserting into the tree.

Binds @b3DynamicTree_MoveProxy@.
-}
moveProxy
  :: Ptr DynamicTree
  -> Int
  -- ^ @proxyId@
  -> AABB
  -> IO ()
moveProxy :: Ptr DynamicTree -> Int -> AABB -> IO ()
moveProxy Ptr DynamicTree
a0 Int
a1 AABB
a2 =
  AABB -> (Ptr AABB -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with AABB
a2 ((Ptr AABB -> IO ()) -> IO ()) -> (Ptr AABB -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr AABB
p2 ->
  Ptr DynamicTree -> CInt -> Ptr AABB -> IO ()
c_b3DynamicTree_MoveProxy Ptr DynamicTree
a0 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1) Ptr AABB
p2

{- | Enlarge a proxy and enlarge ancestors as necessary.

Binds @b3DynamicTree_EnlargeProxy@.
-}
enlargeProxy
  :: Ptr DynamicTree
  -> Int
  -- ^ @proxyId@
  -> AABB
  -> IO ()
enlargeProxy :: Ptr DynamicTree -> Int -> AABB -> IO ()
enlargeProxy Ptr DynamicTree
a0 Int
a1 AABB
a2 =
  AABB -> (Ptr AABB -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with AABB
a2 ((Ptr AABB -> IO ()) -> IO ()) -> (Ptr AABB -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr AABB
p2 ->
  Ptr DynamicTree -> CInt -> Ptr AABB -> IO ()
c_b3DynamicTree_EnlargeProxy Ptr DynamicTree
a0 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1) Ptr AABB
p2

{- | Modify the category bits on a proxy. This is an expensive operation.

Binds @b3DynamicTree_SetCategoryBits@.
-}
setCategoryBits
  :: Ptr DynamicTree
  -> Int
  -- ^ @proxyId@
  -> Word64
  -- ^ @categoryBits@
  -> IO ()
setCategoryBits :: Ptr DynamicTree -> Int -> Word64 -> IO ()
setCategoryBits Ptr DynamicTree
a0 Int
a1 Word64
a2 =
  Ptr DynamicTree -> CInt -> Word64 -> IO ()
c_b3DynamicTree_SetCategoryBits Ptr DynamicTree
a0 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1) Word64
a2

{- | Get the category bits on a proxy.

Binds @b3DynamicTree_GetCategoryBits@.
-}
getCategoryBits
  :: Ptr DynamicTree
  -> Int
  -- ^ @proxyId@
  -> IO Word64
getCategoryBits :: Ptr DynamicTree -> Int -> IO Word64
getCategoryBits Ptr DynamicTree
a0 Int
a1 =
  Ptr DynamicTree -> CInt -> IO Word64
c_b3DynamicTree_GetCategoryBits Ptr DynamicTree
a0 (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1)

{- | Query an AABB for overlapping proxies. The callback function is called for each proxy that overlaps the supplied AABB.

Returns: performance data

Binds @b3DynamicTree_Query@.
-}
query
  :: Ptr DynamicTree
  -> AABB
  -> Word64
  -- ^ @maskBits@
  -> Bool
  -- ^ @requireAllBits@
  -> FunPtr TreeQueryCallbackFcn
  -> Ptr ()
  -- ^ @context@
  -> IO TreeStats
query :: Ptr DynamicTree
-> AABB
-> Word64
-> Bool
-> FunPtr TreeQueryCallbackFcn
-> Ptr ()
-> IO TreeStats
query Ptr DynamicTree
a0 AABB
a1 Word64
a2 Bool
a3 FunPtr TreeQueryCallbackFcn
a4 Ptr ()
a5 =
  AABB -> (Ptr AABB -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with AABB
a1 ((Ptr AABB -> IO TreeStats) -> IO TreeStats)
-> (Ptr AABB -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr AABB
p1 ->
  (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr TreeStats -> IO TreeStats) -> IO TreeStats)
-> (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr TreeStats
pOut -> Ptr DynamicTree
-> Ptr AABB
-> Word64
-> CBool
-> FunPtr TreeQueryCallbackFcn
-> Ptr ()
-> Ptr TreeStats
-> IO ()
c_b3DynamicTree_Query Ptr DynamicTree
a0 Ptr AABB
p1 Word64
a2 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a3) FunPtr TreeQueryCallbackFcn
a4 Ptr ()
a5 Ptr TreeStats
pOut IO () -> IO TreeStats -> IO TreeStats
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr TreeStats -> IO TreeStats
forall a. Storable a => Ptr a -> IO a
peek Ptr TreeStats
pOut

{- | Query an AABB for the closest object. The callback function is called for each proxy that might be closest to the supplied point.

Returns: performance data

Binds @b3DynamicTree_QueryClosest@.
-}
queryClosest
  :: Ptr DynamicTree
  -- ^ @tree@: the dynamic tree to query
  -> Vec3
  -- ^ @point@: the query point
  -> Word64
  -- ^ @maskBits@: nodes are skipped if the bit-wise AND with the node category bits is zero
  -> Bool
  -- ^ @requireAllBits@: nodes are skipped if the bit-wise AND with the node category bits does not equal the maskBits
  -> FunPtr TreeQueryClosestCallbackFcn
  -- ^ @callback@: a user provided instance of b3TreeQueryClosestCallbackFcn
  -> Ptr ()
  -- ^ @context@: a user context object that is provided to the callback
  -> Ptr Float
  -- ^ @minDistanceSqr@: the initial and final minimum squared distance. Provide a small initial to restrict the search and improve performance. If the value is large this query has performance that scales linearly with the number of proxies and would be slower than a brute force search.
  -> IO TreeStats
queryClosest :: Ptr DynamicTree
-> Vec3
-> Word64
-> Bool
-> FunPtr TreeQueryClosestCallbackFcn
-> Ptr ()
-> Ptr Float
-> IO TreeStats
queryClosest Ptr DynamicTree
a0 Vec3
a1 Word64
a2 Bool
a3 FunPtr TreeQueryClosestCallbackFcn
a4 Ptr ()
a5 Ptr Float
a6 =
  Vec3 -> (Ptr Vec3 -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with Vec3
a1 ((Ptr Vec3 -> IO TreeStats) -> IO TreeStats)
-> (Ptr Vec3 -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr Vec3
p1 ->
  (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr TreeStats -> IO TreeStats) -> IO TreeStats)
-> (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr TreeStats
pOut -> Ptr DynamicTree
-> Ptr Vec3
-> Word64
-> CBool
-> FunPtr TreeQueryClosestCallbackFcn
-> Ptr ()
-> Ptr Float
-> Ptr TreeStats
-> IO ()
c_b3DynamicTree_QueryClosest Ptr DynamicTree
a0 Ptr Vec3
p1 Word64
a2 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a3) FunPtr TreeQueryClosestCallbackFcn
a4 Ptr ()
a5 Ptr Float
a6 Ptr TreeStats
pOut IO () -> IO TreeStats -> IO TreeStats
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr TreeStats -> IO TreeStats
forall a. Storable a => Ptr a -> IO a
peek Ptr TreeStats
pOut

{- | Ray cast against the proxies in the tree. This relies on the callback
to perform an exact ray cast in the case where the proxy contains a shape.
The callback also performs any collision filtering. This has performance
roughly equal to k * log(n), where k is the number of collisions and n is the
number of proxies in the tree.
Bit-wise filtering using mask bits can greatly improve performance in some scenarios.
However, this filtering may be approximate, so the user should still apply filtering to results.

Returns: performance data

Binds @b3DynamicTree_RayCast@.
-}
rayCast
  :: Ptr DynamicTree
  -- ^ @tree@: the dynamic tree to ray cast
  -> RayCastInput
  -- ^ @input@: the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1)
  -> Word64
  -- ^ @maskBits@: bit mask test: \`bool accept = (maskBits & node-\>categoryBits) != 0;\`
  -> Bool
  -- ^ @requireAllBits@: modifies bit mask test: \`bool accept = (maskBits & node-\>categoryBits) == maskBits;\`
  -> FunPtr TreeRayCastCallbackFcn
  -- ^ @callback@: a callback function that is called for each proxy that is hit by the ray
  -> Ptr ()
  -- ^ @context@: user context that is passed to the callback
  -> IO TreeStats
rayCast :: Ptr DynamicTree
-> RayCastInput
-> Word64
-> Bool
-> FunPtr TreeRayCastCallbackFcn
-> Ptr ()
-> IO TreeStats
rayCast Ptr DynamicTree
a0 RayCastInput
a1 Word64
a2 Bool
a3 FunPtr TreeRayCastCallbackFcn
a4 Ptr ()
a5 =
  RayCastInput -> (Ptr RayCastInput -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with RayCastInput
a1 ((Ptr RayCastInput -> IO TreeStats) -> IO TreeStats)
-> (Ptr RayCastInput -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr RayCastInput
p1 ->
  (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr TreeStats -> IO TreeStats) -> IO TreeStats)
-> (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr TreeStats
pOut -> Ptr DynamicTree
-> Ptr RayCastInput
-> Word64
-> CBool
-> FunPtr TreeRayCastCallbackFcn
-> Ptr ()
-> Ptr TreeStats
-> IO ()
c_b3DynamicTree_RayCast Ptr DynamicTree
a0 Ptr RayCastInput
p1 Word64
a2 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a3) FunPtr TreeRayCastCallbackFcn
a4 Ptr ()
a5 Ptr TreeStats
pOut IO () -> IO TreeStats -> IO TreeStats
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr TreeStats -> IO TreeStats
forall a. Storable a => Ptr a -> IO a
peek Ptr TreeStats
pOut

{- | Sweep an AABB through the tree. The box is in the tree\'s world float frame and the callback
re-differences each shape at full precision against the query origin. Used by the large world
spatial queries so the tree traversal stays float while the narrow phase stays precise.

Binds @b3DynamicTree_BoxCast@.
-}
boxCast
  :: Ptr DynamicTree
  -> Ptr BoxCastInput
  -> Word64
  -- ^ @maskBits@
  -> Bool
  -- ^ @requireAllBits@
  -> FunPtr TreeBoxCastCallbackFcn
  -> Ptr ()
  -- ^ @context@
  -> IO TreeStats
boxCast :: Ptr DynamicTree
-> Ptr BoxCastInput
-> Word64
-> Bool
-> FunPtr TreeBoxCastCallbackFcn
-> Ptr ()
-> IO TreeStats
boxCast Ptr DynamicTree
a0 Ptr BoxCastInput
a1 Word64
a2 Bool
a3 FunPtr TreeBoxCastCallbackFcn
a4 Ptr ()
a5 =
  (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr TreeStats -> IO TreeStats) -> IO TreeStats)
-> (Ptr TreeStats -> IO TreeStats) -> IO TreeStats
forall a b. (a -> b) -> a -> b
$ \Ptr TreeStats
pOut -> Ptr DynamicTree
-> Ptr BoxCastInput
-> Word64
-> CBool
-> FunPtr TreeBoxCastCallbackFcn
-> Ptr ()
-> Ptr TreeStats
-> IO ()
c_b3DynamicTree_BoxCast Ptr DynamicTree
a0 Ptr BoxCastInput
a1 Word64
a2 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a3) FunPtr TreeBoxCastCallbackFcn
a4 Ptr ()
a5 Ptr TreeStats
pOut IO () -> IO TreeStats -> IO TreeStats
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr TreeStats -> IO TreeStats
forall a. Storable a => Ptr a -> IO a
peek Ptr TreeStats
pOut

-- | Like 'boxCast', but the result is written into a caller-supplied buffer.
boxCastInto
  :: Ptr DynamicTree
  -> Ptr BoxCastInput
  -> Word64
  -- ^ @maskBits@
  -> Bool
  -- ^ @requireAllBits@
  -> FunPtr TreeBoxCastCallbackFcn
  -> Ptr ()
  -- ^ @context@
  -> Ptr TreeStats
  -- ^ Result buffer.
  -> IO ()
boxCastInto :: Ptr DynamicTree
-> Ptr BoxCastInput
-> Word64
-> Bool
-> FunPtr TreeBoxCastCallbackFcn
-> Ptr ()
-> Ptr TreeStats
-> IO ()
boxCastInto Ptr DynamicTree
a0 Ptr BoxCastInput
a1 Word64
a2 Bool
a3 FunPtr TreeBoxCastCallbackFcn
a4 Ptr ()
a5 Ptr TreeStats
out =
  Ptr DynamicTree
-> Ptr BoxCastInput
-> Word64
-> CBool
-> FunPtr TreeBoxCastCallbackFcn
-> Ptr ()
-> Ptr TreeStats
-> IO ()
c_b3DynamicTree_BoxCast Ptr DynamicTree
a0 Ptr BoxCastInput
a1 Word64
a2 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a3) FunPtr TreeBoxCastCallbackFcn
a4 Ptr ()
a5 Ptr TreeStats
out

{- | Validate this tree. For testing.

Binds @b3DynamicTree_Validate@.
-}
validate
  :: Ptr DynamicTree
  -> IO ()
validate :: Ptr DynamicTree -> IO ()
validate Ptr DynamicTree
a0 =
  Ptr DynamicTree -> IO ()
c_b3DynamicTree_Validate Ptr DynamicTree
a0

{- | Get the height of the binary tree.

Binds @b3DynamicTree_GetHeight@.
-}
getHeight
  :: Ptr DynamicTree
  -> IO Int
getHeight :: Ptr DynamicTree -> IO Int
getHeight Ptr DynamicTree
a0 =
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr DynamicTree -> IO CInt
c_b3DynamicTree_GetHeight Ptr DynamicTree
a0)

{- | Get the ratio of the sum of the node areas to the root area.

Binds @b3DynamicTree_GetAreaRatio@.
-}
getAreaRatio
  :: Ptr DynamicTree
  -> IO Float
getAreaRatio :: Ptr DynamicTree -> IO Float
getAreaRatio Ptr DynamicTree
a0 =
  Ptr DynamicTree -> IO Float
c_b3DynamicTree_GetAreaRatio Ptr DynamicTree
a0

{- | Get the bounding box that contains the entire tree

Binds @b3DynamicTree_GetRootBounds@.
-}
getRootBounds
  :: Ptr DynamicTree
  -> IO AABB
getRootBounds :: Ptr DynamicTree -> IO AABB
getRootBounds Ptr DynamicTree
a0 =
  (Ptr AABB -> IO AABB) -> IO AABB
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca ((Ptr AABB -> IO AABB) -> IO AABB)
-> (Ptr AABB -> IO AABB) -> IO AABB
forall a b. (a -> b) -> a -> b
$ \Ptr AABB
pOut -> Ptr DynamicTree -> Ptr AABB -> IO ()
c_b3DynamicTree_GetRootBounds Ptr DynamicTree
a0 Ptr AABB
pOut IO () -> IO AABB -> IO AABB
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr AABB -> IO AABB
forall a. Storable a => Ptr a -> IO a
peek Ptr AABB
pOut

-- | Like 'getRootBounds', but the result is written into a caller-supplied buffer.
getRootBoundsInto
  :: Ptr DynamicTree
  -> Ptr AABB
  -- ^ Result buffer.
  -> IO ()
getRootBoundsInto :: Ptr DynamicTree -> Ptr AABB -> IO ()
getRootBoundsInto Ptr DynamicTree
a0 Ptr AABB
out =
  Ptr DynamicTree -> Ptr AABB -> IO ()
c_b3DynamicTree_GetRootBounds Ptr DynamicTree
a0 Ptr AABB
out

{- | Get the number of proxies created

Binds @b3DynamicTree_GetProxyCount@.
-}
getProxyCount
  :: Ptr DynamicTree
  -> IO Int
getProxyCount :: Ptr DynamicTree -> IO Int
getProxyCount Ptr DynamicTree
a0 =
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr DynamicTree -> IO CInt
c_b3DynamicTree_GetProxyCount Ptr DynamicTree
a0)

{- | Rebuild the tree while retaining subtrees that haven\'t changed. Returns the number of boxes sorted.

Binds @b3DynamicTree_Rebuild@.
-}
rebuild
  :: Ptr DynamicTree
  -> Bool
  -- ^ @fullBuild@
  -> IO Int
rebuild :: Ptr DynamicTree -> Bool -> IO Int
rebuild Ptr DynamicTree
a0 Bool
a1 =
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr DynamicTree -> CBool -> IO CInt
c_b3DynamicTree_Rebuild Ptr DynamicTree
a0 (Bool -> CBool
forall a. Num a => Bool -> a
fromBool Bool
a1))

{- | Get the number of bytes used by this tree

Binds @b3DynamicTree_GetByteCount@.
-}
getByteCount
  :: Ptr DynamicTree
  -> IO Int
getByteCount :: Ptr DynamicTree -> IO Int
getByteCount Ptr DynamicTree
a0 =
  CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int) -> IO CInt -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr DynamicTree -> IO CInt
c_b3DynamicTree_GetByteCount Ptr DynamicTree
a0)

{- | Validate this tree has no enlarged AABBs. For testing.

Binds @b3DynamicTree_ValidateNoEnlarged@.
-}
validateNoEnlarged
  :: Ptr DynamicTree
  -> IO ()
validateNoEnlarged :: Ptr DynamicTree -> IO ()
validateNoEnlarged Ptr DynamicTree
a0 =
  Ptr DynamicTree -> IO ()
c_b3DynamicTree_ValidateNoEnlarged Ptr DynamicTree
a0

{- | Save this tree to a file for debugging

Binds @b3DynamicTree_Save@.
-}
save
  :: Ptr DynamicTree
  -> CString
  -- ^ @fileName@
  -> IO ()
save :: Ptr DynamicTree -> CString -> IO ()
save Ptr DynamicTree
a0 CString
a1 =
  Ptr DynamicTree -> CString -> IO ()
c_b3DynamicTree_Save Ptr DynamicTree
a0 CString
a1

{- | Load a file for debugging

Binds @b3DynamicTree_Load@.
-}
load
  :: CString
  -- ^ @fileName@
  -> Float
  -- ^ @scale@
  -> Ptr DynamicTree
  -- ^ Result buffer.
  -> IO ()
load :: CString -> Float -> Ptr DynamicTree -> IO ()
load CString
a0 Float
a1 Ptr DynamicTree
out =
  CString -> Float -> Ptr DynamicTree -> IO ()
c_b3DynamicTree_Load CString
a0 Float
a1 Ptr DynamicTree
out