Skip to content

Commit

Permalink
Fix of Insert: Child nodes are attached in order
Browse files Browse the repository at this point in the history
  • Loading branch information
attcs committed Mar 26, 2024
1 parent 75bd3e4 commit 561a230
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion adaptortests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ namespace
tree.Insert(pointNo - 1, points.back());
tree.template Erase<false>(0, points[0]);
auto const entityIDsInDFS_AfterErase_Actual = tree.CollectAllIdInDFS();
auto const entityIDsInDFS_AfterErase_Expected = std::vector<std::size_t>{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 };
auto const entityIDsInDFS_AfterErase_Expected = std::vector<std::size_t>{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 };

auto const entityIDsKNNActual = tree.GetNearestNeighbors(pointOfkNN, 3, points);
auto const entityIDsKNNExpected = std::vector<std::size_t>{ 1, 10, 8 };
Expand Down
7 changes: 6 additions & 1 deletion octree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TGeometry>)
Expand Down Expand Up @@ -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<TVector, TData>;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions unittests/adaptor.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ namespace AdaptorTest

Assert::IsTrue(vector<std::size_t>{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS);
Assert::IsTrue(vector<std::size_t>{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
}

TEST_METHOD(BoxGeneral2DC_Example2)
Expand Down Expand Up @@ -349,7 +349,7 @@ namespace AdaptorTest

Assert::IsTrue(vector<std::size_t>{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS);
Assert::IsTrue(vector<std::size_t>{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
}

TEST_METHOD(BoxGeneral2DC_Example2)
Expand Down Expand Up @@ -594,7 +594,7 @@ namespace AdaptorTest

Assert::IsTrue(vector<std::size_t>{ 7, 6, 5, 0, 2, 1, 8, 9, 3, 4 } == entityIDsInBFS);
Assert::IsTrue(vector<std::size_t>{ 0, 1, 8, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 9, 10, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
Assert::IsTrue(vector<std::size_t>{ 1, 8, 10, 9, 7, 6, 5, 2, 3, 4 } == entityIDsInDFS_AfterErase);
}

TEST_METHOD(BoxGeneral2DC_Example2)
Expand Down

0 comments on commit 561a230

Please sign in to comment.