Skip to content

Commit

Permalink
Merge pull request #486 from lepsa/removing-partial-functions
Browse files Browse the repository at this point in the history
Removing more partial functions the GHC picked up.
  • Loading branch information
julialongtin committed Apr 19, 2024
2 parents 2cd6592 + fa13508 commit 7815bc1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Graphics/Implicit/Export/OutputFormat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ module Graphics.Implicit.Export.OutputFormat
)
where

import Prelude (Bool, Eq, FilePath, Maybe, Read (readsPrec), Show(show), String, drop, error, flip, length, take, ($), (<>), (==), snd)
import Prelude (Bool, Eq, FilePath, Maybe, Read (readsPrec), Show(show), String, drop, error, flip, length, take, ($), (<>), (==))
import Control.Applicative ((<$>))
-- For making the format guesser case insensitive when looking at file extensions.
import Data.Char (toLower)
import Data.Default.Class (Default(def))
import Data.List (lookup, elem, uncons)
import Data.List (lookup, elem)
import Data.Maybe (fromMaybe)
import Data.Tuple (swap)
-- For handling input/output files.
import System.FilePath (takeExtensions)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l
tail = drop 1

-- | A type serving to enumerate our output formats.
data OutputFormat
Expand Down
5 changes: 2 additions & 3 deletions Graphics/Implicit/Export/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- export getContour and getMesh, which returns the edge of a 2D object, or the surface of a 3D object, respectively.
module Graphics.Implicit.Export.Render (getMesh, getContour) where

import Prelude(error, (-), ceiling, ($), (+), (*), max, div, fmap, reverse, (.), foldMap, min, Int, (<>), (<$>), traverse, snd)
import Prelude(error, (-), ceiling, ($), (+), (*), max, div, fmap, reverse, (.), foldMap, min, Int, (<>), (<$>), traverse, drop)

import Graphics.Implicit.Definitions (, , Fastℕ, ℝ2, ℝ3, TriangleMesh, Obj2, SymbolicObj2, Obj3, SymbolicObj3, Polyline(getSegments), (⋯/), fromℕtoℝ, fromℕ, ℝ3' (ℝ3'))

Expand Down Expand Up @@ -71,13 +71,12 @@ import Graphics.Implicit.Export.Render.HandlePolylines (cleanLoopsFromSegs)
import Data.Maybe (fromMaybe)
import Graphics.Implicit.Primitives (getImplicit)
import Control.Lens (_Wrapped, view, over, _Just)
import Data.List (uncons)

-- Set the default types for the numbers in this file.
default (, Fastℕ, )

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l
tail = drop 1

getMesh :: ℝ3 -> SymbolicObj3 -> TriangleMesh
getMesh res@(V3 xres yres zres) symObj =
Expand Down
4 changes: 2 additions & 2 deletions Graphics/Implicit/Export/Render/GetLoops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Graphics.Implicit.Export.Render.GetLoops (getLoops) where

-- Explicitly include what we want from Prelude.
import Prelude ((<$>), head, last, (==), Bool(False), (.), null, (<>), Eq, Maybe(Just, Nothing))
import Prelude ((<$>), last, (==), Bool(False), (.), null, (<>), Eq, Maybe(Just, Nothing))

import Data.List (partition)

Expand Down Expand Up @@ -51,7 +51,7 @@ getLoops' (x:xs) [] _ = getLoops' xs [x] (last x)

-- A loop is finished if its start and end are the same.
-- Return it and start searching for another loop.
getLoops' segs workingLoop ultima | head (head workingLoop) == ultima =
getLoops' segs workingLoop@((x:_):_) ultima | x == ultima =
(workingLoop :) <$> getLoops' segs [] ultima

-- Finally, we search for pieces that can continue the working loop,
Expand Down
18 changes: 11 additions & 7 deletions Graphics/Implicit/Export/Render/TesselateLoops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

module Graphics.Implicit.Export.Render.TesselateLoops (tesselateLoop) where

import Prelude(sum, (-), pure, ($), length, (==), zip, init, reverse, (<), (/), null, (<>), head, (*), abs, (+), foldMap, (&&), snd, (<$>))
import Prelude(sum, (-), pure, ($), length, (==), zip, init, reverse, (<), (/), null, (<>), (*), abs, (+), foldMap, (&&), drop, Int)

import Graphics.Implicit.Definitions (, , Obj3, ℝ3, TriangleMesh(TriangleMesh), Triangle(Triangle))

import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris))

import Graphics.Implicit.Export.Util (centroid)

