Make Shapes use Streaming rather than Vector streaming

This commit is contained in:
2022-07-03 23:04:58 +01:00
parent 02fcb5f072
commit f9a904d52b
11 changed files with 54 additions and 47 deletions
+8 -8
View File
@@ -21,7 +21,7 @@ module Shape
import Geometry
import Shape.Data
import Color
import qualified Data.Vector.Fusion.Stream.Monadic as VS
import qualified Streaming.Prelude as S
emptySH :: Shape
{-# INLINE emptySH #-}
@@ -45,7 +45,7 @@ prismPoly
-> [Point3]
-> Shape
{-# INLINE prismPoly #-}
prismPoly upps downps = [ShapeObj (TopPrism n) (VS.fromList $ f upps downps)]
prismPoly upps downps = S.yield (ShapeObj (TopPrism n) (S.each $ f upps downps))
where
n = length upps
f (a:as) (b:bs) = g a:g b:f as bs
@@ -58,7 +58,7 @@ upperPrismPoly
-> [Point2]
-> Shape
{-# INLINE upperPrismPoly #-}
upperPrismPoly h ps = [ShapeObj (TopPrism n) (VS.fromList $ f ps)]
upperPrismPoly h ps = S.yield (ShapeObj (TopPrism n) (S.each $ f ps))
where
n = length ps
g h' (V2 x y) = pairToSV (V3 x y h', black)
@@ -70,7 +70,7 @@ upperPrismPolyHalf
-> [Point2]
-> Shape
{-# INLINE upperPrismPolyHalf #-}
upperPrismPolyHalf h ps = [ShapeObj (TopPrism n) (VS.fromList $ f upps downps)]
upperPrismPolyHalf h ps = S.yield (ShapeObj (TopPrism n) (S.each $ f upps downps))
where
n = length ps
upps = map f' ps
@@ -86,7 +86,7 @@ colorSH = overColSH . const
overColSH :: (Point4 -> Point4) -> Shape -> Shape
{-# INLINE overColSH #-}
overColSH = fmap . overColObj
overColSH = S.map . overColObj
--overColSHM :: Monad m => (Point4 -> m Point4) -> Shape -> m Shape
--{-# INLINE overColSHM #-}
@@ -94,7 +94,7 @@ overColSH = fmap . overColObj
overPosSHI :: (Point3 -> Point3) -> Shape -> Shape
{-# INLINE overPosSHI #-}
overPosSHI = fmap . overPosObj
overPosSHI = S.map . overPosObj
translateSH :: Point3 -> Shape -> Shape
{-# INLINE translateSH #-}
@@ -126,7 +126,7 @@ scaleSH (V3 a b c) = overPosSHI (\(V3 x y z) -> V3 (x*a) (y*b) (z*c))
overColObj :: (Point4 -> Point4) -> ShapeObj -> ShapeObj
{-# INLINE overColObj #-}
overColObj f (ShapeObj st vs) = ShapeObj st (VS.map (overColVertex f) vs)
overColObj f (ShapeObj st vs) = ShapeObj st (S.map (overColVertex f) vs)
--overColObjM :: Monad m => (Point4 -> m Point4) -> ShapeObj -> m ShapeObj
--{-# INLINE overColObjM #-}
@@ -138,7 +138,7 @@ overColVertex f (ShapeV a b) = ShapeV a (f b)
overPosObj :: (Point3 -> Point3) -> ShapeObj -> ShapeObj
{-# INLINE overPosObj #-}
overPosObj f (ShapeObj st vs) = ShapeObj st $ VS.map (overPosVertex f) vs
overPosObj f (ShapeObj st vs) = ShapeObj st $ S.map (overPosVertex f) vs
overPosVertex :: (Point3 -> Point3) -> ShapeV -> ShapeV
{-# INLINE overPosVertex #-}