Add SearchTree
Class and integrate with VoronoiMeshSnapshot
#226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Introduced a new
SearchTree
class in theutils/
directory, implemented as a general-purpose k-d tree. The class provides a spatial data structure for efficient nearest-neighbor searches to an input position inO(log(N))
time.Additionally, the
VoronoiMeshSnapshot
class has been updated to replace its private nestedNode
class with the newSearchTree
.Motivation
The upcoming Tetrahedral grid requires a k-d search tree. Moving the search tree implementation to a shared class improves code maintainability. This class is now also available for future features requiring k-d tree functionality.
Tests
All tests passed, including all Voronoi tests that rely on the new
SearchTree
. No additional tests were deemed necessary, as the current tests sufficiently cover the implementation of theSearchTree
.Code Guidelines
Efforts were made to adhere to SKIRT guidelines. Feel free to highlight any required corrections.
Additional changes to
VoronoiMeshSnapshot
Cell
class no longer stores the site positions. Instead, these are maintained in a separate field:std::vector<Vec> _sites
. This change was necessary to allow for the generic implementation ofSearchTree
, which operates on astd::vector
of node positions. The_blocktrees
and_blocklists
remain within theVoronoiMeshSnapshot
class, as these are only relevant when the Voronoi cell or its bounding box are available for every node. Since a node belongs to a block precisely if its Voronoi cell (or bounding box for simplicity) intersects that block.removeCells
method ensures that_cells
and_sites
remain synchronized when cells are removed.buildMesh
function previously usedstd::sort
for efficiently finding cells that were too close. This sort now has to be applied to both_cells
and_sites
, ensuring consistent ordering between the two. The current approach may seem somewhat convoluted, but it remains efficient.