{- ORMOLU_DISABLE -}
-- Implicit CAD. Copyright (C) 2011, Christopher Olah (chris@colah.ca)
-- Copyright (C) 2014 2015 2016, Julia Longtin (julial@turinglace.com)
-- Released under the GNU AGPLV3+, see LICENSE

{- The purpose of this file is to pass on the functionality we want
   to be accessible to an end user who is compiling objects using
   this haskell library. -}

module Graphics.Implicit (
  -- * Types
  W.ℝ,
  W.ℝ2,
  W.ℝ3,
  SymbolicObj2 (),
  SymbolicObj3 (),
  W.ExtrudeMScale(C1, C2, Fn),

  -- * Shared operations
  P.Object (),
  P.translate,
  P.scale,
  P.mirror,
  P.complement,
  P.union,
  P.unionR,
  P.intersect,
  P.intersectR,
  P.difference,
  P.differenceR,
  P.implicit,
  P.shell,
  P.outset,
  P.emptySpace,
  P.fullSpace,
  P.withRounding,

  -- * 2D primitive shapes
  P.square,
  P.rect,
  P.circle,
  P.polygon,

  -- * 2D operations
  P.rotate,
  P.transform,
  P.pack2,

  -- * 3D primitive shapes
  P.cube,
  P.rect3,
  P.sphere,
  P.cylinder,
  P.cylinder2,

  -- * 3D operations
  P.rotate3,
  P.rotate3V,
  P.pack3,
  P.transform3,

  -- * Extrusions into 3D
  P.extrude,
  P.extrudeM,
  P.extrudeOnEdgeOf,
  P.rotateExtrude,

  -- * OpenScad support
  E.runOpenscad,

  -- * 2D exporters
  writeSVG,
  writePNG2,
  writeDXF2,
  writeSCAD2,
  writeGCodeHacklabLaser,

  -- * 3D exporters
  writeSTL,
  writeBinSTL,
  writeOBJ,
  writeTHREEJS,
  writeSCAD3,
  writePNG3,

  -- * Linear re-exports
  L.V2(V2),
  L.V3(V3),
  L.Quaternion(Quaternion)

) where

import Prelude(FilePath, IO)

-- The primitive objects, and functions for manipulating them.
-- MAYBEFIXME: impliment slice operation, regularPolygon and zsurface primitives.
import Graphics.Implicit.Primitives as P (withRounding, rect, rect3, translate, scale, mirror, complement, union, intersect, difference, unionR, intersectR, differenceR, shell, extrude, extrudeM, extrudeOnEdgeOf, sphere, cube, circle, cylinder, cylinder2, square, polygon, rotateExtrude, rotate3, rotate3V, pack3, transform3, rotate, transform, pack2, implicit, fullSpace, emptySpace, outset, Object)

-- The Extended OpenScad interpreter.
import Graphics.Implicit.ExtOpenScad as E (runOpenscad)

-- typesclasses and types defining the world, or part of the world.
import Graphics.Implicit.Definitions as W (, ℝ2, ℝ3, SymbolicObj2, SymbolicObj3, ExtrudeMScale(C1, C2, Fn))

-- Functions for writing files based on the result of operations on primitives.
import qualified Graphics.Implicit.Export as Export (writeSVG, writeDXF2, writeSTL, writeBinSTL, writeOBJ, writeSCAD2, writeSCAD3, writeTHREEJS, writeGCodeHacklabLaser, writePNG)

import Linear as L (V2(V2), V3(V3), Quaternion(Quaternion))

-- We want Export to be a bit less polymorphic
-- (so that types will collapse nicely)

writeSVG
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-2)/ more time.
    -> FilePath
    -> SymbolicObj2
    -> IO ()
writeSVG :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writeSVG = ℝ -> FilePath -> SymbolicObj2 -> IO ()
forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> FilePath -> obj -> IO ()
Export.writeSVG

writeDXF2
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-2)/ more time.
    -> FilePath
    -> SymbolicObj2
    -> IO ()
writeDXF2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writeDXF2 = ℝ -> FilePath -> SymbolicObj2 -> IO ()
forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> FilePath -> obj -> IO ()
Export.writeDXF2

writeSTL
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writeSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeSTL = ℝ -> FilePath -> SymbolicObj3 -> IO ()
forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> FilePath -> obj -> IO ()
Export.writeSTL

writeBinSTL
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writeBinSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeBinSTL = ℝ -> FilePath -> SymbolicObj3 -> IO ()
forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> FilePath -> obj -> IO ()
Export.writeBinSTL

writeOBJ
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writeOBJ :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeOBJ = ℝ -> FilePath -> SymbolicObj3 -> IO ()
forall obj.
DiscreteAproxable obj NormedTriangleMesh =>
ℝ -> FilePath -> obj -> IO ()
Export.writeOBJ

writeSCAD2
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-2)/ more time.
    -> FilePath
    -> SymbolicObj2
    -> IO ()
writeSCAD2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writeSCAD2 = ℝ -> FilePath -> SymbolicObj2 -> IO ()
Export.writeSCAD2

writeSCAD3
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writeSCAD3 :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeSCAD3 = ℝ -> FilePath -> SymbolicObj3 -> IO ()
Export.writeSCAD3

writeTHREEJS
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writeTHREEJS :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writeTHREEJS = ℝ -> FilePath -> SymbolicObj3 -> IO ()
forall obj.
DiscreteAproxable obj TriangleMesh =>
ℝ -> FilePath -> obj -> IO ()
Export.writeTHREEJS

writeGCodeHacklabLaser
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-2)/ more time.
    -> FilePath
    -> SymbolicObj2
    -> IO ()
writeGCodeHacklabLaser :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writeGCodeHacklabLaser = ℝ -> FilePath -> SymbolicObj2 -> IO ()
forall obj.
DiscreteAproxable obj [Polyline] =>
ℝ -> FilePath -> obj -> IO ()
Export.writeGCodeHacklabLaser

writePNG2
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-2)/ more time.
    -> FilePath
    -> SymbolicObj2
    -> IO ()
writePNG2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
writePNG2 = ℝ -> FilePath -> SymbolicObj2 -> IO ()
forall obj.
DiscreteAproxable obj DynamicImage =>
ℝ -> FilePath -> obj -> IO ()
Export.writePNG

-- | 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
    ::   -- ^ Rendering resolution, in millimeters. Smaller values produce
          -- exports more faithful to the implicit model, at the expense of
          -- taking /O(n^-3)/ more time.
    -> FilePath
    -> SymbolicObj3
    -> IO ()
writePNG3 :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
writePNG3 = ℝ -> FilePath -> SymbolicObj3 -> IO ()
forall obj.
DiscreteAproxable obj DynamicImage =>
ℝ -> FilePath -> obj -> IO ()
Export.writePNG