summaryrefslogtreecommitdiff
path: root/OpenSCAD/Carpentry.hs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSCAD/Carpentry.hs')
-rw-r--r--OpenSCAD/Carpentry.hs151
1 files changed, 64 insertions, 87 deletions
diff --git a/OpenSCAD/Carpentry.hs b/OpenSCAD/Carpentry.hs
index b6d1e73..aeb9ede 100644
--- a/OpenSCAD/Carpentry.hs
+++ b/OpenSCAD/Carpentry.hs
@@ -15,16 +15,17 @@ module OpenSCAD.Carpentry
15, component 15, component
16 ) where 16 ) where
17 17
18import Control.Applicative 18import Control.Applicative
19import Control.Lens hiding (at) 19import Control.Lens hiding (at)
20import Graphics.OpenSCAD 20import Data.Colour.RGBSpace
21import Linear.V3 21import Data.Either
22import System.IO.Temp 22import Data.Functor
23import System.Process 23import Data.List
24import Data.List 24import Data.Maybe
25import Data.Functor 25import Graphics.OpenSCAD
26import Data.Maybe 26import Linear.V3
27import Data.Either 27import System.IO.Temp
28import System.Process
28 29
29v3box :: R3 t => t Double -> Model3d 30v3box :: R3 t => t Double -> Model3d
30v3box v = box (v ^. _x) (v ^. _y) (v ^. _z) 31v3box v = box (v ^. _x) (v ^. _y) (v ^. _z)
@@ -49,9 +50,9 @@ at :: Applicative f => f a -> f a -> f a -> f (V3 a)
49at = liftA3 V3 50at = liftA3 V3
50--at x y z = V3 <$> x <*> y <*> z -- same as above 51--at x y z = V3 <$> x <*> y <*> z -- same as above
51 52
52placeColored rgb board coords = map boardAt coords 53placeColored c board coords = map boardAt coords
53 where 54 where
54 boardAt p = color rgb $ translate (p ^. _x, p ^. _y, p ^. _z) $ v3box board 55 boardAt p = color c $ translate (p ^. _x, p ^. _y, p ^. _z) $ v3box board
55 56
56-- deprecated due to the superiority of using place in conjunction with at 57-- deprecated due to the superiority of using place in conjunction with at
57-- placeAlong (V3 2 4 16) (V3 0 0 0) (_x +~ 4) _x (<= 20) 58-- placeAlong (V3 2 4 16) (V3 0 0 0) (_x +~ 4) _x (<= 20)
@@ -83,91 +84,67 @@ placeAlong board initial shift targ cond =
83-- data Component = Component { 84-- data Component = Component {
84-- name :: String, 85-- name :: String,
85-- , dim :: V3 Double 86-- , dim :: V3 Double
86-- , orient :: 87-- , orient ::
87-- } 88-- }
88-- assemble 89-- assemble
89-- assemble [ component "shelves" (V3 1 8 36) _xyz $ at [0] [0,12,24,36] [0] 90-- assemble [ component "shelves" (V3 1 8 36) _xyz $ at [0] [0,12,24,36] [0]
90-- , component "sides" (V3 1 8 40) _xyz $ at [0] [0,36] [0] ] 91-- , component "sides" (V3 1 8 40) _xyz $ at [0] [0,36] [0] ]
91 92
93assemble :: [(String, String, V3 Double,
94 (V3 Double -> Const (V3 Double) (V3 Double))
95 -> V3 Double -> Const (V3 Double) (V3 Double),
96 [V3 Double])] -> (String, [Model3d])
92assemble c = (cutlist, model) 97assemble c = (cutlist, model)
93 where 98 where
94 model = concatMap (\(_, b, o, p) -> place (b ^. o) p) c 99 model = concatMap (\(_, c, b, o, p) -> placeColored (safeColor c) (b ^. o) p) c
95 cutlist = putStrLn $ intercalate "\n" $ map tocut c 100 safeColor :: String -> Colour Double
96 tocut (n, b, _, p) = n ++ " (" ++ (show $ length p) ++ ") @ " ++ v3toStr b 101 safeColor = runIdentity . readColourName
102 cutlist = intercalate "\n" $ map tocut c
103 tocut (n, c, b, _, p) = n ++ " (" ++ show (length p) ++ ", " ++ c ++ ") @ " ++ v3toStr b
97 v3toStr c = show (c ^. _x) ++ " x " ++ show (c ^. _y) ++ " x " ++ show (c ^. _z) 104 v3toStr c = show (c ^. _x) ++ " x " ++ show (c ^. _y) ++ " x " ++ show (c ^. _z)
98 105
99-- assemble' c = (cutlist, model) 106--component :: a -> b -> c -> d -> e -> (a, b, c, d, e)
100-- where 107--component :: a -> b -> c -> d -> e -> (a, b, c, d, e)
101-- model = let placeBoard b p = translate (p ^. _x, p ^. _y, p ^. _z) $ v3box b 108-- component :: String
102-- in concatMap (\(_, b, o, p, tf) placeBoard 109-- -> String
103-- boardAt p = 110-- -> V3 Double
104component name dim orient pos = (name, dim, orient, pos) 111-- -> ((f -> Const f f) -> V3 Double -> Const f (V3 Double))
112-- -> [V3 Double]
113-- -> (String, String, V3 Double,
114-- (f -> Const f f) ->
115-- V3 Double -> Const f (V3 Double), [V3 Double], f)
116
117-- c :: ([Char], [Char], V3 Integer,
118-- (V3 a -> ghc-prim-0.5.3:GHC.Types.Any (V3 a))
119-- -> ghc-prim-0.5.3:GHC.Types.Any a
120-- -> ghc-prim-0.5.3:GHC.Types.Any (ghc-prim-0.5.3:GHC.Types.Any a),
121-- [V3 Integer])
122-- component :: (String, String, V3 Double,
123-- (V3 Double -> Const (V3 Double) (V3 Double))
124-- -> V3 Double -> Const (V3 Double) (V3 Double), [V3 Double])
125-- component :: String -> String, V3 Integer,
126-- (V3 Integer -> Const (V3 Integer) (V3 Integer))
127-- -> V3 Integer -> Const (V3 Integer) (V3 Integer),
128-- [V3 Integer])
129--component name col dim orient pos = (name, col, dim, orient, pos, dim ^. orient)
130
131--component name col dim orient pos = (name, col, dim, orient, pos, dim ^. orient)
132component
133 :: String
134 -> String
135 -> V3 Double
136 -> ((V3 Double -> Const (V3 Double) (V3 Double))
137 -> V3 Double -> Const (V3 Double) (V3 Double))
138 -> [V3 Double]
139 -> (String, String, V3 Double,
140 (V3 Double -> Const (V3 Double) (V3 Double))
141 -> V3 Double -> Const (V3 Double) (V3 Double),
142 [V3 Double])
143component name col dim orient pos = (name, col, dim, orient, pos)
144--component name col dim orient pos = (name :: String, col :: String, dim :: V3 Double, orient, pos :: [V3 Double])
145
146ass = assemble [component "shelves" "neh" (V3 1 8 36) _xyz [V3 0 0 0, V3 0 0 10] ]
105 147
106--data CName = String
107
108--data Component name dim pos = (
109
110-- data Component = Component {
111-- name :: String,
112-- , dim :: V3 Double
113-- , orient ::
114
115-- ass ::
116-- ass v = show v
117
118-- maybeMore :: Either a [a]
119-- maybeMore x = either [x] x x
120
121-- count :: Either a0 [a1] -> Int
122-- count (Left a) = length [a]
123-- count (Right b) = length b
124
125-- maybeMore :: Maybe [a] -> [a]
126-- maybeMore x = [x]
127-- maybeMore [x] = [x]
128
129-- maybeMore :: Maybe [a] -> [a]
130-- maybeMore x = fromMaybe
131
132
133
134-- data Many = Left [a] | Right b
135-- maybeMany :: Many -> Int
136-- maybeMany Left x = x
137-- maybeMany Right x = [x]
138
139-- data AlwaysMany = FromOne a | AlreadyMany [a]
140-- alwaysMany (FromOne x) = [x]
141-- alwaysMany (AlreadyMany x) = x
142
143-- data AlwaysMany a b = Left a | Right b
144-- data Many a = Either [a]
145
146-- alwaysMany :: Many a -> Int
147-- alwaysMany (Right x) = x
148
149-- type OnceOne a = [a]
150-- type AlreadyMany a = [a]
151-- data AlwaysMany a = OnceOne a | AlreadyMany a deriving (Foldable, Eq, Ord)
152
153-- alwaysMany :: AlwaysMany a -> Int
154-- alwaysMany x = length x
155
156
157-- data AlwaysMany a = Maybe [a] | Just [a]
158-- alwaysMany :: AlwaysMany a -> [a]
159-- alwaysMany x = x
160
161
162-- count x
163-- -- where y = if isLeft x then [x] else x
164-- | isLeft x = length [x]
165-- | otherwise = length x
166
167-- which :: Either String Int -> String
168-- which x = either show show x
169-- which Left x = "string"
170-- which Right x = "int"
171 148
172 149
173-- evenly spread <boardCount> number of boards (of the width <boardWidth>) in <span> space 150-- evenly spread <boardCount> number of boards (of the width <boardWidth>) in <span> space