module Graphics.Gloss.Accelerate.Data.Point (
Point,
makePoint,
xyOfPoint,
pointOfIndex,
pointInBox,
) where
import Data.Array.Accelerate as A
import Data.Array.Accelerate.Linear.V2
import qualified Prelude as P
type Point = V2 Float
makePoint
:: Exp Float
-> Exp Float
-> Exp Point
makePoint = V2_
xyOfPoint
:: Exp Point
-> (Exp Float, Exp Float)
xyOfPoint (V2_ x y) = (x, y)
pointOfIndex
:: Int
-> Int
-> Exp DIM2
-> Exp Point
pointOfIndex sizeX sizeY ix
= let
fsizeX, fsizeY :: Float
fsizeX = P.fromIntegral sizeX
fsizeY = P.fromIntegral sizeY
fsizeX2, fsizeY2 :: Exp Float
fsizeX2 = constant $ fsizeX / 2
fsizeY2 = constant $ fsizeY / 2
midX, midY :: Exp Int
midX = constant $ sizeX `div` 2
midY = constant $ sizeY `div` 2
Z :. y :. x = unlift ix
x' = A.fromIntegral (x - midX) / fsizeX2
y' = A.fromIntegral (y - midY) / fsizeY2
in
makePoint x' y'
pointInBox
:: Exp Point
-> Exp Point
-> Exp Point
-> Exp Bool
pointInBox (V2_ x0 y0) (V2_ x1 y1) (V2_ x2 y2) =
x0 >= min x1 x2 &&
x0 <= max x1 x2 &&
y0 >= min y1 y2 &&
y0 <= max y1 y2