Zone creatures
This commit is contained in:
@@ -8,6 +8,9 @@ module Geometry.Data
|
||||
import Linear.V2
|
||||
import Linear.V3
|
||||
import Linear.V4
|
||||
import Streaming
|
||||
type StreamOf a = Stream (Of a) Identity ()
|
||||
type Int2 = V2 Int
|
||||
type Point2 = V2 Float
|
||||
type Point3 = V3 Float
|
||||
type Point4 = V4 Float
|
||||
|
||||
+11
-10
@@ -10,6 +10,7 @@ module Geometry.Zone
|
||||
, xIntercepts
|
||||
, yIntercepts
|
||||
, divTo
|
||||
, zoneOfPoint
|
||||
) where
|
||||
import Geometry.Data
|
||||
|
||||
@@ -90,9 +91,9 @@ modTo s x = x - s * fromIntegral (divTo s x)
|
||||
-- | abs (sx-ex) > abs (sy-ey) = f sp ep
|
||||
-- | otherwise = map flipV $ f (flipV sp) (flipV ep)
|
||||
|
||||
sizeZoneOfPoint' :: Float -> Point2 -> V2 Int
|
||||
{-# INLINE sizeZoneOfPoint' #-}
|
||||
sizeZoneOfPoint' s = fmap (divTo s)
|
||||
zoneOfPoint :: Float -> Point2 -> V2 Int
|
||||
{-# INLINE zoneOfPoint #-}
|
||||
zoneOfPoint s = fmap (divTo s)
|
||||
|
||||
--increasingInterval :: Int -> Int -> [Int]
|
||||
--increasingInterval x y
|
||||
@@ -128,7 +129,7 @@ ddaExt' s sp@(V2 sx sy) ep@(V2 ex ey)
|
||||
$ map (IS.singleton . divTo s) [x1y,x1y+ydx..]
|
||||
| otherwise = ddaExt' s ep sp
|
||||
where
|
||||
addsp im = let V2 x y = sizeZoneOfPoint' s sp
|
||||
addsp im = let V2 x y = zoneOfPoint s sp
|
||||
in insertXY im (x,y)
|
||||
x1 = divTo s sx
|
||||
x2 = divTo s ex
|
||||
@@ -148,8 +149,8 @@ ddaExt' s sp@(V2 sx sy) ep@(V2 ex ey)
|
||||
ddaSqStream :: Float -> Point2 -> Point2 -> Stream (Of (V2 Int)) Identity ()
|
||||
ddaSqStream s sp ep = S.each [V2 x y | x <- makeInterval sx ex, y <- makeInterval sy ey]
|
||||
where
|
||||
V2 sx sy = sizeZoneOfPoint' s sp
|
||||
V2 ex ey = sizeZoneOfPoint' s ep
|
||||
V2 sx sy = zoneOfPoint s sp
|
||||
V2 ex ey = zoneOfPoint s ep
|
||||
|
||||
makeInterval :: Int -> Int -> [Int]
|
||||
makeInterval x y
|
||||
@@ -157,16 +158,16 @@ makeInterval x y
|
||||
| otherwise = [y-1..x+1]
|
||||
|
||||
ddaStream :: Float -> Point2 -> Point2 -> Stream (Of (V2 Int)) Identity ()
|
||||
ddaStream s sp ep = S.map (sizeZoneOfPoint' s)
|
||||
ddaStream s sp ep = S.map (zoneOfPoint s)
|
||||
$ S.yield sp
|
||||
<> xIntercepts s sp ep
|
||||
<> yIntercepts s sp ep
|
||||
|
||||
ddaStreamX :: Float -> Point2 -> Point2 -> Stream (Of (V2 Int)) Identity ()
|
||||
ddaStreamX s sp ep = S.map (sizeZoneOfPoint' s) $ xIntercepts s sp ep
|
||||
ddaStreamX s sp ep = S.map (zoneOfPoint s) $ xIntercepts s sp ep
|
||||
|
||||
ddaStreamY :: Float -> Point2 -> Point2 -> Stream (Of (V2 Int)) Identity ()
|
||||
ddaStreamY s sp ep = S.map (sizeZoneOfPoint' s) $ yIntercepts s sp ep
|
||||
ddaStreamY s sp ep = S.map (zoneOfPoint s) $ yIntercepts s sp ep
|
||||
|
||||
xIntercepts :: Float -> Point2 -> Point2 -> Stream (Of Point2) Identity ()
|
||||
{-# INLINE xIntercepts #-}
|
||||
@@ -200,7 +201,7 @@ ddaExt s sp@(V2 sx sy) ep@(V2 ex ey)
|
||||
| otherwise = addsp . addys . IM.fromDistinctAscList $ zip [x2-1 .. x1-1]
|
||||
$ map (IS.singleton . divTo s) [x2y,x2y+ydx..]
|
||||
where
|
||||
addsp im = let V2 x y = sizeZoneOfPoint' s sp
|
||||
addsp im = let V2 x y = zoneOfPoint s sp
|
||||
in insertXY im (x,y)
|
||||
x1 = divTo s sx
|
||||
x2 = divTo s ex
|
||||
|
||||
Reference in New Issue
Block a user