never executed always true always false
1 module HelVM.HelMA.Automata.Piet.Types.Image (
2 witdthImage,
3 heightImage,
4 inRangeImage,
5 pixelImage,
6 setPixelImage,
7 newImage,
8 Image(..),
9 ) where
10
11 import HelVM.HelMA.Automata.Piet.Types.Coordinates
12
13 import Data.Array.Diff
14
15 witdthImage :: Image a -> Int
16 witdthImage = fst . dimensionsImage
17
18 heightImage :: Image a -> Int
19 heightImage = snd . dimensionsImage
20
21 dimensionsImage :: Image a -> Coordinates
22 dimensionsImage (Image pixels) = (maxX - minX + 1, maxY - minY + 1) where ((minX, minY), (maxX, maxY)) = bounds pixels
23
24 inRangeImage :: Coordinates -> Image a -> Bool
25 inRangeImage (x, y) img = 0 <= x && x < witdthImage img && 0 <= y && y < heightImage img
26
27 pixelImage :: Coordinates -> Image a -> a
28 pixelImage (x, y) img = pixels img ! (x, y)
29
30 setPixelImage :: Coordinates -> a -> Image a -> Image a
31 setPixelImage (x, y) pixel img = img { pixels = pixels img // [((x, y), pixel)] }
32
33 newImage :: Coordinates -> [(Coordinates, a)] -> Image a
34 newImage (width, height) = Image . array ((0, 0), (width - 1, height - 1))
35
36 instance Functor Image where
37 fmap f img = img { pixels = amap f (pixels img) }
38
39 newtype Image a = Image
40 { pixels :: DiffArray Coordinates a
41 }
42 deriving stock (Show)