aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Spear/Math/Octree.hs30
1 files changed, 16 insertions, 14 deletions
diff --git a/Spear/Math/Octree.hs b/Spear/Math/Octree.hs
index 74689a0..1e257eb 100644
--- a/Spear/Math/Octree.hs
+++ b/Spear/Math/Octree.hs
@@ -26,22 +26,22 @@ import qualified Data.Foldable as F
26data Octree e 26data Octree e
27 = Octree 27 = Octree
28 { 28 {
29 root :: AABB, 29 root :: !AABB,
30 ents :: [e], 30 ents :: ![e],
31 c1 :: Octree e, 31 c1 :: !(Octree e),
32 c2 :: Octree e, 32 c2 :: !(Octree e),
33 c3 :: Octree e, 33 c3 :: !(Octree e),
34 c4 :: Octree e, 34 c4 :: !(Octree e),
35 c5 :: Octree e, 35 c5 :: !(Octree e),
36 c6 :: Octree e, 36 c6 :: !(Octree e),
37 c7 :: Octree e, 37 c7 :: !(Octree e),
38 c8 :: Octree e 38 c8 :: !(Octree e)
39 } 39 }
40 | 40 |
41 Leaf 41 Leaf
42 { 42 {
43 root :: AABB, 43 root :: !AABB,
44 ents :: [e] 44 ents :: ![e]
45 } 45 }
46 46
47 47
@@ -180,7 +180,7 @@ extract (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) = (Octree root [] c1' c2' c3'
180 180
181 181
182-- | Applies the given function to the entities in the octree. 182-- | Applies the given function to the entities in the octree.
183-- Entities that break out of their cell are reallocated appropiately. 183-- Entities that break out of their cell are reallocated appropriately.
184map :: (e -> AABB -> CollisionType) -> (e -> e) -> Octree e -> Octree e 184map :: (e -> AABB -> CollisionType) -> (e -> e) -> Octree e -> Octree e
185map testAABB f o = let (o', outliers) = map' testAABB f o in insertl testAABB o' outliers 185map testAABB f o = let (o', outliers) = map' testAABB f o in insertl testAABB o' outliers
186 186
@@ -212,7 +212,7 @@ map' testAABB f (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) =
212 212
213 213
214-- | Applies a function to the entity groups in the octree. 214-- | Applies a function to the entity groups in the octree.
215-- Entities that break out of their cell are reallocated appropiately. 215-- Entities that break out of their cell are reallocated appropriately.
216gmap :: (e -> AABB -> CollisionType) -> (e -> e -> e) -> Octree e -> Octree e 216gmap :: (e -> AABB -> CollisionType) -> (e -> e -> e) -> Octree e -> Octree e
217gmap testAABB f o = let (o', outliers) = gmap' testAABB f o in insertl testAABB o' outliers 217gmap testAABB f o = let (o', outliers) = gmap' testAABB f o in insertl testAABB o' outliers
218 218
@@ -248,6 +248,7 @@ population = F.foldr (\_ acc -> acc+1) 0
248 248
249 249
250instance Functor Octree where 250instance Functor Octree where
251
251 fmap f (Leaf root ents) = Leaf root $ fmap f ents 252 fmap f (Leaf root ents) = Leaf root $ fmap f ents
252 253
253 fmap f (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) = 254 fmap f (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) =
@@ -265,6 +266,7 @@ instance Functor Octree where
265 266
266 267
267instance F.Foldable Octree where 268instance F.Foldable Octree where
269
268 foldMap f (Leaf root ents) = mconcat . fmap f $ ents 270 foldMap f (Leaf root ents) = mconcat . fmap f $ ents
269 271
270 foldMap f (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) = 272 foldMap f (Octree root ents c1 c2 c3 c4 c5 c6 c7 c8) =