From 561a23023ac71b9460f0444977041aa7cbff95d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csik=C3=B3s=20Attila?= Date: Tue, 26 Mar 2024 19:55:28 +0100 Subject: [PATCH] Fix of Insert: Child nodes are attached in order --- adaptortests/test.cpp | 2 +- octree.h | 7 ++++++- unittests/adaptor.tests.cpp | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/adaptortests/test.cpp b/adaptortests/test.cpp index 5504712..96d42c9 100644 --- a/adaptortests/test.cpp +++ b/adaptortests/test.cpp @@ -340,7 +340,7 @@ namespace tree.Insert(pointNo - 1, points.back()); tree.template Erase(0, points[0]); auto const entityIDsInDFS_AfterErase_Actual = tree.CollectAllIdInDFS(); - auto const entityIDsInDFS_AfterErase_Expected = std::vector{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 }; + auto const entityIDsInDFS_AfterErase_Expected = std::vector{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 }; auto const entityIDsKNNActual = tree.GetNearestNeighbors(pointOfkNN, 3, points); auto const entityIDsKNNExpected = std::vector{ 1, 10, 8 }; diff --git a/octree.h b/octree.h index bddbb2e..a3bd299 100644 --- a/octree.h +++ b/octree.h @@ -971,7 +971,6 @@ namespace OrthoTree inline Node& createChild(Node& parentNode, ChildID childID, MortonNodeIDCR childKey) noexcept { assert(childID < this->CHILD_NO); - parentNode.AddChild(childKey); auto& nodeChild = m_nodes[childKey]; if constexpr (std::is_integral_v) @@ -1110,7 +1109,10 @@ namespace OrthoTree if (parentNode.HasChild(childNodeKey)) return childNodesCache.emplace_back(childNodeKey, this->m_nodes.at(childNodeKey)).second; else + { + parentNode.AddChildInOrder(childNodeKey); return childNodesCache.emplace_back(childNodeKey, this->createChild(parentNode, childID, childNodeKey)).second; + } }; autoce isPointSolution = std::is_same_v; @@ -1189,6 +1191,7 @@ namespace OrthoTree autoc childID = getChildIDByDepth(parentDepth, this->GetDepthID(entityNodeKey), entityNodeKey); autoc childNodeKey = parentFlag | MortonGridID(childID); + parentNode.AddChildInOrder(childNodeKey); auto& nodeChild = this->createChild(parentNode, childID, childNodeKey); nodeChild.Entities.emplace_back(entityID); } @@ -2042,6 +2045,7 @@ namespace OrthoTree MortonGridID const childKey = parentKeyFlag | actualChildGridID; MortonGridID const beginChildGridID = gridID + actualChildGridID * stepNo; + parentNode.AddChild(childKey); auto& childNode = this->createChild(parentNode, actualChildID, childKey); this->addNodes(childNode, childKey, locationBeginIterator, actualEndIterator, beginChildGridID, remainingDepth); } @@ -2519,6 +2523,7 @@ namespace OrthoTree MortonGridID const childKey = parentFlag | actualChildID_; MortonGridID const firstChildLocationID = firstLocationID + actualChildID_ * locationStepNo; + parentNode.AddChild(childKey); auto& nodeChild = this->createChild(parentNode, actualChildID, childKey); this->addNodes(nodeChild, childKey, beginLocationIterator, actualEndLocationIterator, firstChildLocationID, remainingDepthNo); } diff --git a/unittests/adaptor.tests.cpp b/unittests/adaptor.tests.cpp index c464fcf..00251e1 100644 --- a/unittests/adaptor.tests.cpp +++ b/unittests/adaptor.tests.cpp @@ -213,7 +213,7 @@ namespace AdaptorTest Assert::IsTrue(vector{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS); Assert::IsTrue(vector{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS); - Assert::IsTrue(vector{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); + Assert::IsTrue(vector{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); } TEST_METHOD(BoxGeneral2DC_Example2) @@ -349,7 +349,7 @@ namespace AdaptorTest Assert::IsTrue(vector{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS); Assert::IsTrue(vector{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS); - Assert::IsTrue(vector{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); + Assert::IsTrue(vector{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); } TEST_METHOD(BoxGeneral2DC_Example2) @@ -594,7 +594,7 @@ namespace AdaptorTest Assert::IsTrue(vector{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS); Assert::IsTrue(vector{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS); - Assert::IsTrue(vector{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); + Assert::IsTrue(vector{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase); } TEST_METHOD(BoxGeneral2DC_Example2)