{-# LANGUAGE ForeignFunctionInterface #-}
module Box2D.MathFunctions
( isValidVec2
, isValidRotation
, isValidTransform
, isValidAABB
, isValidPlane
, computeCosSin
, makeRot
, rotGetAngle
) where
import Foreign
import Foreign.C.Types (CBool (..))
import Box2D.Internal (allocaOut, withValid)
import Box2D.MathTypes
foreign import ccall unsafe "hs_b2IsValidVec2"
c_b2IsValidVec2 :: Ptr Vec2 -> IO CBool
foreign import ccall unsafe "hs_b2IsValidRotation"
c_b2IsValidRotation :: Ptr Rot -> IO CBool
foreign import ccall unsafe "hs_b2IsValidTransform"
c_b2IsValidTransform :: Ptr Transform -> IO CBool
foreign import ccall unsafe "hs_b2IsValidAABB"
c_b2IsValidAABB :: Ptr AABB -> IO CBool
foreign import ccall unsafe "hs_b2IsValidPlane"
c_b2IsValidPlane :: Ptr Plane -> IO CBool
foreign import ccall unsafe "hs_b2ComputeCosSin"
c_b2ComputeCosSin :: Float -> Ptr CosSin -> IO ()
foreign import ccall unsafe "hs_b2MakeRot"
c_b2MakeRot :: Float -> Ptr Rot -> IO ()
isValidVec2 :: Vec2 -> IO Bool
isValidVec2 :: Vec2 -> IO Bool
isValidVec2 = (Ptr Vec2 -> IO CBool) -> Vec2 -> IO Bool
forall a. Storable a => (Ptr a -> IO CBool) -> a -> IO Bool
withValid Ptr Vec2 -> IO CBool
c_b2IsValidVec2
isValidRotation :: Rot -> IO Bool
isValidRotation :: Rot -> IO Bool
isValidRotation = (Ptr Rot -> IO CBool) -> Rot -> IO Bool
forall a. Storable a => (Ptr a -> IO CBool) -> a -> IO Bool
withValid Ptr Rot -> IO CBool
c_b2IsValidRotation
isValidTransform :: Transform -> IO Bool
isValidTransform :: Transform -> IO Bool
isValidTransform = (Ptr Transform -> IO CBool) -> Transform -> IO Bool
forall a. Storable a => (Ptr a -> IO CBool) -> a -> IO Bool
withValid Ptr Transform -> IO CBool
c_b2IsValidTransform
isValidAABB :: AABB -> IO Bool
isValidAABB :: AABB -> IO Bool
isValidAABB = (Ptr AABB -> IO CBool) -> AABB -> IO Bool
forall a. Storable a => (Ptr a -> IO CBool) -> a -> IO Bool
withValid Ptr AABB -> IO CBool
c_b2IsValidAABB
isValidPlane :: Plane -> IO Bool
isValidPlane :: Plane -> IO Bool
isValidPlane = (Ptr Plane -> IO CBool) -> Plane -> IO Bool
forall a. Storable a => (Ptr a -> IO CBool) -> a -> IO Bool
withValid Ptr Plane -> IO CBool
c_b2IsValidPlane
computeCosSin :: Float -> IO CosSin
computeCosSin :: Float -> IO CosSin
computeCosSin Float
radians = (Ptr CosSin -> IO ()) -> IO CosSin
forall a. Storable a => (Ptr a -> IO ()) -> IO a
allocaOut (Float -> Ptr CosSin -> IO ()
c_b2ComputeCosSin Float
radians)
makeRot :: Float -> IO Rot
makeRot :: Float -> IO Rot
makeRot Float
radians = (Ptr Rot -> IO ()) -> IO Rot
forall a. Storable a => (Ptr a -> IO ()) -> IO a
allocaOut (Float -> Ptr Rot -> IO ()
c_b2MakeRot Float
radians)
rotGetAngle :: Rot -> Float
rotGetAngle :: Rot -> Float
rotGetAngle (Rot Float
c Float
s) = Float -> Float -> Float
forall a. RealFloat a => a -> a -> a
atan2 Float
s Float
c