import Data.List (genericLength, uncons)
import Data.List (genericLength)
import Linear ( cross, Metric(norm), (^*), (^/) )
import Data.Maybe (fromMaybe)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l
tail = drop 1

-- de-compose a loop into a series of triangles or squares.
-- FIXME: res should be ℝ3.
Expand Down Expand Up @@ -84,8 +83,13 @@ tesselateLoop res obj pathSides = pure $ Tris $ TriangleMesh $
else let
mid = centroid path
midval = obj mid
rotateList :: Int -> [a] -> [a]
rotateList 0 l = l
rotateList _ [] = []
rotateList _ [a] = [a]
rotateList n (a:as) = rotateList (n-1) (as <> [a])
preNormal = sum
[ a `cross` b | (a,b) <- zip path (tail path <> [head path]) ]
[ a `cross` b | (a,b) <- zip path (rotateList 1 path) ]
preNormalNorm = norm preNormal
normal = preNormal ^/ preNormalNorm
deriv = (obj (mid + (normal ^* (res/100)) ) - midval)/res*100
Expand All @@ -94,8 +98,8 @@ tesselateLoop res obj pathSides = pure $ Tris $ TriangleMesh $
isCloserToSurface = abs midval' < abs midval
isNearby = norm (mid - mid') < 2 * abs midval
in if isCloserToSurface && isNearby
then early_tris <> [Triangle (a,b,mid') | (a,b) <- zip path (tail path <> [head path]) ]
else early_tris <> [Triangle (a,b,mid) | (a,b) <- zip path (tail path <> [head path]) ]
then early_tris <> [Triangle (a,b,mid') | (a,b) <- zip path (rotateList 1 path) ]
else early_tris <> [Triangle (a,b,mid) | (a,b) <- zip path (rotateList 1 path) ]

shrinkLoop :: -> [ℝ3] -> -> Obj3 -> ([Triangle], [ℝ3])

Expand Down
8 changes: 4 additions & 4 deletions Graphics/Implicit/ExtOpenScad/Parser/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-- A parser for a numeric expressions.
module Graphics.Implicit.ExtOpenScad.Parser.Expr(expr0) where

import Prelude (Char, Maybe(Nothing, Just), ($), (<>), id, foldl, foldr, (==), length, head, (&&), (<$>), (<*>), (*>), (<*), flip, (.), pure)
import Prelude (Char, Maybe(Nothing, Just), ($), (<>), id, foldl, foldr, (==), (<$>), (<*>), (*>), (<*), flip, (.), pure, Bool (True))

import Graphics.Implicit.ExtOpenScad.Definitions (Expr(LamE, LitE, ListE, (:$)), OVal(ONum, OUndefined), Symbol(Symbol))

Expand Down Expand Up @@ -147,9 +147,9 @@ vectorListParentheses =
<* if o == '['
then matchTok ']'
else matchTok ')'
pure $ if o == '(' && length exprs == 1
then head exprs
else ListE exprs
pure $ case (o == '(', exprs) of
(True, [e]) -> e
_ -> ListE exprs
*<|> "vector/list generator" ?: do
-- eg. [ a : 1 : a + 10 ]
-- [ a : a + 10 ]
Expand Down
6 changes: 2 additions & 4 deletions programs/docgen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
-- FIXME: document why we need each of these.
{-# LANGUAGE ScopedTypeVariables #-}

import Prelude(IO, Show, String, Int, Maybe(Just,Nothing), Eq, return, ($), show, fmap, (<>), putStrLn, filter, zip, null, undefined, const, Bool(True,False), fst, (.), head, length, (/=), (+), error, print, snd, (<$>))
import Data.Maybe (fromMaybe)
import Data.List (uncons)
import Prelude(IO, Show, String, Int, Maybe(Just,Nothing), Eq, return, ($), show, fmap, (<>), putStrLn, filter, zip, null, undefined, const, Bool(True,False), fst, (.), head, length, (/=), (+), error, print, drop)
import Graphics.Implicit.ExtOpenScad.Primitives (primitiveModules)
import Graphics.Implicit.ExtOpenScad.Definitions (ArgParser(AP,APFail,APExample,APTest,APTerminator,APBranch), Symbol(Symbol), OVal(ONModule), SourcePosition(SourcePosition), StateC)

Expand All @@ -16,7 +14,7 @@ import Data.Traversable (traverse)
import Data.Text.Lazy (unpack, pack)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l
tail = drop 1

-- | Return true if the argument is of type ExampleDoc.
isExample :: DocPart -> Bool
Expand Down

0 comments on commit 7815bc1

Please sign in to comment.