From 82bb1d438b4600a3e220c7882d64a868bbd08676 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Thu, 9 Nov 2017 19:36:13 +0000 Subject: [PATCH] Correct bug in tree creation leading to Empty leaves --- src/Lib.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Lib.hs b/src/Lib.hs index 51d717b..a4b942b 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -143,7 +143,7 @@ insertBody b t = case t of -- If it is empty, we turn it into a singleton Region, adjusting its -- mass and center of mass. However, if the body is too far away -- (i.e. outside the diameter of the Region), we just ignore it. - Empty r -> if distance (_bodyPosition b) (_regionCenter r) > (_regionDiameter r / 2) + Empty r -> if distance (_bodyPosition b) (_regionCenter r) > (_regionDiameter r) then Empty r else Single (updateRegion b r) b -- If it is a singleton, we create the 8 subtrees and we insert the @@ -170,6 +170,11 @@ insertBody b t = case t of -- | Build a Barnes-Hut Octree from a list of Bodies buildTree :: [Body] -> Octree +buildTree [] = Empty (Region { _regionCenter = P $ V3 0 0 0, + _regionCenterOfMass = P $ V3 0 0 0, + _regionMass = 0, + _regionDiameter = 0 + }) buildTree bs = foldr insertBody (Empty r) bs where r = Region { _regionCenter = center, _regionCenterOfMass = center,