Skip to content

Commit

Permalink
Add haddock
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed Sep 16, 2018
1 parent a652b39 commit 808e692
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
15 changes: 12 additions & 3 deletions src/Lsystem/Generator.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{-|
Module : Lsystem.Generator
Description : Generate the L-system
Copyright : (c) Zebulun Arendsee, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
-}

module Lsystem.Generator
(
step
Expand Down Expand Up @@ -40,9 +49,9 @@ applyRules g lc rc rs n = fromMaybe [n] . firstSuccess (applyRule p) $ rs
applyRule :: Chance -> Rule -> Maybe [Node]
applyRule _ (DeterministicRule cont cond match repl) =
return (repl lc rc n) -- replace node if:
>>= match n -- * the node is of the correct form
>>= cont lc rc -- * it is in the required context
>>= cond lc rc n -- * all parametric restrictions are met
>>= match n -- the node is of the correct form
>>= cont lc rc -- it is in the required context
>>= cond lc rc n -- all parametric restrictions are met
applyRule p (StochasticRule rs') = case (choose p rs') of
-- p is rescaled by dividing by the selected rule's probability
Just (cp', r) -> applyRule (p / cp') r
Expand Down
21 changes: 15 additions & 6 deletions src/Lsystem/Grammar.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{-|
Module : Lsystem.Grammar
Description : Core types
Copyright : (c) Zebulun Arendsee, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
-}

module Lsystem.Grammar
(
System(..)
Expand All @@ -13,17 +22,17 @@ module Lsystem.Grammar
, Chance
) where

-- context-sensitive stochastic parameterized L-systems
--

type Distance = Double -- x > 0
type Yaw = Double -- -180 < x < 180
type Pitch = Double -- -180 < x < 180
type Roll = Double -- -180 < x < 180
type Distance = Double -- ^ x > 0
type Yaw = Double -- ^ -180 < x < 180
type Pitch = Double -- ^ -180 < x < 180
type Roll = Double -- ^ -180 < x < 180

type LeftContext = [Node]
type RightContext = [Node]

type Chance = Double -- 0 <= x <= 1
type Chance = Double -- ^ 0 <= x <= 1

data System = System {
systemBasis :: [Node]
Expand Down
9 changes: 9 additions & 0 deletions src/Lsystem/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}

{-|
Module : Lsystem.Render
Description : Render a generated L-system
Copyright : (c) Zebulun Arendsee, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
-}

module Lsystem.Render
(
renderSystem
Expand Down
27 changes: 18 additions & 9 deletions src/Lsystem/Sugar.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{-|
Module : Lsystem.Sugar
Description : Functions for simplifying L-system specification
Copyright : (c) Zebulun Arendsee, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
-}

module Lsystem.Sugar
(
transDol
Expand Down Expand Up @@ -68,11 +77,11 @@ matchWidth _ _ = Nothing
unconditional :: LeftContext -> RightContext -> Node -> a -> Maybe a
unconditional _ _ _ x = Just x

-- Check is A is a similar to B. For branches, A must be a subtree of B.
-- | Check is A is a similar to B. For branches, A must be a subtree of B.
similar
:: Node -- A
-> Node -- B
-> Bool -- True is A is in B (where `in` is weirdly defined ...)
:: Node -- ^ A
-> Node -- ^ B
-> Bool -- ^ True if A is in B (where `in` is weirdly defined ...)
similar (NodeDummy _ s) (NodeDummy _ t) = s == t
similar (NodeDraw _ _ ) (NodeDraw _ _) = True
similar (NodeRotate _ _ _ _) (NodeRotate _ _ _ _) = True
Expand All @@ -92,11 +101,11 @@ similar (NodeBranch mss) (NodeBranch nss) = any id $ map (anyBranch nss) mss
similar _ _ = False

contextMatch
:: [Node] -- elements to ignore
-> [Node] -- left contextual pattern
-> [Node] -- right contextual pattern
-> [Node] -- left context
-> [Node] -- right context
:: [Node] -- ^ elements to ignore
-> [Node] -- ^ left contextual pattern
-> [Node] -- ^ right contextual pattern
-> [Node] -- ^ left context
-> [Node] -- ^ right context
-> a -> Maybe a -- combinator kludge (I really should go to Bool)
contextMatch ss lpat rpat lc rc x =
return x
Expand Down

0 comments on commit 808e692

Please sign in to comment.