summaryrefslogtreecommitdiff
path: root/src/Graphics/WaveFront/Parse/Common.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Graphics/WaveFront/Parse/Common.hs')
-rw-r--r--src/Graphics/WaveFront/Parse/Common.hs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Graphics/WaveFront/Parse/Common.hs b/src/Graphics/WaveFront/Parse/Common.hs
index bfeb2d8..1554d45 100644
--- a/src/Graphics/WaveFront/Parse/Common.hs
+++ b/src/Graphics/WaveFront/Parse/Common.hs
@@ -33,10 +33,11 @@ module Graphics.WaveFront.Parse.Common where
33-- We'll need these 33-- We'll need these
34-------------------------------------------------------------------------------------------------------------------------------------------- 34--------------------------------------------------------------------------------------------------------------------------------------------
35import Data.Text (Text, pack) 35import Data.Text (Text, pack)
36import Data.Maybe
36import qualified Data.Attoparsec.Text as Atto 37import qualified Data.Attoparsec.Text as Atto
37 38
38import Control.Applicative (pure, liftA2, (<$>), (<*>), (<*), (*>), (<|>)) 39import Control.Applicative (pure, liftA2, (<$>), (<*>), (<*), (*>), (<|>))
39import Linear (V2(..), V3(..)) 40import Linear (V2(..), V3(..),V4(..))
40 41
41import Graphics.WaveFront.Types 42import Graphics.WaveFront.Types
42 43
@@ -151,6 +152,20 @@ point2D :: Fractional f => Atto.Parser (V2 f)
151point2D = V2 <$> coord <*> coord 152point2D = V2 <$> coord <*> coord
152 153
153 154
155pointTo3 :: Fractional f => Int -> f -> Atto.Parser (V3 f)
156pointTo3 3 def = V3 <$> coord <*> coord <*> coord
157pointTo3 2 def = V3 <$> coord <*> coord <*> (fromMaybe def <$> optional coord)
158pointTo3 1 def = (\x m -> case m of { Just (y,z) -> V3 x y z; Nothing -> V3 x def def })
159 <$> coord <*> optional ( do y <- coord
160 z <- fromMaybe def <$> optional coord
161 return (y,z) )
162pointTo3 0 def = fromMaybe (V3 def def def) <$> optional (pointTo3 1 def)
163
164
165pointTo4 :: Fractional f => Int -> f -> Atto.Parser (V4 f)
166pointTo4 4 def = V4 <$> coord <*> coord <*> coord <*> coord
167pointTo4 n def = (\(V3 x y z) mw -> V4 x y z $ fromMaybe def mw) <$> pointTo3 n def <*> optional coord
168
154-- | 169-- |
155clamp :: Ord n => n -> n -> n -> Atto.Parser n 170clamp :: Ord n => n -> n -> n -> Atto.Parser n
156clamp lower upper n 171clamp lower upper n
@@ -163,4 +178,4 @@ clamp lower upper n
163-- | 178-- |
164-- TODO | - Clean up and generalise 179-- TODO | - Clean up and generalise
165clamped :: Integral i => i -> i -> Atto.Parser i 180clamped :: Integral i => i -> i -> Atto.Parser i
166clamped lower upper = Atto.decimal >>= clamp lower upper \ No newline at end of file 181clamped lower upper = Atto.decimal >>= clamp lower upper