From 78a3dd8b9501b34354caad25950bfff3897d90d1 Mon Sep 17 00:00:00 2001 From: hasufell Date: Sun, 30 Nov 2014 20:04:02 +0100 Subject: [PATCH] ALGO: avoid printing KTNil for both childs --- Algorithms/KDTree/KDTree.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Algorithms/KDTree/KDTree.hs b/Algorithms/KDTree/KDTree.hs index b0c55b2..5822fd2 100644 --- a/Algorithms/KDTree/KDTree.hs +++ b/Algorithms/KDTree/KDTree.hs @@ -125,14 +125,16 @@ rangeSearch kd' sq' = (goPt kd' sq', goTree kd' sq' True) -- A pretty rose tree suitable for printing. goTree :: KDTree PT -> Square -> Bool -> Tree String goTree KTNil _ _ = Node "nil" [] - goTree (KTNode ln pt dir rn) sq vis = - Node treeText - [if' (p1' dir sq < (cur' dir . unp2 $ pt)) - (goTree ln sq vis) - (goTree ln sq False) - , if' ((cur' dir . unp2 $ pt) < p2' dir sq) - (goTree rn sq vis) - (goTree rn sq False)] + goTree (KTNode ln pt dir rn) sq vis + | ln == KTNil && rn == KTNil = Node treeText [] + | otherwise = + Node treeText + [if' (p1' dir sq < (cur' dir . unp2 $ pt)) + (goTree ln sq vis) + (goTree ln sq False) + , if' ((cur' dir . unp2 $ pt) < p2' dir sq) + (goTree rn sq vis) + (goTree rn sq False)] where treeText | vis && inRange sq pt = "** " ++ (show . unp2 $ pt)