Skip to content

Commit

Permalink
Fix middleSplit_ for same points
Browse files Browse the repository at this point in the history
  • Loading branch information
Yahor Zabalotski authored and Yahor Zabalotski committed Oct 30, 2024
1 parent d2fdfed commit 549a5e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/nanoflann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ class KDTreeBaseClass
NodePtr divideTree(
Derived& obj, const Offset left, const Offset right, BoundingBox& bbox)
{
assert(left < obj.dataset_.kdtree_get_point_count());

NodePtr node = obj.pool_.template allocate<Node>(); // allocate memory
const auto dims = (DIM > 0 ? DIM : obj.dim_);

Expand Down Expand Up @@ -1306,7 +1308,7 @@ class KDTreeBaseClass
for (Dimension i = 0; i < dims; ++i)
{
ElementType span = bbox[i].high - bbox[i].low;
if (span > (1 - EPS) * max_span)
if (span >= (1 - EPS) * max_span)
{
ElementType min_elem_, max_elem_;
computeMinMax(obj, ind, count, i, min_elem_, max_elem_);
Expand Down
19 changes: 19 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,22 @@ TEST(kdtree, L2_concurrent_build_vs_L2)
L2_concurrent_build_vs_L2_test<double>(100, 7);
}
}

TEST(kdtree, same_points)
{
using num_t = double;
using point_cloud_t = PointCloud<num_t>;
using kdtree_t = KDTreeSingleIndexAdaptor<
L2_Simple_Adaptor<num_t, point_cloud_t>, point_cloud_t, 3 /* dim */>;

point_cloud_t cloud;
cloud.pts.resize(16);
for (size_t i = 0; i < 16; ++i)
{
cloud.pts[i].x = -1.;
cloud.pts[i].y = 0.;
cloud.pts[i].z = 1.;
}

kdtree_t idx(3 /*dim*/, cloud);
}

0 comments on commit 549a5e3

Please sign in to comment.