summaryrefslogtreecommitdiff
path: root/Mask.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Mask.hs')
-rw-r--r--Mask.hs63
1 files changed, 63 insertions, 0 deletions
diff --git a/Mask.hs b/Mask.hs
new file mode 100644
index 0000000..0b91e42
--- /dev/null
+++ b/Mask.hs
@@ -0,0 +1,63 @@
1module Mask where
2
3import Data.Int
4
5newtype Mask = Mask [(Int32,Int32)]
6 deriving (Eq,Ord,Show)
7
8{-
9merge ((x0,x):xs) ((y0,y):ys) =
10 if x0 <= y0
11 then case compare x y0 of
12 LT -> (x0 x) (y0 y)
13 EQ -> (x0 x=y0 y)
14 GT -> if x <= y then -> (x0 y0 x y)
15 else -> (x0 y0 y x)
16 else case compare x0 y of
17 LT -> if x <= y then (y0 x0 x y)
18 else (y0 x0 y x)
19 EQ -> (y0 y=x0 x)
20 GT -> (y0 y) (x0 x)
21-}
22
23subtr [] ys = []
24subtr xs [] = xs
25subtr ((x0,x):xs) ((y0,y):ys) =
26 if x0 <= y0
27 then case compare x y0 of
28 LT -> subtr ((x0,x):xs) ys
29 EQ -> (x0,x) : subtr xs ((y0,y):ys)
30 GT -> if x <= y then (if x0<y0 then ((x0,y0) :) else id) $ subtr xs ((y0,y):ys)
31 else (if x0<y0 then ((x0,y0) :) else id) $ subtr ((y,x):xs) ys
32 else case compare x0 y of
33 LT -> if x <= y then subtr xs ((y0,y):ys)
34 else subtr ((y,x):xs) ys
35 EQ -> subtr ((x0,x):xs) ys
36 GT -> subtr ((x0,x):xs) ys
37
38union [] ys = ys
39union xs [] = xs
40union ((x0,x):xs) ((y0,y):ys) =
41 if x0 <= y0
42 then case compare x y0 of
43 LT -> (x0,x) : union xs ((y0,y):ys)
44 EQ -> (x0,y) : union xs ys
45 GT -> if x <= y then union xs ((x0,y):ys)
46 else union ((x0,x):xs) ys
47 else case compare x0 y of
48 LT -> if x <= y then union xs ((y0,y):ys)
49 else union ((y0,x):xs) ys
50 EQ -> (y0,x) : union xs ys
51 GT -> (y0,y) : union ((x0,x):xs) ys
52
53endpts :: (Int32,Int32) -> (Int32,Int32)
54endpts (x0,sz) = (x0,x0 + sz)
55
56sized :: (Int32,Int32) -> (Int32,Int32)
57sized (x0,x) = (x0, x - x0)
58
59maskPlus :: Mask -> Mask -> Mask
60maskPlus (Mask xs) (Mask ys) = Mask $ sized <$> union (endpts <$> xs) (endpts <$> ys)
61
62maskSubtract :: Mask -> Mask -> Mask
63maskSubtract (Mask xs) (Mask ys) = Mask $ sized <$> subtr (endpts <$> xs) (endpts <$> ys)