Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+60 -47
View File
@@ -1,25 +1,23 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Picture.Data
where
import GHC.Generics
import Data.Aeson
import Geometry.Data
module Picture.Data where
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
import Geometry.Data
import Streaming
data Verx = Verx
{ _vxPos :: !Point3
, _vxCol :: !Point4
, _vxExt :: [Float]
, _vxLayer :: !Layer
, _vxShadNum :: !ShadNum
{ _vxPos :: !Point3
, _vxCol :: !Point4
, _vxExt :: [Float]
, _vxLayer :: !Layer
, _vxShadNum :: !ShadNum
}
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON Verx where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Verx
deriving (Eq, Ord, Show, Read)
data Layer
= BottomLayer
| MidLayer
@@ -27,20 +25,17 @@ data Layer
| BloomNoZWrite
| DebugLayer
| FixedCoordLayer
deriving (Eq,Ord,Enum,Bounded,Show,Read,Generic)
instance ToJSON Layer where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Layer
deriving (Eq, Ord, Enum, Bounded, Show, Read)
layerNum :: Layer -> Int
layerNum = fromEnum
numLayers :: Int
numLayers = length [minBound::Layer .. maxBound]
--TODO use synonyms for layer numbers
newtype ShadNum = ShadNum { _unShadNum :: Int }
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON ShadNum where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ShadNum
numLayers = length [minBound :: Layer .. maxBound]
newtype ShadNum = ShadNum {_unShadNum :: Int}
deriving (Eq, Ord, Show, Read)
polyNum, polyzNum, bezNum, textNum, arcNum, ellNum :: ShadNum
{-# INLINE polyNum #-}
{-# INLINE polyzNum #-}
@@ -48,30 +43,48 @@ polyNum, polyzNum, bezNum, textNum, arcNum, ellNum :: ShadNum
{-# INLINE textNum #-}
{-# INLINE arcNum #-}
{-# INLINE ellNum #-}
polyNum = ShadNum 0
polyzNum = ShadNum 1
bezNum = ShadNum 2
textNum = ShadNum 3
arcNum = ShadNum 4
ellNum = ShadNum 5
polyNum = ShadNum 0
polyzNum = ShadNum 1
bezNum = ShadNum 2
textNum = ShadNum 3
arcNum = ShadNum 4
ellNum = ShadNum 5
type Picture' = Stream (Of Verx) IO ()
type Picture = [Verx]
flat2 :: V2 a -> [a]
flat2 (V2 x y) = [x,y]
flat3 :: V3 a -> [a]
flat3 (V3 x y z) = [x,y,z]
flat4 :: V4 a -> [a]
flat4 (V4 x y z w) = [x,y,z,w]
{-# INLINE flat2 #-}
{-# INLINE flat3 #-}
{-# INLINE flat4 #-}
tflat2 :: (a,a) -> [a]
tflat2 (x,y) = [x,y]
tflat3 :: (a,a,a) -> [a]
tflat3 (x,y,z) = [x,y,z]
tflat4 :: (a,a,a,a) -> [a]
tflat4 (x,y,z,w) = [x,y,z,w]
flatV2 :: V2 a -> [a]
flatV2 (V2 x y) = [x, y]
flatV3 :: V3 a -> [a]
flatV3 (V3 x y z) = [x, y, z]
flatV4 :: V4 a -> [a]
flatV4 (V4 x y z w) = [x, y, z, w]
{-# INLINE flatV2 #-}
{-# INLINE flatV3 #-}
{-# INLINE flatV4 #-}
tflat2 :: (a, a) -> [a]
tflat2 (x, y) = [x, y]
tflat3 :: (a, a, a) -> [a]
tflat3 (x, y, z) = [x, y, z]
tflat4 :: (a, a, a, a) -> [a]
tflat4 (x, y, z, w) = [x, y, z, w]
{-# INLINE tflat2 #-}
{-# INLINE tflat3 #-}
{-# INLINE tflat4 #-}
makeLenses ''Verx
deriveJSON defaultOptions ''Verx
deriveJSON defaultOptions ''Layer
deriveJSON defaultOptions ''ShadNum