1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
{-# LANGUAGE FlexibleContexts #-}
module OpenSCAD.Carpentry
(
place
, placeAlong
, v3box
, v3translate
) where
import Control.Lens
import Graphics.OpenSCAD
import Linear.V3
v3box :: R3 t => t Double -> Model3d
v3box v = box (v ^. _x) (v ^. _y) (v ^. _z)
v3translate :: (Vector (c, c, c), R3 t) => t c -> Model (c, c, c) -> Model (c, c, c)
v3translate v m = translate (v ^. _x, v ^. _y, v ^. _z) $ m
-- ^ doesn't work ??
place :: (R3 t1, R3 t2) => t2 Double -> [t1 Double] -> [Model (Double, Double, Double)]
place board positions = map boardAt positions
where
boardAt p = translate (p ^. _x, p ^. _y, p ^. _z) $ v3box board
-- boardAt p = v3translate p $ v3box board
-- placeAlong (V3 2 4 16) (V3 0 0 0) (_x +~ 4) _x (<= 20)
placeAlong :: (R3 t1, R3 t2) => t2 Double -> t1 Double -> (t1 Double -> t1 Double) -> ((t3 -> Const t3 t3) -> t1 Double -> Const t3 (t1 Double)) -> (t3 -> Bool) -> [Model (Double, Double, Double)]
placeAlong board initial shift targ cond =
place board positions
where positions =
let next x =
let p = x & shift
in if cond (p ^. targ)
then p : next p
else []
in initial : next initial
|