-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A math-inspired programmatic 2D & 3D CAD system. -- -- An OpenSCAD execution engine for generating models in STL and many -- other formats. @package implicit @version 0.4.1.0 module Graphics.Implicit.Export.OutputFormat -- | A type serving to enumerate our output formats. data OutputFormat SVG :: OutputFormat SCAD :: OutputFormat PNG :: OutputFormat GCode :: OutputFormat ASCIISTL :: OutputFormat STL :: OutputFormat THREEJS :: OutputFormat OBJ :: OutputFormat DXF :: OutputFormat -- | Lookup an output format for a given output file. Throw an error if one -- cannot be found. guessOutputFormat :: FilePath -> OutputFormat -- | A list mapping file extensions to output formats. formatExtensions :: [(String, OutputFormat)] -- | Get filename extension for OutputFormat formatExtension :: OutputFormat -> String -- | All supported 2D formats formats2D :: [OutputFormat] -- | True for 2D capable OutputFormats formatIs2D :: OutputFormat -> Bool -- | Default 2D output format def2D :: OutputFormat -- | All supported 3D formats formats3D :: [OutputFormat] -- | True for 3D capable OutputFormats formatIs3D :: OutputFormat -> Bool -- | Default 3D output format def3D :: OutputFormat instance GHC.Classes.Eq Graphics.Implicit.Export.OutputFormat.OutputFormat instance GHC.Show.Show Graphics.Implicit.Export.OutputFormat.OutputFormat instance Data.Default.Class.Default Graphics.Implicit.Export.OutputFormat.OutputFormat instance GHC.Read.Read Graphics.Implicit.Export.OutputFormat.OutputFormat module Graphics.Implicit.Export.Render.GetLoops -- | The goal of getLoops is to extract loops from a list of segments. The -- input is a list of segments. The output a list of loops, where each -- loop is a list of segments, which each piece representing a "side". -- -- For example: Given points [[1,2],[5,1],[2,3,4,5], ... ] notice that -- there is a loop 1,2,3,4,5... repeat But we give the output [ [ -- [1,2], [2,3,4,5], [5,1] ], ... ] so that we have the loop, and also -- knowledge of how the list is built (the "sides" of it). getLoops :: Eq a => [[a]] -> Maybe [[[a]]] module Graphics.Implicit.Definitions newtype Fastℕ Fastℕ :: Int -> Fastℕ fromFastℕ :: FastN n => Fastℕ -> n toFastℕ :: FastN n => n -> Fastℕ data ℕ fromℕ :: N n => ℕ -> n toℕ :: N n => n -> ℕ -- | A type synonym for Double. When used in the context of -- positions or sizes, measured in units of millimeters. When used as in -- the context of a rotation, measured in radians. type ℝ = Double -- | A pair of two Doubles. When used as an area or position vector, -- measured in millimeters squared. type ℝ2 = V2 ℝ -- | A triple of Doubles. When used as a volume or position vector, -- measured in millimeters cubed. When used as a rotation, interpreted as -- Euler angles measured in radians. type ℝ3 = V3 ℝ newtype ℝ3' ℝ3' :: V3 ℝ -> ℝ3' -- | A give up point for dividing ℝs, and for the maximum difference -- between abs(n) and abs(-n). minℝ :: ℝ -- | Add multiply and divide operators for two ℝ2s or ℝ3s. class ComponentWiseMultable a (⋯*) :: ComponentWiseMultable a => a -> a -> a (⋯/) :: ComponentWiseMultable a => a -> a -> a -- | A chain of line segments, as in SVG or DXF. eg. [(0,0), (0.5,1), -- (1,0)] ---> / FIXME: May not be empty. expose to type system. newtype Polyline Polyline :: [ℝ2] -> Polyline [getSegments] :: Polyline -> [ℝ2] -- | A triangle in 2D space (a,b,c). newtype Polytri Polytri :: (ℝ2, ℝ2, ℝ2) -> Polytri -- | A triangle in 3D space (a,b,c) = a triangle with vertices a, b and c newtype Triangle Triangle :: (ℝ3, ℝ3, ℝ3) -> Triangle -- | A triangle ((v1,n1),(v2,n2),(v3,n3)) has vertices v1, v2, v3 with -- corresponding normals n1, n2, and n3 newtype NormedTriangle NormedTriangle :: ((ℝ3, ℝ3), (ℝ3, ℝ3), (ℝ3, ℝ3)) -> NormedTriangle -- | A triangle mesh is a bunch of triangles, attempting to be a surface. newtype TriangleMesh TriangleMesh :: [Triangle] -> TriangleMesh [getTriangles] :: TriangleMesh -> [Triangle] -- | A normed triangle mesh is a mesh of normed triangles. newtype NormedTriangleMesh NormedTriangleMesh :: [NormedTriangle] -> NormedTriangleMesh [getNormedTriangles] :: NormedTriangleMesh -> [NormedTriangle] -- | A 2D object. type Obj2 = (ℝ2 -> ℝ) -- | A 3D object. type Obj3 = (ℝ3 -> ℝ) -- | A 2D box. type Box2 = (ℝ2, ℝ2) -- | A 3D box. type Box3 = (ℝ3, ℝ3) -- | A Box containing a 2D object. type Boxed2 a = (a, Box2) -- | A Box containing a 3D object. type Boxed3 a = (a, Box3) -- | A Boxed 2D object type BoxedObj2 = Boxed2 Obj2 -- | A Boxed 3D object type BoxedObj3 = Boxed3 Obj3 -- | Means of constructing symbolic objects that are common between the 2D -- and 3D case. This type is parameterized on obj and -- vec so that SymbolicObj2 and SymbolicObj3 can -- instantiate it for their own purposes. data SharedObj obj f a -- | The empty object Empty :: SharedObj obj f a -- | The entirely full object Full :: SharedObj obj f a Complement :: obj -> SharedObj obj f a UnionR :: ℝ -> [obj] -> SharedObj obj f a DifferenceR :: ℝ -> obj -> [obj] -> SharedObj obj f a IntersectR :: ℝ -> [obj] -> SharedObj obj f a Translate :: f a -> obj -> SharedObj obj f a Scale :: f a -> obj -> SharedObj obj f a -- | Mirror across the line whose normal is defined by the vector Mirror :: f a -> obj -> SharedObj obj f a Outset :: ℝ -> obj -> SharedObj obj f a Shell :: ℝ -> obj -> SharedObj obj f a EmbedBoxedObj :: (f a -> a, (f a, f a)) -> SharedObj obj f a WithRounding :: ℝ -> obj -> SharedObj obj f a -- | A 2-dimensional vector -- --
-- >>> pure 1 :: V2 Int -- V2 1 1 ---- --
-- >>> V2 1 2 + V2 3 4 -- V2 4 6 ---- --
-- >>> V2 1 2 * V2 3 4 -- V2 3 8 ---- --
-- >>> sum (V2 1 2) -- 3 --data V2 a V2 :: !a -> !a -> V2 a -- | A 3-dimensional vector data V3 a V3 :: !a -> !a -> !a -> V3 a -- | A symbolic 2D object format. We want to have symbolic objects so that -- we can accelerate rendering & give ideal meshes for simple cases. data SymbolicObj2 Square :: ℝ2 -> SymbolicObj2 Circle :: ℝ -> SymbolicObj2 Polygon :: [ℝ2] -> SymbolicObj2 Rotate2 :: ℝ -> SymbolicObj2 -> SymbolicObj2 Transform2 :: M33 ℝ -> SymbolicObj2 -> SymbolicObj2 Shared2 :: SharedObj SymbolicObj2 V2 ℝ -> SymbolicObj2 -- | A symbolic 3D format! data SymbolicObj3 Cube :: ℝ3 -> SymbolicObj3 Sphere :: ℝ -> SymbolicObj3 Cylinder :: ℝ -> ℝ -> ℝ -> SymbolicObj3 Rotate3 :: Quaternion ℝ -> SymbolicObj3 -> SymbolicObj3 Transform3 :: M44 ℝ -> SymbolicObj3 -> SymbolicObj3 Extrude :: SymbolicObj2 -> ℝ -> SymbolicObj3 ExtrudeM :: Either ℝ (ℝ -> ℝ) -> ExtrudeMScale -> Either ℝ2 (ℝ -> ℝ2) -> SymbolicObj2 -> Either ℝ (ℝ2 -> ℝ) -> SymbolicObj3 RotateExtrude :: ℝ -> Either ℝ2 (ℝ -> ℝ2) -> Either ℝ (ℝ -> ℝ) -> SymbolicObj2 -> SymbolicObj3 ExtrudeOnEdgeOf :: SymbolicObj2 -> SymbolicObj2 -> SymbolicObj3 Shared3 :: SharedObj SymbolicObj3 V3 ℝ -> SymbolicObj3 data ExtrudeMScale C1 :: ℝ -> ExtrudeMScale C2 :: ℝ2 -> ExtrudeMScale Fn :: (ℝ -> Either ℝ ℝ2) -> ExtrudeMScale newtype ObjectContext ObjectContext :: ℝ -> ObjectContext [objectRounding] :: ObjectContext -> ℝ defaultObjectContext :: ObjectContext -- | Convert from our Integral to our Rational. fromℕtoℝ :: ℕ -> ℝ -- | Convert from our Fast Integer (int32) to ℝ. fromFastℕtoℝ :: Fastℕ -> ℝ -- | Convert from our rational to a float, for output to a file. fromℝtoFloat :: ℝ -> Float toScaleFn :: ExtrudeMScale -> ℝ -> ℝ2 isScaleID :: ExtrudeMScale -> Bool -- | Convert a Quaternion to its constituent euler angles. -- -- From -- https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Source_code_2 quaternionToEuler :: RealFloat a => Quaternion a -> V3 a -- | Returns True if any component of a foldable functor is zero hasZeroComponent :: (Foldable f, Num a, Eq a) => f a -> Bool instance GHC.Generics.Generic (Graphics.Implicit.Definitions.SharedObj obj f a) instance GHC.Show.Show Graphics.Implicit.Definitions.ObjectContext instance GHC.Classes.Ord Graphics.Implicit.Definitions.ObjectContext instance GHC.Classes.Eq Graphics.Implicit.Definitions.ObjectContext instance GHC.Generics.Generic Graphics.Implicit.Definitions.SymbolicObj2 instance GHC.Generics.Generic Graphics.Implicit.Definitions.ExtrudeMScale instance GHC.Generics.Generic Graphics.Implicit.Definitions.SymbolicObj3 instance GHC.Show.Show Graphics.Implicit.Definitions.SymbolicObj3 instance GHC.Base.Semigroup Graphics.Implicit.Definitions.SymbolicObj3 instance GHC.Base.Monoid Graphics.Implicit.Definitions.SymbolicObj3 instance GHC.Show.Show Graphics.Implicit.Definitions.ExtrudeMScale instance GHC.Show.Show Graphics.Implicit.Definitions.SymbolicObj2 instance GHC.Base.Semigroup Graphics.Implicit.Definitions.SymbolicObj2 instance GHC.Base.Monoid Graphics.Implicit.Definitions.SymbolicObj2 instance (GHC.Show.Show obj, GHC.Show.Show (f a)) => GHC.Show.Show (Graphics.Implicit.Definitions.SharedObj obj f a) instance GHC.Show.Show Graphics.Implicit.Definitions.Blackhole instance Control.DeepSeq.NFData Graphics.Implicit.Definitions.TriangleMesh instance Control.DeepSeq.NFData Graphics.Implicit.Definitions.NormedTriangle instance Control.DeepSeq.NFData Graphics.Implicit.Definitions.Triangle instance Control.DeepSeq.NFData Graphics.Implicit.Definitions.Polytri instance Control.DeepSeq.NFData Graphics.Implicit.Definitions.Polyline instance Graphics.Implicit.Definitions.ComponentWiseMultable Graphics.Implicit.Definitions.ℝ2 instance Graphics.Implicit.Definitions.ComponentWiseMultable Graphics.Implicit.Definitions.ℝ3 instance (Graphics.Implicit.Definitions.ℝ3' GHC.Types.~ t) => Control.Lens.Wrapped.Rewrapped Graphics.Implicit.Definitions.ℝ3' t instance Control.Lens.Wrapped.Wrapped Graphics.Implicit.Definitions.ℝ3' instance GHC.Classes.Eq Graphics.Implicit.Definitions.ℝ3' module Graphics.Implicit.ExtOpenScad.Definitions -- | Handles parsing arguments to built-in modules data ArgParser a -- | For actual argument entries: AP (argument name) (default) (doc) -- (next Argparser...) AP :: Symbol -> Maybe OVal -> Text -> (OVal -> ArgParser a) -> ArgParser a -- | For returns: APTerminator (return value) APTerminator :: a -> ArgParser a -- | For failure: APFail (error message) APFail :: Text -> ArgParser a -- | An example, then next APExample :: Text -> ArgParser a -> ArgParser a -- | A string to run as a test, then invariants for the results, then next APTest :: Text -> [TestInvariant] -> ArgParser a -> ArgParser a -- | A branch where there are a number of possibilities for the parser -- underneath APBranch :: [ArgParser a] -> ArgParser a newtype Symbol Symbol :: Text -> Symbol data Pattern Name :: Symbol -> Pattern ListP :: [Pattern] -> Pattern Wild :: Pattern -- | An expression. data Expr Var :: Symbol -> Expr LitE :: OVal -> Expr ListE :: [Expr] -> Expr LamE :: [Pattern] -> Expr -> Expr (:$) :: Expr -> [Expr] -> Expr -- | A statement, along with the line, column number, and file it is found -- at. data StatementI StatementI :: SourcePosition -> Statement StatementI -> StatementI data Statement st Include :: Text -> Bool -> Statement st (:=) :: Pattern -> Expr -> Statement st If :: Expr -> [st] -> [st] -> Statement st NewModule :: Symbol -> [(Symbol, Maybe Expr)] -> [st] -> Statement st ModuleCall :: Symbol -> [(Maybe Symbol, Expr)] -> [st] -> Statement st DoNothing :: Statement st -- | Objects for our OpenSCAD-like language data OVal OUndefined :: OVal OError :: Text -> OVal OBool :: Bool -> OVal ONum :: ℝ -> OVal OList :: [OVal] -> OVal OString :: Text -> OVal OFunc :: (OVal -> OVal) -> OVal OIO :: IO OVal -> OVal OUModule :: Symbol -> Maybe [(Symbol, Bool)] -> (VarLookup -> ArgParser (StateC [OVal])) -> OVal ONModule :: Symbol -> (SourcePosition -> [OVal] -> ArgParser (StateC [OVal])) -> [([(Symbol, Bool)], Maybe Bool)] -> OVal OVargsModule :: Symbol -> (Symbol -> SourcePosition -> [(Maybe Symbol, OVal)] -> [StatementI] -> ([StatementI] -> StateC ()) -> StateC ()) -> OVal OObj3 :: SymbolicObj3 -> OVal OObj2 :: SymbolicObj2 -> OVal newtype TestInvariant EulerCharacteristic :: ℕ -> TestInvariant -- | In order to not propagate Parsec or other modules around, create our -- own source position type for the AST. data SourcePosition SourcePosition :: Fastℕ -> Fastℕ -> FilePath -> SourcePosition type StateC a = ImplicitCadM ScadOpts [Message] CompState IO a -- | The state of computation. data CompState CompState :: VarLookup -> [OVal] -> FilePath -> CompState -- | A hash of variables and functions. [scadVars] :: CompState -> VarLookup -- | The result of geometry generating functions. [oVals] :: CompState -> [OVal] -- | The path we are looking for includes in. [sourceDir] :: CompState -> FilePath newtype ImplicitCadM r w s m a ImplicitCadM :: ReaderT r (WriterT w (StateT s m)) a -> ImplicitCadM r w s m a [unImplicitCadM] :: ImplicitCadM r w s m a -> ReaderT r (WriterT w (StateT s m)) a newtype VarLookup VarLookup :: Map Symbol OVal -> VarLookup -- | An individual message. data Message Message :: MessageType -> SourcePosition -> Text -> Message -- | The types of messages the execution engine can send back to the -- application. data MessageType TextOut :: MessageType Warning :: MessageType Error :: MessageType SyntaxError :: MessageType Compatibility :: MessageType Unimplemented :: MessageType -- | Options changing the behavior of the extended OpenScad engine. data ScadOpts ScadOpts :: Bool -> Bool -> ScadOpts [openScadCompatibility] :: ScadOpts -> Bool [importsAllowed] :: ScadOpts -> Bool -- | For programs using this API to perform variable lookups, after -- execution of an escad has completed. lookupVarIn :: Text -> VarLookup -> Maybe OVal varUnion :: VarLookup -> VarLookup -> VarLookup runImplicitCadM :: Monad m => r -> s -> ImplicitCadM r w s m a -> m (a, w, s) type CanCompState m = CanCompState' ScadOpts [Message] CompState m type CanCompState' r w s m = (MonadReader r m, MonadWriter w m, MonadState s m, MonadIO m) instance GHC.Base.Functor m => GHC.Base.Functor (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => GHC.Base.Applicative (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => GHC.Base.Monad (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, Control.Monad.IO.Class.MonadIO m) => Control.Monad.IO.Class.MonadIO (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.State.Class.MonadState s (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Writer.Class.MonadWriter w (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance (GHC.Base.Monoid w, GHC.Base.Monad m) => Control.Monad.Reader.Class.MonadReader r (Graphics.Implicit.ExtOpenScad.Definitions.ImplicitCadM r w s m) instance GHC.Classes.Ord Graphics.Implicit.ExtOpenScad.Definitions.Symbol instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.Symbol instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.Symbol instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.Pattern instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.Pattern instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.SourcePosition instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.MessageType instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.MessageType instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.Message instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.ScadOpts instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.ScadOpts instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.TestInvariant instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.CompState instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.VarLookup instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.VarLookup instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.Expr instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.Expr instance GHC.Classes.Eq st => GHC.Classes.Eq (Graphics.Implicit.ExtOpenScad.Definitions.Statement st) instance GHC.Show.Show st => GHC.Show.Show (Graphics.Implicit.ExtOpenScad.Definitions.Statement st) instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.StatementI instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.StatementI instance GHC.Base.Functor Graphics.Implicit.ExtOpenScad.Definitions.ArgParser instance GHC.Base.Applicative Graphics.Implicit.ExtOpenScad.Definitions.ArgParser instance GHC.Base.Monad Graphics.Implicit.ExtOpenScad.Definitions.ArgParser instance GHC.Base.MonadPlus Graphics.Implicit.ExtOpenScad.Definitions.ArgParser instance GHC.Base.Alternative Graphics.Implicit.ExtOpenScad.Definitions.ArgParser instance GHC.Classes.Eq Graphics.Implicit.ExtOpenScad.Definitions.OVal instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.OVal instance Data.Default.Class.Default Graphics.Implicit.ExtOpenScad.Definitions.ScadOpts instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.Message instance GHC.Show.Show Graphics.Implicit.ExtOpenScad.Definitions.SourcePosition module Graphics.Implicit.ExtOpenScad.Parser.Expr expr0 :: GenParser Char st Expr module Graphics.Implicit.ExtOpenScad.Parser.Statement -- | all of the token parsers are lexemes which consume all trailing spaces -- nicely. | This leaves us to deal only with the first spaces in the -- file. parseProgram :: SourceName -> String -> Either ParseError [StatementI] module Graphics.Implicit.Export.TriangleMeshFormats -- | Generate an STL file is ASCII format. stl :: TriangleMesh -> Text -- | Generate an STL file in it's binary format. binaryStl :: TriangleMesh -> ByteString jsTHREE :: TriangleMesh -> Text module Graphics.Implicit.Export.PolylineFormats svg :: [Polyline] -> Text -- | Gcode generation for the laser cutter in HackLab. Complies with -- https://ws680.nist.gov/publication/get_pdf.cfm?pub_id=823374 -- FIXME: parameters would be nice. hacklabLaserGCode :: [Polyline] -> Text -- | DXF2 export in 2D. conforming to AutoCAD R12/13. dxf2 :: [Polyline] -> Text module Graphics.Implicit.Export.NormedTriangleMeshFormats -- | Generate a .obj format file from a NormedTriangleMesh see: -- https://en.wikipedia.org/wiki/Wavefront_.obj_file obj :: NormedTriangleMesh -> Text module Graphics.Implicit.MathUtil -- | Rounded Maximum Consider max(x,y) = 0, the generated curve has a -- square-like corner. We replace it with a quarter of a circle -- -- NOTE: rmax is not associative! rmax :: ℝ -> ℝ -> ℝ -> ℝ -- | Like rmax, but on a list instead of two. Just as maximum is. The -- implementation is to take the maximum two and rmax those. rmaximum :: ℝ -> [ℝ] -> ℝ -- | Like rmin but on a list. rminimum :: ℝ -> [ℝ] -> ℝ -- | The distance a point p is from a line segment (a,b) distFromLineSeg :: ℝ2 -> (ℝ2, ℝ2) -> ℝ -- | Pack the given objects in a box the given size. pack :: Box2 -> ℝ -> [(Box2, a)] -> ([(ℝ2, a)], [(Box2, a)]) box3sWithin :: ℝ -> (ℝ3, ℝ3) -> (ℝ3, ℝ3) -> Bool -- | Reflect a vector across a hyperplane defined by its normal vector. -- -- From -- https://en.wikipedia.org/wiki/Reflection_(mathematics)#Reflection_through_a_hyperplane_in_n_dimensions reflect :: (Num (f a), Fractional a, Metric f) => f a -> f a -> f a -- | Lift a function over V3 into a function over ℝ3. alaV3 :: (V3 a -> V3 a) -> (a, a, a) -> (a, a, a) packV3 :: (a, a, a) -> V3 a unpackV3 :: V3 a -> (a, a, a) -- | Haskell's standard library doesn't make floating-point infinity -- available in any convenient way, so we define it here. infty :: Fractional t => t module Graphics.Implicit.Primitives -- | Translate an object by a vector of appropriate dimension. translate :: Object obj f a => f a -> obj -> obj -- | Mirror an object across the hyperplane whose normal is a given vector. mirror :: Object obj f a => f a -> obj -> obj -- | Scale an object scale :: Object obj f a => f a -> obj -> obj -- | Outset of an object. outset :: Object obj f a => ℝ -> obj -> obj -- | Complement an Object complement :: Object obj f a => obj -> obj union :: Object obj f a => [obj] -> obj intersect :: Object obj f a => [obj] -> obj difference :: Object obj f a => obj -> [obj] -> obj -- | Rounded union unionR :: Object obj f a => ℝ -> [obj] -> obj -- | Rounded minimum intersectR :: Object obj f a => ℝ -> [obj] -> obj -- | Rounded difference differenceR :: Object obj f a => ℝ -> obj -> [obj] -> obj -- | Make a shell of an object. shell :: Object obj f a => ℝ -> obj -> obj -- | Get the bounding box an object getBox :: Object obj f a => obj -> (f a, f a) -- | Get the implicit function for an object getImplicit :: Object obj f a => obj -> f a -> a -- | Get the implicit function for an object getImplicit' :: Object obj f a => ObjectContext -> obj -> f a -> a -- | Extrude a 2d object upwards. The current object-rounding value set by -- withRounding is used to round the caps, but is not used by the -- 2D object. extrude :: SymbolicObj2 -> ℝ -> SymbolicObj3 -- | The current object-rounding value set by withRounding is used -- to round the caps, but is not used by the 2D object. extrudeM :: Either ℝ (ℝ -> ℝ) -> ExtrudeMScale -> Either ℝ2 (ℝ -> ℝ2) -> SymbolicObj2 -> Either ℝ (ℝ2 -> ℝ) -> SymbolicObj3 extrudeOnEdgeOf :: SymbolicObj2 -> SymbolicObj2 -> SymbolicObj3 sphere :: ℝ -> SymbolicObj3 -- | A cube cube :: Bool -> ℝ3 -> SymbolicObj3 -- | A rectangular prism rect3 :: ℝ3 -> ℝ3 -> SymbolicObj3 circle :: ℝ -> SymbolicObj2 cylinder :: ℝ -> ℝ -> SymbolicObj3 -- | A conical frustum --- ie. a cylinder with different radii at either -- end. cylinder2 :: ℝ -> ℝ -> ℝ -> SymbolicObj3 cone :: ℝ -> ℝ -> SymbolicObj3 torus :: ℝ -> ℝ -> SymbolicObj3 ellipsoid :: ℝ -> ℝ -> ℝ -> SymbolicObj3 -- | A square square :: Bool -> ℝ2 -> SymbolicObj2 -- | A rectangle rect :: ℝ2 -> ℝ2 -> SymbolicObj2 -- | A 2D polygon polygon :: [ℝ2] -> SymbolicObj2 rotateExtrude :: ℝ -> Either ℝ2 (ℝ -> ℝ2) -> Either ℝ (ℝ -> ℝ) -> SymbolicObj2 -> SymbolicObj3 -- | Rotate a 3D object via an Euler angle, measured in radians, along the -- world axis. rotate3 :: ℝ3 -> SymbolicObj3 -> SymbolicObj3 rotateQ :: Quaternion ℝ -> SymbolicObj3 -> SymbolicObj3 -- | Rotate a 3D object along an arbitrary axis. rotate3V :: ℝ -> ℝ3 -> SymbolicObj3 -> SymbolicObj3 -- | Transform a 3D object using a 4x4 matrix representing affine -- transformation (OpenSCAD multmatrix) transform3 :: M44 ℝ -> SymbolicObj3 -> SymbolicObj3 -- | Attempt to pack multiple 3D objects into a fixed area. The z -- coordinate of each object is dropped, and the resulting packed objects -- will all be on the same plane. -- -- FIXME: shouldn't this pack into a 3d area, or have a 3d equivalent? pack3 :: ℝ2 -> ℝ -> [SymbolicObj3] -> Maybe SymbolicObj3 rotate :: ℝ -> SymbolicObj2 -> SymbolicObj2 -- | Transform a 2D object using a 3x3 matrix representing affine -- transformation (OpenSCAD multmatrix) transform :: M33 ℝ -> SymbolicObj2 -> SymbolicObj2 -- | Attempt to pack multiple 2D objects into a fixed area. pack2 :: ℝ2 -> ℝ -> [SymbolicObj2] -> Maybe SymbolicObj2 implicit :: Object obj f a => (f a -> a) -> (f a, f a) -> obj -- | The object that fills no space emptySpace :: Object obj f a => obj -- | The object that fills the entire space fullSpace :: Object obj f a => obj -- | Set the current object-rounding value for the given object. The -- rounding value is measured in units of distance, and describes the -- radius of rounded corners. -- -- This can be used to change the shape of more primitive forms, for -- example, we can make a cube with rounded corners via withRounding -- 5 (cube True 20). -- -- withRounding r obj applies the rounding r -- all primitives objects in obj, so long as they have -- the same dimensionality. That is to say, the current object-rounding -- value set in 3D will not apply to extruded 2D shapes. withRounding :: Object obj f a => ℝ -> obj -> obj -- | A Prism' for including SharedObjs in obj. -- Prefer using Shared instead of this. _Shared :: Object obj f a => Prism' obj (SharedObj obj f a) -- | A pattern that abstracts over Shared2 and Shared3. pattern Shared :: Object obj f a => SharedObj obj f a -> obj -- | Operations available on both 2D and 3D objects. The obvious omission -- of rotation operations from this class are a technical limitation, and -- are instead provided by rotate and rotate3. -- -- Library users shouldn't need to provide new instances of this class. class (Applicative f, Eq a, Eq (f a), Foldable f, Num a, Num (f a)) => Object obj f a | obj -> f a where { -- | Type representing a space this object belongs to. V3 for 3D objects, -- V2 for 2D type Space obj :: Type -> Type; } -- | Canonicalization function used to rewrite / normalize abstract syntax -- tree representing an object canonicalize :: Object obj f a => obj -> obj instance Graphics.Implicit.Primitives.Object Graphics.Implicit.Definitions.SymbolicObj2 Linear.V2.V2 Graphics.Implicit.Definitions.ℝ instance Graphics.Implicit.Primitives.Object Graphics.Implicit.Definitions.SymbolicObj3 Linear.V3.V3 Graphics.Implicit.Definitions.ℝ module Graphics.Implicit.ObjectUtil getImplicit3 :: ObjectContext -> SymbolicObj3 -> Obj3 getImplicit2 :: ObjectContext -> SymbolicObj2 -> Obj2 getBox3 :: SymbolicObj3 -> Box3 getBox2 :: SymbolicObj2 -> Box2 -- | This module implements canonicalization pass that * eliminates -- identities * merges consecutive transformations like transform . -- transform into one * prevents invalid transformations like scaling by -- zero that would otherwise result in NaNs down the pipe * turns -- degenerate objects into empty space (i.e. circle 0, cube (pure 0)) module Graphics.Implicit.Canon -- | Canonicalize SymbolicObj2 tree canonicalize2 :: SymbolicObj2 -> SymbolicObj2 -- | Canonicalize SymbolicObj3 tree canonicalize3 :: SymbolicObj3 -> SymbolicObj3 -- | Map over SymbolicObj2 and its underlying shared objects -- -- This function is co-recursive with fmapSharedObj to achieve -- deep mapping over objects nested in Shared2 constructor fmapObj2 :: (SymbolicObj2 -> SymbolicObj2) -> (SymbolicObj3 -> SymbolicObj3) -> (forall obj f a. Object obj f a => obj -> obj) -> SymbolicObj2 -> SymbolicObj2 -- | Map over SymbolicObj3 and its underlying shared objects -- -- This function is co-recursive with fmapSharedObj to achieve -- deep mapping over objects nested in Shared3 constructor fmapObj3 :: (SymbolicObj3 -> SymbolicObj3) -> (SymbolicObj2 -> SymbolicObj2) -> (forall obj f a. Object obj f a => obj -> obj) -> SymbolicObj3 -> SymbolicObj3 -- | Map over SharedObj and its underlying objects -- -- This resembles bimap from Bifunctor but the structure of SharedObj -- doesn't allow us to define Bifunctor instance as we need to map over -- the first type argument (obj) and not f and a. fmapSharedObj :: forall obj f a. Object obj f a => (obj -> obj) -> (obj -> obj) -> obj -> obj -- | Rewrite the object tree until it cannot be reduced further rewriteUntilIrreducible :: (Object obj f a, EqObj obj) => (obj -> obj) -> obj -> obj -- | We have to define our own variant of Eq which compares objects when -- possible and returns True when we cannot compare things like functions class EqObj a (=^=) :: EqObj a => a -> a -> Bool instance Graphics.Implicit.Canon.EqObj a => Graphics.Implicit.Canon.EqObj [a] instance (Graphics.Implicit.Canon.EqObj obj, GHC.Classes.Eq (f a)) => Graphics.Implicit.Canon.EqObj (Graphics.Implicit.Definitions.SharedObj obj f a) instance Graphics.Implicit.Canon.EqObj Graphics.Implicit.Definitions.ExtrudeMScale instance Graphics.Implicit.Canon.EqObj Graphics.Implicit.Definitions.SymbolicObj2 instance Graphics.Implicit.Canon.EqObj Graphics.Implicit.Definitions.SymbolicObj3 module Graphics.Implicit.Export.SymbolicFormats scad2 :: ℝ -> SymbolicObj2 -> Text scad3 :: ℝ -> SymbolicObj3 -> Text instance Graphics.Implicit.Export.SymbolicFormats.Build Graphics.Implicit.Definitions.SymbolicObj2 instance Graphics.Implicit.Export.SymbolicFormats.Build Graphics.Implicit.Definitions.SymbolicObj3 module Graphics.Implicit.ExtOpenScad.Primitives -- | The only thing exported here. basically, a list of modules. primitiveModules :: [(Symbol, OVal)] module Graphics.Implicit.ExtOpenScad.Eval.Constant -- | Define variables used during the extOpenScad run. addConstants :: [String] -> Bool -> IO (VarLookup, [Message]) -- | Evaluate an expression. runExpr :: String -> Bool -> (OVal, [Message]) module Graphics.Implicit.ExtOpenScad -- | Small wrapper of our parser to handle parse errors, etc. runOpenscad :: ScadOpts -> [String] -> String -> IO (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message]) module Graphics.Implicit.Export.SymbolicObj3 symbolicGetMesh :: ℝ -> SymbolicObj3 -> TriangleMesh module Graphics.Implicit.Export.SymbolicObj2 symbolicGetContour :: ℝ -> ObjectContext -> SymbolicObj2 -> [Polyline] -- | A module for retrieving approximate represententations of objects. module Graphics.Implicit.Export.DiscreteAproxable -- | There is a discrete way to aproximate this object. eg. Aproximating a -- 3D object with a triangle mesh would be DiscreteApproxable Obj3 -- TriangleMesh class DiscreteAproxable obj aprox discreteAprox :: DiscreteAproxable obj aprox => ℝ -> obj -> aprox instance Graphics.Implicit.Export.DiscreteAproxable.DiscreteAproxable Graphics.Implicit.Definitions.SymbolicObj3 Graphics.Implicit.Definitions.TriangleMesh instance Graphics.Implicit.Export.DiscreteAproxable.DiscreteAproxable Graphics.Implicit.Definitions.SymbolicObj3 Graphics.Implicit.Definitions.NormedTriangleMesh instance Graphics.Implicit.Export.DiscreteAproxable.DiscreteAproxable Graphics.Implicit.Definitions.SymbolicObj3 Codec.Picture.Types.DynamicImage instance Graphics.Implicit.Export.DiscreteAproxable.DiscreteAproxable Graphics.Implicit.Definitions.SymbolicObj2 [Graphics.Implicit.Definitions.Polyline] instance Graphics.Implicit.Export.DiscreteAproxable.DiscreteAproxable Graphics.Implicit.Definitions.SymbolicObj2 Codec.Picture.Types.DynamicImage module Graphics.Implicit.Export -- | Output a file containing a 2D object. export2 :: OutputFormat -> ℝ -> FilePath -> SymbolicObj2 -> IO () -- | Output a file containing a 3D object. export3 :: OutputFormat -> ℝ -> FilePath -> SymbolicObj3 -> IO () -- | A type serving to enumerate our output formats. data OutputFormat SVG :: OutputFormat SCAD :: OutputFormat PNG :: OutputFormat GCode :: OutputFormat ASCIISTL :: OutputFormat STL :: OutputFormat THREEJS :: OutputFormat OBJ :: OutputFormat DXF :: OutputFormat -- | Write an object to a file with LazyText IO, using the given format -- writer function. writeObject :: DiscreteAproxable obj aprox => ℝ -> (aprox -> Text) -> FilePath -> obj -> IO () -- | Serialize an object using the given format writer. No file target is -- implied. formatObject :: DiscreteAproxable obj aprox => ℝ -> (aprox -> Text) -> obj -> Text writeSVG :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO () writeSTL :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO () writeBinSTL :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO () writeOBJ :: DiscreteAproxable obj NormedTriangleMesh => ℝ -> FilePath -> obj -> IO () writeTHREEJS :: DiscreteAproxable obj TriangleMesh => ℝ -> FilePath -> obj -> IO () writeGCodeHacklabLaser :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO () writeDXF2 :: DiscreteAproxable obj [Polyline] => ℝ -> FilePath -> obj -> IO () writeSCAD2 :: ℝ -> FilePath -> SymbolicObj2 -> IO () writeSCAD3 :: ℝ -> FilePath -> SymbolicObj3 -> IO () writePNG :: DiscreteAproxable obj DynamicImage => ℝ -> FilePath -> obj -> IO () module Graphics.Implicit -- | A type synonym for Double. When used in the context of -- positions or sizes, measured in units of millimeters. When used as in -- the context of a rotation, measured in radians. type ℝ = Double -- | A pair of two Doubles. When used as an area or position vector, -- measured in millimeters squared. type ℝ2 = V2 ℝ -- | A triple of Doubles. When used as a volume or position vector, -- measured in millimeters cubed. When used as a rotation, interpreted as -- Euler angles measured in radians. type ℝ3 = V3 ℝ -- | A symbolic 2D object format. We want to have symbolic objects so that -- we can accelerate rendering & give ideal meshes for simple cases. data SymbolicObj2 -- | A symbolic 3D format! data SymbolicObj3 data ExtrudeMScale C1 :: ℝ -> ExtrudeMScale C2 :: ℝ2 -> ExtrudeMScale Fn :: (ℝ -> Either ℝ ℝ2) -> ExtrudeMScale -- | Operations available on both 2D and 3D objects. The obvious omission -- of rotation operations from this class are a technical limitation, and -- are instead provided by rotate and rotate3. -- -- Library users shouldn't need to provide new instances of this class. class (Applicative f, Eq a, Eq (f a), Foldable f, Num a, Num (f a)) => Object obj f a | obj -> f a -- | Translate an object by a vector of appropriate dimension. translate :: Object obj f a => f a -> obj -> obj -- | Scale an object scale :: Object obj f a => f a -> obj -> obj -- | Mirror an object across the hyperplane whose normal is a given vector. mirror :: Object obj f a => f a -> obj -> obj -- | Complement an Object complement :: Object obj f a => obj -> obj union :: Object obj f a => [obj] -> obj -- | Rounded union unionR :: Object obj f a => ℝ -> [obj] -> obj intersect :: Object obj f a => [obj] -> obj -- | Rounded minimum intersectR :: Object obj f a => ℝ -> [obj] -> obj difference :: Object obj f a => obj -> [obj] -> obj -- | Rounded difference differenceR :: Object obj f a => ℝ -> obj -> [obj] -> obj implicit :: Object obj f a => (f a -> a) -> (f a, f a) -> obj -- | Make a shell of an object. shell :: Object obj f a => ℝ -> obj -> obj -- | Outset of an object. outset :: Object obj f a => ℝ -> obj -> obj -- | The object that fills no space emptySpace :: Object obj f a => obj -- | The object that fills the entire space fullSpace :: Object obj f a => obj -- | Set the current object-rounding value for the given object. The -- rounding value is measured in units of distance, and describes the -- radius of rounded corners. -- -- This can be used to change the shape of more primitive forms, for -- example, we can make a cube with rounded corners via withRounding -- 5 (cube True 20). -- -- withRounding r obj applies the rounding r -- all primitives objects in obj, so long as they have -- the same dimensionality. That is to say, the current object-rounding -- value set in 3D will not apply to extruded 2D shapes. withRounding :: Object obj f a => ℝ -> obj -> obj -- | A square square :: Bool -> ℝ2 -> SymbolicObj2 -- | A rectangle rect :: ℝ2 -> ℝ2 -> SymbolicObj2 circle :: ℝ -> SymbolicObj2 -- | A 2D polygon polygon :: [ℝ2] -> SymbolicObj2 rotate :: ℝ -> SymbolicObj2 -> SymbolicObj2 -- | Transform a 2D object using a 3x3 matrix representing affine -- transformation (OpenSCAD multmatrix) transform :: M33 ℝ -> SymbolicObj2 -> SymbolicObj2 -- | Attempt to pack multiple 2D objects into a fixed area. pack2 :: ℝ2 -> ℝ -> [SymbolicObj2] -> Maybe SymbolicObj2 -- | A cube cube :: Bool -> ℝ3 -> SymbolicObj3 -- | A rectangular prism rect3 :: ℝ3 -> ℝ3 -> SymbolicObj3 sphere :: ℝ -> SymbolicObj3 cylinder :: ℝ -> ℝ -> SymbolicObj3 -- | A conical frustum --- ie. a cylinder with different radii at either -- end. cylinder2 :: ℝ -> ℝ -> ℝ -> SymbolicObj3 -- | Rotate a 3D object via an Euler angle, measured in radians, along the -- world axis. rotate3 :: ℝ3 -> SymbolicObj3 -> SymbolicObj3 -- | Rotate a 3D object along an arbitrary axis. rotate3V :: ℝ -> ℝ3 -> SymbolicObj3 -> SymbolicObj3 -- | Attempt to pack multiple 3D objects into a fixed area. The z -- coordinate of each object is dropped, and the resulting packed objects -- will all be on the same plane. -- -- FIXME: shouldn't this pack into a 3d area, or have a 3d equivalent? pack3 :: ℝ2 -> ℝ -> [SymbolicObj3] -> Maybe SymbolicObj3 -- | Transform a 3D object using a 4x4 matrix representing affine -- transformation (OpenSCAD multmatrix) transform3 :: M44 ℝ -> SymbolicObj3 -> SymbolicObj3 -- | Extrude a 2d object upwards. The current object-rounding value set by -- withRounding is used to round the caps, but is not used by the -- 2D object. extrude :: SymbolicObj2 -> ℝ -> SymbolicObj3 -- | The current object-rounding value set by withRounding is used -- to round the caps, but is not used by the 2D object. extrudeM :: Either ℝ (ℝ -> ℝ) -> ExtrudeMScale -> Either ℝ2 (ℝ -> ℝ2) -> SymbolicObj2 -> Either ℝ (ℝ2 -> ℝ) -> SymbolicObj3 extrudeOnEdgeOf :: SymbolicObj2 -> SymbolicObj2 -> SymbolicObj3 rotateExtrude :: ℝ -> Either ℝ2 (ℝ -> ℝ2) -> Either ℝ (ℝ -> ℝ) -> SymbolicObj2 -> SymbolicObj3 -- | Small wrapper of our parser to handle parse errors, etc. runOpenscad :: ScadOpts -> [String] -> String -> IO (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message]) writeSVG :: ℝ -> FilePath -> SymbolicObj2 -> IO () writePNG2 :: ℝ -> FilePath -> SymbolicObj2 -> IO () writeDXF2 :: ℝ -> FilePath -> SymbolicObj2 -> IO () writeSCAD2 :: ℝ -> FilePath -> SymbolicObj2 -> IO () writeGCodeHacklabLaser :: ℝ -> FilePath -> SymbolicObj2 -> IO () writeSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO () writeBinSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO () writeOBJ :: ℝ -> FilePath -> SymbolicObj3 -> IO () writeTHREEJS :: ℝ -> FilePath -> SymbolicObj3 -> IO () writeSCAD3 :: ℝ -> FilePath -> SymbolicObj3 -> IO () -- | Export a PNG of the SymbolicObj3. The projection is with a -- front-facing camera, so the coordinate system is (left to right, -- front to back, down to up). writePNG3 :: ℝ -> FilePath -> SymbolicObj3 -> IO () -- | A 2-dimensional vector -- --
-- >>> pure 1 :: V2 Int -- V2 1 1 ---- --
-- >>> V2 1 2 + V2 3 4 -- V2 4 6 ---- --
-- >>> V2 1 2 * V2 3 4 -- V2 3 8 ---- --
-- >>> sum (V2 1 2) -- 3 --data V2 a V2 :: !a -> !a -> V2 a -- | A 3-dimensional vector data V3 a V3 :: !a -> !a -> !a -> V3 a -- | Quaternions data Quaternion a Quaternion :: !a -> {-# UNPACK #-} !V3 a -> Quaternion a module Graphics.Implicit.Export.Resolution -- | Find the resolution to raytrace at. estimateResolution :: (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message]) -> ℝ