summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-03-13 00:18:59 -0400
committerAndrew Cady <d@jerkface.net>2019-03-13 00:18:59 -0400
commit519a2c67255cb16edced9ebfdc344c11fb7778b8 (patch)
treef279e2fa629c5a94975f406da9338ea82919a3ef
parentd117d0de23ea78f7d614cb6d1603b3dba45b8890 (diff)
add type signatures
-rw-r--r--GenSCAD.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/GenSCAD.hs b/GenSCAD.hs
index 6eca485..5989c65 100644
--- a/GenSCAD.hs
+++ b/GenSCAD.hs
@@ -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 ","
33color :: [Char] -> [Char] -> [Char]
33color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}" 34color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}"
35translate :: [Char] -> [Char] -> [Char]
34translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }" 36translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }"
37cube :: [Char] -> [Char]
35cube d = "cube([ " ++ d ++ "]);" 38cube d = "cube([ " ++ d ++ "]);"
39cubeat :: [Char] -> [Char] -> [Char]
36cubeat d here = translate here $ (cube d) 40cubeat d here = translate here $ (cube d)
41colorcubeat :: [Char] -> [Char] -> [Char] -> [Char]
37colorcubeat rgb d pos = color rgb $ translate pos $ cube d 42colorcubeat rgb d pos = color rgb $ translate pos $ cube d
38 43
39--place [x] = "ERROR" 44--place [x] = "ERROR"
45place :: [[Char]] -> [Char]
40place [d, p] = cubeat d p 46place [d, p] = cubeat d p
41place [r, d, p] = colorcubeat r d p 47place [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)
57scad :: [([Char], [Char])] -> [Char]
51scad [(d, p)] = cubeat p d 58scad [(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
65placecube :: (R3 c2, R3 c3, Show a1, Show a2) => (c2 a1, c3 a2) -> [Char]
58placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" 66placecube 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
83genscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> [Char]
75genscad objs = concat $ map (++ "\n") $ map (placecube) objs 84genscad objs = concat $ map (++ "\n") $ map (placecube) objs
85printscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO ()
76printscad objs = putStrLn $ genscad objs 86printscad objs = putStrLn $ genscad objs
77--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs 87--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs
88writetempscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO FilePath
78writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs) 89writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs)
90opentempscad :: (R3 c2, R3 c3, Show a1, Show a2) => [(c2 a1, c3 a2)] -> IO ProcessHandle
79opentempscad objs = do 91opentempscad objs = do
80 fp <- writetempscad objs 92 fp <- writetempscad objs
81 runCommand $ "openscad " ++ fp 93 runCommand $ "openscad " ++ fp