From 6c3dc1d22075aa464f8b0b2e0bd8cffd2e46e609 Mon Sep 17 00:00:00 2001 From: Sebastian Dorda Date: Sat, 18 Jul 2015 19:06:19 +0200 Subject: [PATCH 1/2] fix typo --- src/RTree/RTree.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RTree/RTree.cs b/src/RTree/RTree.cs index 1b03e42..5ed4487 100644 --- a/src/RTree/RTree.cs +++ b/src/RTree/RTree.cs @@ -204,7 +204,7 @@ private void Insert(RTreeNode item, int level) } // adjust bboxes along the insertion path - AdjutsParentBounds(envelope, insertPath, level); + AdjustParentBounds(envelope, insertPath, level); } private static int CombinedArea(Envelope what, Envelope with) @@ -456,7 +456,7 @@ private static Envelope SumChildBounds(RTreeNode node, int startIndex, int en return retval; } - private static void AdjutsParentBounds(Envelope bbox, List> path, int level) + private static void AdjustParentBounds(Envelope bbox, List> path, int level) { // adjust bboxes along the given tree path for (var i = level; i >= 0; i--) From b83748190c0f7205701ea4189af558f8be341347 Mon Sep 17 00:00:00 2001 From: Sebastian Dorda Date: Sat, 18 Jul 2015 19:09:43 +0200 Subject: [PATCH 2/2] fix removing could accidentally clear the whole tree. The path list in CondenseNodes in the C# implementation seems to be reverted in comparison to the original JS implementation. --- src/RTree/RTree.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/RTree/RTree.cs b/src/RTree/RTree.cs index 5ed4487..7c655bd 100644 --- a/src/RTree/RTree.cs +++ b/src/RTree/RTree.cs @@ -416,24 +416,26 @@ public void Remove(T item, Envelope envelope) private void CondenseNodes(IList> path) { + var count = path.Count; + // go through the path, removing empty nodes and updating bboxes - for (var i = path.Count - 1; i >= 0; i--) + for (var i = 0; i < count; i++) { - if (path[i].Children.Count == 0) + if (path[i].Children.Count == 0) { - if (i == 0) + if (i == count - 1) { - Clear(); + Clear(); } else { - var siblings = path[i - 1].Children; - siblings.Remove(path[i]); - } + var siblings = path[i + 1].Children; + siblings.Remove(path[i]); + } } else { - RefreshEnvelope(path[i]); + RefreshEnvelope(path[i]); } } }