{-# LINE 1 "src/GEGL/FFI/Rectangle.hsc" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LINE 2 "src/GEGL/FFI/Rectangle.hsc" #-}

-- | FFI module for defining and using rectangles
module GEGL.FFI.Rectangle
  ( GeglRectangle(..)
  , c_gegl_rectangle_intersect
  -- , c_gegl_rectangle_infinite_plane
  ) where

import Foreign
import Foreign.Ptr
import Foreign.C.Types


{-# LINE 15 "src/GEGL/FFI/Rectangle.hsc" #-}

-- | A standard GEGL rectangle
data GeglRectangle = GeglRectangle
  { rectangleX      :: Int -- ^ X coordinate of upper left corner
  , rectangleY      :: Int -- ^ Y coordinate of upper left corner
  , rectangleWidth  :: Int -- ^ Width in pixels
  , rectangleHeight :: Int -- ^ Height in picels
  } deriving (Show)

instance Storable GeglRectangle where
  sizeOf _    = ((16))
{-# LINE 26 "src/GEGL/FFI/Rectangle.hsc" #-}
  alignment _ = alignment (undefined :: CDouble)
  peek ptr = do
    x      <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr :: IO CInt
{-# LINE 29 "src/GEGL/FFI/Rectangle.hsc" #-}
    y      <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr :: IO CInt
{-# LINE 30 "src/GEGL/FFI/Rectangle.hsc" #-}
    width  <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr :: IO CInt
{-# LINE 31 "src/GEGL/FFI/Rectangle.hsc" #-}
    height <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr :: IO CInt
{-# LINE 32 "src/GEGL/FFI/Rectangle.hsc" #-}
    return GeglRectangle
      { rectangleX      = fromIntegral x
      , rectangleY      = fromIntegral y
      , rectangleWidth  = fromIntegral width
      , rectangleHeight = fromIntegral height
      }
  poke ptr (GeglRectangle x y w h) = do
    ((\hsc_ptr -> pokeByteOff hsc_ptr 0))      ptr (CInt $ fromIntegral x)
{-# LINE 40 "src/GEGL/FFI/Rectangle.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 4))      ptr (CInt $ fromIntegral y)
{-# LINE 41 "src/GEGL/FFI/Rectangle.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 8))  ptr (CInt $ fromIntegral w)
{-# LINE 42 "src/GEGL/FFI/Rectangle.hsc" #-}
    ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (CInt $ fromIntegral h)
{-# LINE 43 "src/GEGL/FFI/Rectangle.hsc" #-}

-- | Interface to @gegl_rectangle_intersect@ function in C.
foreign import ccall unsafe "gegl.h gegl_rectangle_intersect"
  c_gegl_rectangle_intersect
    :: Ptr GeglRectangle -- ^ destination rectangle
    -> Ptr GeglRectangle -- ^ A Rectangle
    -> Ptr GeglRectangle -- ^ A rectangle
    -> IO Bool           -- ^ Returns @True@ if rectangles intersect

-- -- | Interface to the @gegl_rectangle_infinite_plane@ function in C.
-- foreign import ccall unsafe "gegl.h gegl_rectangle_infinite_plane"
--   c_gegl_rectangle_infinite_plane
--     :: GeglRectangle