1 module Interpret 2 3 4 5 6 (Command, Operations, Operation, interpret) 7 8 where 9 10 11 12 import Params (Button(..),Command(..),delimiter,buttonIndent,buttonWidth,buttons, 13 buttonHeight) 14 import EuclidGMS (inScreen,Point(..),mkPoint) 15 import GeomNum 16 import Stdlib (between,splitAt_YORK) 17 18 19 20 21 type Operation = (Command,Points) 22 23 24 25 type Points = [Point] 26 27 28 29 type Operations = [Operation] 30 31 32 33 34 35 36 37 38 interpret :: [String] -> Operations 39 interpret (head:residue) = (operation:interpret residue' ) 40 where 41 (operation,residue') = toOperation command residue 42 command = (toCommand.mkPoint) head 43 44 45 46 47 48 toOperation :: Command -> [String] -> (Operation,[String]) 49 toOperation Polygon str = ((Polygon,mkPoints points),out) 50 where 51 (points,out) = splitAt_YORK delimiter str 52 toOperation Union str = ((Union,mkPoints points),out) 53 where 54 (points,out) = splitAt_YORK delimiter str 55 toOperation Intersect str = ((Intersect,mkPoints points),out) 56 where 57 (points,out) = splitAt_YORK delimiter str 58 toOperation Subtract str = ((Subtract,mkPoints points),out) 59 where 60 (points,out) = splitAt_YORK delimiter str 61 toOperation Classify str = ((Classify,mkPoints points),out) 62 where 63 (points,out) = splitAt_YORK delimiter str 64 toOperation Complement str = ((Complement,[]),str) 65 toOperation Partition str = ((Partition,[]),str) 66 toOperation Render str = ((Render,[]),str) 67 toOperation Area str = ((Area,[]),str) 68 toOperation Quit str = ((Quit,[]),str) 69 toOperation Null str = ((Null,[]),str) 70 71 72 73 74 75 mkPoints :: [String] -> Points 76 mkPoints = filter inScreen.map mkPoint 77 78 79 80 81 82 83 84 toCommand :: Point -> Command 85 toCommand (Pt x y) | x<fromIntegral buttonIndent || 86 x>fromIntegral (buttonIndent+buttonWidth) 87 = Null 88 | otherwise = command 89 where (command,_,_) = search (y::Numb) buttons 90 91 92 93 94 95 96 search :: Numb -> [Button] -> Button 97 search y [] = (Null,0,"") 98 search y ((command,d,str):butts) | between (fromIntegral d) 99 (fromIntegral buttonHeight) y = (command,d,str) 100 search y ((command,d,str):butts) = search y butts