Skip to content

Commit

Permalink
extopenscad: add projection(cut=true) calling slice
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Jan 4, 2024
1 parent 0d31e8c commit 4095f7e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Graphics/Implicit/ExtOpenScad/Primitives.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Graphics.Implicit.ExtOpenScad.Util.OVal (OTypeMirror, caseOType, divideOb
import Graphics.Implicit.ExtOpenScad.Util.StateC (errorC)

-- Note the use of a qualified import, so we don't have the functions in this file conflict with what we're importing.
import qualified Graphics.Implicit.Primitives as Prim (withRounding, sphere, rect3, rect, translate, circle, polygon, extrude, cylinder2, union, unionR, intersect, intersectR, difference, differenceR, rotate, transform, rotate3V, rotate3, transform3, scale, extrudeM, rotateExtrude, shell, mirror, pack3, pack2, torus, ellipsoid, cone)
import qualified Graphics.Implicit.Primitives as Prim (withRounding, sphere, rect3, rect, translate, circle, polygon, extrude, cylinder2, union, unionR, intersect, intersectR, difference, differenceR, rotate, slice, transform, rotate3V, rotate3, transform3, scale, extrudeM, rotateExtrude, shell, mirror, pack3, pack2, torus, ellipsoid, cone)

import Control.Monad (when, mplus)

Expand Down Expand Up @@ -70,6 +70,7 @@ primitiveModules =
, onModIze extrude [([("height", hasDefault), ("center", hasDefault), ("twist", hasDefault), ("scale", hasDefault), ("translate", hasDefault), ("r", hasDefault)], requiredSuite)]
, onModIze rotateExtrude [([("angle", hasDefault), ("r", hasDefault), ("translate", hasDefault), ("rotate", hasDefault)], requiredSuite)]
, onModIze shell [([("w", noDefault)], requiredSuite)]
, onModIze projection [([("cut", hasDefault)], requiredSuite)]
, onModIze pack [([("size", noDefault), ("sep", noDefault)], requiredSuite)]
, onModIze unit [([("unit", noDefault)], requiredSuite)]
, onModIze mirror [([("x", noDefault), ("y", noDefault), ("z", noDefault)], requiredSuite), ([("v", noDefault)], requiredSuite)]
Expand Down Expand Up @@ -574,6 +575,20 @@ shell = moduleWithSuite "shell" $ \_ children -> do
`doc` "width of the shell..."
pure $ pure $ objMap (Prim.shell w) (Prim.shell w) children

projection :: (Symbol, SourcePosition -> [OVal] -> ArgParser (StateC [OVal]))
projection = moduleWithSuite "projection" $ \sourcePosition children -> do
example "projection(cut=true) sphere(10);"
-- arguments
cut :: Bool <- argument "cut"
`defaultTo` False
`doc` "Cut with a plane at z=0"
pure $
if cut
then pure $ obj3DownMap Prim.slice children
else do
errorC sourcePosition "projection(cut=false) is not yet implemented"
pure children

-- Not a permanent solution! Breaks if can't pack.
pack :: (Symbol, SourcePosition -> [OVal] -> ArgParser (StateC [OVal]))
pack = moduleWithSuite "pack" $ \sourcePosition children -> do
Expand Down Expand Up @@ -705,6 +720,12 @@ obj2UpMap obj2upmod (x:xs) = case x of
a -> a : obj2UpMap obj2upmod xs
obj2UpMap _ [] = []

obj3DownMap :: (SymbolicObj3 -> SymbolicObj2) -> [OVal] -> [OVal]
obj3DownMap obj3downmod (x:xs) = case x of
OObj3 obj3 -> OObj2 (obj3downmod obj3) : obj3DownMap obj3downmod xs
a -> a : obj3DownMap obj3downmod xs
obj3DownMap _ [] = []

toInterval :: Bool -> -> ℝ2
toInterval center h =
if center
Expand Down

0 comments on commit 4095f7e

Please sign in to comment.