module GridBox.Coordinate
( fromBox
, fromBoxes
, getX
, getY
, topX
, topY
, transform
) where
import GridBox.Box (Box(width, height, x, y))
fromBox :: Box -> [(Double, Double)]
fromBox 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
fromBoxes :: [Box] -> [[(Double, Double)]]
fromBoxes boxes =
map fromBox boxes
getX :: Int -> Double -> Double -> Double
getX col size xOffset =
topX (fromIntegral(col) * size + size/2) xOffset
getY :: Int -> Double -> Double -> Double
getY row size yOffset =
topY (fromIntegral(row) * size + size/2) yOffset
topX :: Double -> Double -> Double
topX pos xOffset =
pos + xOffset
topY :: Double -> Double -> Double
topY pos yOffset =
pos + yOffset
transform :: (Double, Double) -> Double -> Double -> Double -> (Double, Double) -> (Double, Double)
transform (ox, oy) scale xOffset yOffset (x, y) =
(topX (scale * x) (xOffset + ox), topY (scale *y) (yOffset + oy))