Skip to content

Commit 165162f

Browse files
committed
Comments, or other hlint inspired nonfuncional changes.
1 parent ad7df23 commit 165162f

17 files changed

Lines changed: 101 additions & 96 deletions

File tree

Graphics/Implicit/Definitions.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ where
8383

8484
import GHC.Generics (Generic)
8585

86-
import Prelude (Foldable, Num, Ord, Eq, atan2, asin, pi, (>=), signum, abs, (+), (-), RealFloat, (==), ($), flip, Semigroup((<>)), Monoid (mempty), Double, Either(Left, Right), Bool(True, False), (*), (/), fromIntegral, Float, realToFrac, (&&), RealFloat(isNaN), (||), any)
86+
import Prelude (Foldable, Num, Ord, Eq, atan2, asin, elem, pi, (>=), signum, abs, (+), (-), RealFloat, (==), ($), flip, Semigroup((<>)), Monoid (mempty), Double, Either(Left, Right), Bool(True, False), (*), (/), fromIntegral, Float, realToFrac, (&&), RealFloat(isNaN), (||))
8787

8888
import Graphics.Implicit.FastIntUtil as F (Fastℕ(Fastℕ), fromFastℕ, toFastℕ)
8989

@@ -456,4 +456,4 @@ hasZeroComponent
456456
=> f a
457457
-> Bool
458458
{-# INLINABLE hasZeroComponent #-}
459-
hasZeroComponent = any (==0)
459+
hasZeroComponent = elem 0

Graphics/Implicit/Export/DiscreteAproxable.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import Codec.Picture (DynamicImage(ImageRGBA8), PixelRGBA8(PixelRGBA8), generate
3131

3232
import Control.Parallel.Strategies (using, rdeepseq, parBuffer)
3333

34-
import Linear ( V3(V3), V2(V2), (*^), (^/) )
35-
import Linear.Affine ( Affine((.+^), (.-^)) )
34+
import Linear (V3(V3), V2(V2), (*^), (^/))
35+
36+
import Linear.Affine (Affine((.+^), (.-^)))
37+
3638
import Graphics.Implicit.Primitives (getImplicit)
3739

3840
default ()
@@ -82,13 +84,13 @@ instance DiscreteAproxable SymbolicObj3 DynamicImage where
8284
(cameraRay camera (V2 a b + V2 ( 0.25/w) (0.25/h)))
8385
2 box scene,
8486
traceRay
85-
(cameraRay camera (V2 a b + V2 (-0.25/w) (0.25/h)))
87+
(cameraRay camera (V2 a b + V2 (-(0.25/w)) (0.25/h)))
8688
0.5 box scene,
8789
traceRay
88-
(cameraRay camera (V2 a b + V2 (0.25/w) (-0.25/h)))
90+
(cameraRay camera (V2 a b + V2 (0.25/w) (-(0.25/h))))
8991
0.5 box scene,
9092
traceRay
91-
(cameraRay camera (V2 a b + V2 (-0.25/w) (-0.25/h)))
93+
(cameraRay camera (V2 a b + V2 (-(0.25/w)) (-(0.25/h))))
9294
0.5 box scene
9395
]
9496
where
@@ -113,7 +115,7 @@ instance DiscreteAproxable SymbolicObj2 DynamicImage where
113115
pixelRenderer :: Int -> Int -> PixelRGBA8
114116
pixelRenderer mya myb = mycolor
115117
where
116-
xy a b = (V2 x1 y2 .-^ V2 (dxy-dx) (dy-dxy) ^/2) .+^ dxy *^ V2 (a/w) (-b/h)
118+
xy a b = (V2 x1 y2 .-^ V2 (dxy-dx) (dy-dxy) ^/2) .+^ dxy *^ V2 (a/w) (-(b/h))
117119
s = 0.25 ::
118120
V2 a' b' = V2 (realToFrac mya) (realToFrac myb) :: ℝ2
119121
mycolor = colorToPixelRGBA8 $ average [objColor $ xy a' b', objColor $ xy a' b',

Graphics/Implicit/Export/Render/RefineSegs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ detail n res obj (Polyline [p1, p2]) | n < 2 =
4141
else
4242
let
4343
normal = (\(V2 a b) -> V2 b (-a)) $ normalize (p2 - p1)
44-
derivN = -(obj (mid - (normal ^* (midval/2))) - midval) * (2/midval)
44+
derivN = -((obj (mid - (normal ^* (midval/2))) - midval) * (2/midval))
4545
in
4646
if abs derivN > 0.5 && abs derivN < 2 && abs (midval/derivN) < 3*res
4747
then

Graphics/Implicit/Export/SymbolicFormats.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ buildS3 _ (Cylinder h r1 r2) = callNaked "cylinder" ["r1 = " <> pretty (bf r1)
137137
, pretty $ bf h
138138
] []
139139

140-
buildS3 _ (Polyhedron points tris) = callNaked "polyhedron" ["points = [" <> (fold $ intersperse "," $ renderPoint <$> points) <> "], faces = [" <> (fold $ intersperse "," $ renderTri <$> tris) <> "]" ] []
140+
buildS3 _ (Polyhedron points tris) = callNaked "polyhedron" ["points = [" <> fold (intersperse "," $ renderPoint <$> points) <> "], faces = [" <> fold (intersperse "," $ renderTri <$> tris) <> "]" ] []
141141
where
142142
renderPoint (V3 v1 v2 v3) = "[" <> pretty (bf v1) <> "," <> pretty (bf v2) <> "," <> pretty (bf v3) <> "]"
143143
renderTri (n1,n2,n3) = "[" <> pretty (bℕ n1) <> "," <> pretty (bℕ n2) <> "," <> pretty (bℕ n3) <> "]"

Graphics/Implicit/ExtOpenScad/Default.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Graphics.Implicit.MathUtil (infty)
5151
clamp :: Ord a => (a, a) -> a -> a
5252
clamp (lower, upper) a = min upper (max lower a)
5353

54+
-- | Find functions in our SCAD sandbox.
5455
defaultObjects :: Bool -> VarLookup
5556
defaultObjects withCSG = VarLookup $ fromList $
5657
defaultConstants
@@ -62,6 +63,7 @@ defaultObjects withCSG = VarLookup $ fromList $
6263
<> objectFunctions
6364
<> varArgModules
6465

66+
-- | Constants from Haskell.
6567
defaultConstants :: [(Symbol, OVal)]
6668
defaultConstants = (\(a,b) -> (a, toOObj (b :: ))) <$>
6769
[(Symbol "pi", pi),
@@ -77,6 +79,7 @@ nanNegInf x = if isNaN x then -infty else x
7779
signedNaNInf :: RealFloat a => a -> a -> a
7880
signedNaNInf x y = if isNaN y then signum x * infty else y
7981

82+
-- | Functions which only take one argument.
8083
defaultFunctions :: [(Symbol, OVal)]
8184
defaultFunctions = (\(a,b) -> (a, toOObj ( b :: -> ))) <$>
8285
[
@@ -108,6 +111,7 @@ defaultFunctions = (\(a,b) -> (a, toOObj ( b :: ℝ -> ℝ))) <$>
108111
(Symbol "sqrt", clamp (0, infty) . nanNegInf . sqrt)
109112
]
110113

114+
-- | Functions which take two arguments.
111115
defaultFunctions2 :: [(Symbol, OVal)]
112116
defaultFunctions2 = (\(a,b) -> (a, toOObj (b :: -> -> ))) <$>
113117
[
@@ -117,6 +121,7 @@ defaultFunctions2 = (\(a,b) -> (a, toOObj (b :: ℝ -> ℝ -> ℝ))) <$>
117121
(Symbol "pow", (**))
118122
]
119123

124+
-- | Special functions, which accept a funcion as their first argument. Map has to be special.
120125
defaultFunctionsSpecial :: [(Symbol, OVal)]
121126
defaultFunctionsSpecial =
122127
[

Graphics/Implicit/ExtOpenScad/Definitions.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ data OVal = OUndefined
199199
| OIO (IO OVal)
200200
-- Name, arguments, argument parsers.
201201
| OUModule Symbol (Maybe [(Symbol, Bool)]) (VarLookup -> ArgParser (StateC [OVal]))
202-
-- Name, implementation, arguments.
202+
-- Name, implementation, instances.
203203
| ONModule Symbol (SourcePosition -> ArgParser (StateC [OVal])) [[(Symbol, Bool)]]
204-
-- Name, implementation, arguments.
204+
-- Name, implementation, instances.
205205
| ONModuleWithSuite Symbol (SourcePosition -> [OVal] -> ArgParser (StateC [OVal])) [[(Symbol, Bool)]]
206206
| OVargsModule Symbol (Symbol -> SourcePosition -> [(Maybe Symbol, OVal)] -> [StatementI] -> ([StatementI] -> StateC ()) -> StateC ())
207207
| OObj3 SymbolicObj3
@@ -303,11 +303,11 @@ varUnion (VarLookup a) (VarLookup b) = VarLookup $ union a b
303303
lookupVarIn :: Text -> VarLookup -> Maybe OVal
304304
lookupVarIn target (VarLookup vars) = lookup (Symbol target) vars
305305

306-
-- | Our tests. We only have the one, and it is to check the Euler characteristic of a mesh.
306+
-- | Our tests.
307307
data TestInvariant =
308-
EulerCharacteristic
309-
| ContoursAreClosed
310-
| MeshIsWaterTight
308+
EulerCharacteristic -- check the Euler characteristic of a mesh.
309+
| ContoursAreClosed -- Ensure all contours are Closed (start and stop with the same point)
310+
| MeshIsWaterTight -- Ensure all of the triangles in the mesh have neighbors.
311311
deriving (Show)
312312

313313
-- | for composing ArgParsers.

Graphics/Implicit/ExtOpenScad/Eval/Expr.hs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
-- Allow us to use string literals for Text
66
{-# LANGUAGE OverloadedStrings #-}
77

8+
-- Allow us to treat incomplete tuples as function references.
9+
{-# LANGUAGE TupleSections #-}
10+
811
module Graphics.Implicit.ExtOpenScad.Eval.Expr (evalArgs, evalExpr, rawRunExpr, matchPat, StateE, ExprState(ExprState), addMessage) where
912

1013
import Prelude (String, Monoid, Maybe(Just, Nothing), Bool (False, True), ($), elem, mempty, pure, show, zip, (&&), const, (<>), foldr, foldMap, (.), (<$>), traverse)
@@ -72,14 +75,14 @@ type StateE a = ImplicitCadM Input [Message] ExprState Identity a
7275
runStateE :: Input -> ExprState -> StateE a -> (a, [Message], ExprState)
7376
runStateE r s m = runIdentity $ runImplicitCadM r s m
7477

75-
-- Add a message to our list of messages contained in the StatE monad.
78+
-- | Add a message to our list of messages contained in the StateE monad.
7679
addMessage :: MessageType -> SourcePosition -> Text -> StateE ()
7780
addMessage mtype pos text = addMesg $ Message mtype pos text
7881
where
7982
addMesg :: Message -> StateE ()
8083
addMesg = tell . pure
8184

82-
-- Log an error condition.
85+
-- | Log an error condition.
8386
errorE :: SourcePosition -> Text -> StateE ()
8487
errorE = addMessage Error
8588

@@ -122,10 +125,10 @@ evalExpr sourcePos expr = case expr of
122125
evalExprStateC sourcePos expr
123126
_ -> evalExprStateC sourcePos expr
124127
where
125-
isModule (OUModule _ _ _) = True
126-
isModule (ONModule _ _ _) = True
127-
isModule (ONModuleWithSuite _ _ _) = True
128-
isModule (OVargsModule _ _) = True
128+
isModule (OUModule {}) = True
129+
isModule (ONModule {}) = True
130+
isModule (ONModuleWithSuite {}) = True
131+
isModule (OVargsModule {}) = True
129132
isModule _ = False
130133
-- FIXME: We may need a better result cannonicalizer here.
131134
canonicalizeRes (OList [oneItem]) = oneItem
@@ -136,7 +139,7 @@ runExprModule :: SourcePosition -> OVal -> [Expr] -> StateC [OVal]
136139
runExprModule sourcePos mod argExprsRaw = do
137140
let
138141
-- Mark all of our arguments as unnamed. There are no named arguments in expressions.
139-
argExprs = (\a -> (Nothing, a)) <$> argExprsRaw
142+
argExprs = (Nothing,) <$> argExprsRaw
140143
-- Common error messages.
141144
noSuiteError,notModError :: (Monoid a) => StateC a
142145
noSuiteError = do
@@ -151,10 +154,10 @@ runExprModule sourcePos mod argExprsRaw = do
151154

152155
-- We can't handle any suites, either.
153156
_ <- case mod of
154-
(OUModule _ _ _) -> pure mempty :: StateC ()
155-
(ONModule _ _ _) -> pure mempty
156-
(ONModuleWithSuite _ _ _) -> noSuiteError
157-
(OVargsModule _ _) -> noSuiteError
157+
(OUModule {}) -> pure mempty :: StateC ()
158+
(ONModule {}) -> pure mempty
159+
(ONModuleWithSuite {}) -> noSuiteError
160+
(OVargsModule {}) -> noSuiteError
158161
_ -> notModError
159162

160163
-- Perform any per-module-type specific housework, and call the module.
@@ -169,8 +172,8 @@ runExprModule sourcePos mod argExprsRaw = do
169172
(ONModule _ implementation _) -> do
170173
-- Run the module.
171174
runModule sourcePos $ argMap evaluatedArgs $ implementation sourcePos
172-
(ONModuleWithSuite _ _ _) -> noSuiteError
173-
(OVargsModule _ _) -> noSuiteError
175+
(ONModuleWithSuite {}) -> noSuiteError
176+
(OVargsModule {}) -> noSuiteError
174177
_ -> notModError
175178

176179
-- | The inner monadic entry point. Evaluates an expression, pureing the result, and moving any error messages generated into the calling StateC.
@@ -185,7 +188,7 @@ evalExprStateC pos expr = do
185188
traverse_ moveMessage messages
186189
pure $ valf []
187190

188-
-- A more raw entry point, that does not depend on IO.
191+
-- A pure entry point, that does not do module calls, and does not depend on IO.
189192
rawRunExpr :: SourcePosition -> VarLookup -> Expr -> (OVal, [Message])
190193
rawRunExpr pos vars expr = do
191194
let
@@ -241,7 +244,7 @@ evalExpr' (fexpr :$ argExprs) = do
241244
app f l = case (getErrors f, getErrors $ OList l) of
242245
(Nothing, Nothing) -> app' f l
243246
where
244-
-- apply function to the list of its arguments until we run out
247+
-- Apply a function to the list of its arguments until we run out
245248
-- of them
246249
app' (OFunc f') (x:xs) = app (f' x) xs
247250
app' a [] = a

Graphics/Implicit/ExtOpenScad/Eval/Statement.hs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ import System.Directory (doesFileExist)
5151
import System.FilePath (takeDirectory)
5252
import Control.Monad.Reader.Class (MonadReader(ask))
5353

54-
-- | Run statements out of the OpenScad file.
54+
-- | Run a single OpenSCAD statement.
5555
runStatementI :: StatementI -> StateC ()
5656
runStatementI (StatementI sourcePos (pat := expr)) = do
5757
-- Interpret variable assignment
58-
-- FIXME: instead of just expression evaluation, module calling?
5958
val <- evalExpr sourcePos expr
6059
let posMatch = matchPat pat val
6160
case (getErrors val, posMatch) of
@@ -107,19 +106,19 @@ runStatementI (StatementI sourcePos (ModuleCall (Symbol name) argsExpr suite)) =
107106

108107
-- Evaluate the suites, if required.
109108
suiteResults <- case maybeMod of
110-
Just mod@(OUModule _ _ _) -> ensureNoSuite sourcePos mod suite
111-
Just mod@(ONModule _ _ _) -> ensureNoSuite sourcePos mod suite
112-
Just (ONModuleWithSuite _ _ _) -> evalSuite varlookup sourcePos suite
113-
Just mod@(OVargsModule _ _) -> ensureNoSuite sourcePos mod suite
114-
_ -> pure []
109+
Just mod@(OUModule {}) -> ensureNoSuite sourcePos mod suite
110+
Just mod@(ONModule {}) -> ensureNoSuite sourcePos mod suite
111+
Just (ONModuleWithSuite {}) -> evalSuite varlookup sourcePos suite
112+
Just mod@(OVargsModule {}) -> ensureNoSuite sourcePos mod suite
113+
_ -> pure []
115114

116115
-- Check that an instance exists that can execute the module, as it was called.
117-
_ <- case maybeMod of
118-
Just (OUModule _ _ _) -> pure ()
119-
Just mod@(ONModule _ _ forms) -> checkInstances sourcePos mod argsExpr forms
120-
Just mod@(ONModuleWithSuite _ _ forms) -> checkInstances sourcePos mod argsExpr forms
121-
Just (OVargsModule _ _) -> pure ()
122-
_ -> pure ()
116+
case maybeMod of
117+
Just (OUModule {}) -> pure ()
118+
Just mod@(ONModule _ _ forms) -> checkInstances sourcePos mod argsExpr forms
119+
Just mod@(ONModuleWithSuite _ _ forms) -> checkInstances sourcePos mod argsExpr forms
120+
Just (OVargsModule {}) -> pure ()
121+
_ -> pure ()
123122

124123
-- do any per-module-type work, and run the module.
125124
case maybeMod of
@@ -137,17 +136,17 @@ runStatementI (StatementI sourcePos (ModuleCall (Symbol name) argsExpr suite)) =
137136
-- Run the module.
138137
runModule sourcePos $ argMap evaluatedArgs $ implementation sourcePos suiteResults
139138
Just (OVargsModule modname implementation) -> do
140-
-- Run the module, which evaluates it's own suite.
141-
_ <- implementation modname sourcePos evaluatedArgs suite runSuite -- no values are pureed
139+
-- Run the module, which evaluates it's own suite, and cannot return anything.
140+
implementation modname sourcePos evaluatedArgs suite runSuite
142141
pure []
143142
Just foo -> do
144-
case getErrors foo of
145-
Just err -> errorC sourcePos err
146-
Nothing -> errorC sourcePos $ "Object " <> name <> " is not a module!"
147-
pure []
143+
case getErrors foo of
144+
Just err -> errorC sourcePos err
145+
Nothing -> errorC sourcePos $ "Object " <> name <> " is not a module!"
146+
pure []
148147
_ -> do
149-
errorC sourcePos $ "Module " <> name <> " not in scope."
150-
pure []
148+
errorC sourcePos $ "Module " <> name <> " not in scope."
149+
pure []
151150
pushVals newVals
152151

153152
runStatementI (StatementI sourcePos (Include name injectVals)) = do

0 commit comments

Comments
 (0)