Use PeriodicTree for periodic boundary conditions
masterA PeriodicTree wraps an existing KDTree, BallTree, or BruteTree to handle periodic domains. This is essential for simulations where points wrap around boundaries.
Constructor:
PeriodicTree(tree, bounds_min, bounds_max)
bounds_min/bounds_max: Vectors defining the periodic domain. UseInfinbounds_maxfor dimensions that are not periodic.
Mixed Dimensions:
You can define a domain where some dimensions are periodic and others are infinite (non-periodic) by using Inf in the bounds_max vector.
using NearestNeighbors, StaticArrays
# 2D domain: x-periodic, y-infinite
data = [SVector(1.0, 2.0), SVector(9.0, 8.0)]
kdtree = KDTree(data)
ptree = PeriodicTree(kdtree, [0.0, 0.0], [10.0, Inf])
# Query near x-boundary finds wrapped neighbor
query = [0.5, 3.0]
idxs, dists = knn(ptree, query, 1)