Start using streaming as the way to consume foldable objects
This commit is contained in:
@@ -3,9 +3,12 @@ module Geometry.Zone
|
||||
( ddaExt
|
||||
, ddaExt'
|
||||
, ddaSq
|
||||
, ddaSqStream
|
||||
) where
|
||||
import Geometry.Data
|
||||
|
||||
import Streaming
|
||||
import qualified Streaming.Prelude as S
|
||||
import Data.Foldable
|
||||
import qualified Data.IntMap.Strict as IM
|
||||
import qualified Data.IntSet as IS
|
||||
@@ -89,6 +92,14 @@ ddaSq s (V2 sx sy) (V2 ex ey) = IM.fromSet (const ys) xs
|
||||
xs = IS.fromDistinctAscList [minx-1..maxx+1]
|
||||
ys = IS.fromDistinctAscList [miny-1..maxy+1]
|
||||
|
||||
ddaSqStream :: Monad m => Float -> V2 Float -> V2 Float -> Stream (Of (Int,Int)) m ()
|
||||
ddaSqStream s (V2 sx sy) (V2 ex ey) = S.each [(x,y) | x <- [minx..maxx], y <- [miny..maxy]]
|
||||
where
|
||||
maxMin a b | a >= b = (a,b)
|
||||
| otherwise = (b,a)
|
||||
(maxx,minx) = maxMin (divTo s sx) (divTo s ex)
|
||||
(maxy,miny) = maxMin (divTo s sy) (divTo s ey)
|
||||
|
||||
-- | Determines which horizontal and vertical lines on a grid are crossed by a
|
||||
-- line. For each adds the x-y index of the square to the right or above the
|
||||
-- crossed grid line. Also adds the index of the square containing the start
|
||||
|
||||
Reference in New Issue
Block a user