minimung-0.0: Data/Geometry.hs
-- |
--
--
module Data.Geometry where
type Coord = Int
type Point = (Coord, Coord)
type Size = (Int, Int)
-- data Size = Size Int Int
type Origin = Point
-- |
--
-- Origin
-- *---
-- |
-- | Size
--
--
data Region = Rectangle Origin Size deriving Show
-- downSample :: Size -> Int -> Size
-- downSample (w, h) factor = (w `div` factor, h `div` factor)
translate :: Point -> Point -> Point
translate (ox, oy) (x, y) = (ox + x, oy + y)
-- |
-- Makes rectangle region.
--
-- Second argument is center of the rectangle
withCenter :: Size -> Point -> Region
size@(w, h) `withCenter` o = Rectangle o' size
where
o' = translate o (-w `div` 2, -h `div` 2)
points :: Region -> [Point]
points (Rectangle (ox, oy) (w, h)) = [(x, y) | y <- [oy .. (oy + h)], x <- [ox .. (ox + w)]]