diff options
author | Andrew Cady <d@jerkface.net> | 2019-03-13 00:18:59 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-03-13 00:18:59 -0400 |
commit | 519a2c67255cb16edced9ebfdc344c11fb7778b8 (patch) | |
tree | f279e2fa629c5a94975f406da9338ea82919a3ef | |
parent | d117d0de23ea78f7d614cb6d1603b3dba45b8890 (diff) |
add type signatures
-rw-r--r-- | GenSCAD.hs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -30,13 +30,19 @@ _V32s c = intercalate "," (map show (_V32l c)) | |||
30 | -- translate([1, 2, 3]) { cube([10, 20, 30]); } | 30 | -- translate([1, 2, 3]) { cube([10, 20, 30]); } |
31 | 31 | ||
32 | --crandrgb = intercalate "," | 32 | --crandrgb = intercalate "," |
33 | color :: [Char] -> [Char] -> [Char] | ||
33 | color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}" | 34 | color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}" |
35 | translate :: [Char] -> [Char] -> [Char] | ||
34 | translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }" | 36 | translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }" |
37 | cube :: [Char] -> [Char] | ||
35 | cube d = "cube([ " ++ d ++ "]);" | 38 | cube d = "cube([ " ++ d ++ "]);" |
39 | cubeat :: [Char] -> [Char] -> [Char] | ||
36 | cubeat d here = translate here $ (cube d) | 40 | cubeat d here = translate here $ (cube d) |
41 | colorcubeat :: [Char] -> [Char] -> [Char] -> [Char] | ||
37 | colorcubeat rgb d pos = color rgb $ translate pos $ cube d | 42 | colorcubeat rgb d pos = color rgb $ translate pos $ cube d |
38 | 43 | ||
39 | --place [x] = "ERROR" | 44 | --place [x] = "ERROR" |
45 | place :: [[Char]] -> [Char] | ||
40 | place [d, p] = cubeat d p | 46 | place [d, p] = cubeat d p |
41 | place [r, d, p] = colorcubeat r d p | 47 | place [r, d, p] = colorcubeat r d p |
42 | 48 | ||
@@ -48,6 +54,7 @@ place [r, d, p] = colorcubeat r d p | |||
48 | 54 | ||
49 | --scad [] = [] | 55 | --scad [] = [] |
50 | --scad obj = (place (head obj)) ++ "\n" ++ scad (tail obj) | 56 | --scad obj = (place (head obj)) ++ "\n" ++ scad (tail obj) |
57 | scad :: [([Char], [Char])] -> [Char] | ||
51 | scad [(d, p)] = cubeat p d | 58 | scad [(d, p)] = cubeat p d |
52 | --scad [(r, d, p)] = colorcubeat r d p | 59 | --scad [(r, d, p)] = colorcubeat r d p |
53 | --scad [x] = if (length x == 3) then (colorcubeat (x !! 0) (x !! 1) (x !! 2)) | 60 | --scad [x] = if (length x == 3) then (colorcubeat (x !! 0) (x !! 1) (x !! 2)) |
@@ -55,6 +62,7 @@ scad [(d, p)] = cubeat p d | |||
55 | --scad (x:s) = scad [x] ++ scad s | 62 | --scad (x:s) = scad [x] ++ scad s |
56 | 63 | ||
57 | 64 | ||
65 | placecube :: (R3 c2, R3 c3, Show a1, Show a2) => (c2 a1, c3 a2) -> [Char] | ||
58 | placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" | 66 | placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" |
59 | --placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d) | 67 | --placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d) |
60 | 68 | ||
@@ -72,10 +80,14 @@ placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(sn | |||
72 | 80 | ||
73 | --scad (c, p, d) = colorcubeat c d p | 81 | --scad (c, p, d) = colorcubeat c d p |
74 | --scad (p,d) = cubeat d p | 82 | --scad (p,d) = cubeat d p |
83 | genscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> [Char] | ||
75 | genscad objs = concat $ map (++ "\n") $ map (placecube) objs | 84 | genscad objs = concat $ map (++ "\n") $ map (placecube) objs |
85 | printscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO () | ||
76 | printscad objs = putStrLn $ genscad objs | 86 | printscad objs = putStrLn $ genscad objs |
77 | --writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs | 87 | --writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs |
88 | writetempscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO FilePath | ||
78 | writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs) | 89 | writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs) |
90 | opentempscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO ProcessHandle | ||
79 | opentempscad objs = do | 91 | opentempscad objs = do |
80 | fp <- writetempscad objs | 92 | fp <- writetempscad objs |
81 | runCommand $ "openscad " ++ fp | 93 | runCommand $ "openscad " ++ fp |