Commit before tree representation of picture

This commit is contained in:
jgk
2021-02-16 00:00:49 +01:00
parent e8b4f8791b
commit c7aa5f707e
2 changed files with 56 additions and 20 deletions
+49 -12
View File
@@ -3,6 +3,8 @@
module Picture.Data
where
import Data.Monoid
import qualified Data.Foldable as F
import qualified Data.Sequence as Se
import qualified Data.DList as DL
import qualified Data.Vector as V
import Geometry.Data
@@ -13,25 +15,60 @@ type RGBA = (Float,Float,Float,Float)
type Color = (Float,Float,Float,Float)
type VerticesContainer a = Se.Seq a
toVC = Se.fromList
fromVC :: VerticesContainer a -> [a]
fromVC = F.toList
--type VerticesContainer a = DL.DList a
--toVC = DL.fromList
--fromVC = DL.toList
type VerticesContainer a = [a]
toVC = id
fromVC = id
--type VerticesContainer a = [a]
--toVC = id
--fromVC = id
mapVC :: (a -> b) -> VerticesContainer a -> VerticesContainer b
mapVC = fmap
data Shape = Shape
{ _shPos :: VerticesContainer Point3
, _shCol :: VerticesContainer RGBA
}
combineShapes :: Shape -> Shape -> Shape
combineShapes sa sb = Shape
{ _shPos = _shPos sa <> _shPos sb
, _shCol = _shCol sa <> _shCol sb
}
data NTree a b
= NBranch a [NTree a b]
| NLeaf b
reduceNTree :: NTree (a -> a) a -> NTree () a
reduceNTree = reduceNTree' id
where
reduceNTree' :: (b -> b) -> NTree (b -> b) b -> NTree () b
reduceNTree' f (NBranch g xs) = NBranch () $ map (reduceNTree' (f . g)) xs
reduceNTree' f (NLeaf x) = NLeaf $ f x
concatLeaves :: NTree a b -> DL.DList b
concatLeaves (NLeaf x) = DL.singleton x
concatLeaves (NBranch _ xs) = mconcat (map concatLeaves xs)
--reduceShapeTree :: (Shape -> Shape) -> ShapeTree -> [Shape]
--reduceShapeTree
-- (TransformShape f xs) = map (f . reduceShapeTree) xs
--reduceShapeTree
-- (Leaf s) = [s]
data ShapeTree
= TransformShape (Shape -> Shape) [ShapeTree]
| Leaf Shape
data Shape
= Shape
{ _shPos :: VerticesContainer Point3
, _shCol :: VerticesContainer RGBA
}
| TextShape
{ _shPos :: VerticesContainer Point3
, _shCol :: VerticesContainer RGBA
, _shTex :: VerticesContainer Point2
}
--combineShapes :: Shape -> Shape -> Shape
--combineShapes sa sb = Shape
-- { _shPos = _shPos sa <> _shPos sb
-- , _shCol = _shCol sa <> _shCol sb
-- }
data Picture = Scene
{ _scPosTri :: VerticesContainer Point3