From 46bf67f44c4d7b40a50236614ea71c77d1fb38ad Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 13 Mar 2019 00:20:46 -0400 Subject: add type signatures --- shelves.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shelves.hs b/shelves.hs index 0136e1c..b1cfd76 100644 --- a/shelves.hs +++ b/shelves.hs @@ -3,37 +3,52 @@ import Control.Lens import Data.List import GenSCAD +shelf_thickness :: Double shelf_thickness = 0.5 +shelf_width :: Double shelf_width = 8 +shelf_length :: Double shelf_length = 36 * 2 +shelf_dim :: V3 Double shelf_dim = V3 shelf_length shelf_width shelf_thickness +shelf_heights :: [Double] shelf_heights = [12, 10, 8, 8, 8, 8, 8] -- working algorithm doing the same as `scanl (+) 0 shelf_heights` --acc [] = [0] --acc xs = acc(init xs) ++ [sum xs] +shelf_height :: Double shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) +side_dim :: V3 Double side_dim = V3 0.5 shelf_width shelf_height --shelf_y_poss = scanl (+) 0 shelf_heights +shelf_y_poss :: [Double] shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] +shelves_pos :: [V3 Double] shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] +shelves :: [(V3 Double, V3 Double)] shelves = [(p, shelf_dim) | p <- shelves_pos] --sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] +sides_pos :: [V3 Double] sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] +sides :: [(V3 Double, V3 Double)] sides = [(p, side_dim) | p <- sides_pos] --V3_to_string v = drop 3 (show v) +_V32l :: R3 t => t a -> [a] _V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] +_V32s :: (Show a, R3 t) => t a -> [Char] _V32s v3 = intercalate ", " (map show (_V32l v3)) --scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" --genscad objs = concat $ map (++ "\n") $ map scad_place objs +scadshelf :: String scadshelf = genscad $ shelves ++ sides --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] @@ -41,6 +56,7 @@ scadshelf = genscad $ shelves ++ sides +main :: IO () main = do putStrLn scadshelf -- cgit v1.2.3