module GridBox.Box
( Box(..)
, BoxRow
, BoxCol
, BoxPosition
, BoxPositions
, makeBox
, makeVectors
, fromBox
, fromBoxes
) where
data Box = Box
{ x :: Double
, y :: Double
, row :: BoxRow
, col :: BoxCol
, width :: Double
, height :: Double
}
deriving (Read, Show, Eq)
type BoxRow = Int
type BoxCol = Int
type BoxPosition = (BoxRow, BoxCol)
type BoxPositions = [BoxPosition]
makeBox :: Double -> Double -> Int -> Int -> (Double, Double) -> Box
makeBox x y row col (width, height) =
Box x y row col width height
makeVectors :: Box -> [(Double, Double)]
makeVectors box = [
(boxX + offX, boxY + offY),
(boxX + offX, boxY offY),
(boxX offX, boxY offY),
(boxX offX, boxY + offY),
(boxX + offX, boxY + offY)
]
where
offX = (width box) / 2
offY = (height box) / 2
boxX = x box
boxY = y box
fromBox :: Box -> BoxPosition
fromBox box =
(row box, col box)
fromBoxes :: [Box] -> BoxPositions
fromBoxes boxes =
map fromBox boxes