Skip to content

Commit 0e740cd

Browse files
authored
Merge pull request #250 from yzabalotski/fix_middle_split
Fix middleSplit_ for same points
2 parents d2fdfed + 549a5e3 commit 0e740cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

include/nanoflann.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ class KDTreeBaseClass
11351135
NodePtr divideTree(
11361136
Derived& obj, const Offset left, const Offset right, BoundingBox& bbox)
11371137
{
1138+
assert(left < obj.dataset_.kdtree_get_point_count());
1139+
11381140
NodePtr node = obj.pool_.template allocate<Node>(); // allocate memory
11391141
const auto dims = (DIM > 0 ? DIM : obj.dim_);
11401142

@@ -1306,7 +1308,7 @@ class KDTreeBaseClass
13061308
for (Dimension i = 0; i < dims; ++i)
13071309
{
13081310
ElementType span = bbox[i].high - bbox[i].low;
1309-
if (span > (1 - EPS) * max_span)
1311+
if (span >= (1 - EPS) * max_span)
13101312
{
13111313
ElementType min_elem_, max_elem_;
13121314
computeMinMax(obj, ind, count, i, min_elem_, max_elem_);

tests/test_main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,22 @@ TEST(kdtree, L2_concurrent_build_vs_L2)
815815
L2_concurrent_build_vs_L2_test<double>(100, 7);
816816
}
817817
}
818+
819+
TEST(kdtree, same_points)
820+
{
821+
using num_t = double;
822+
using point_cloud_t = PointCloud<num_t>;
823+
using kdtree_t = KDTreeSingleIndexAdaptor<
824+
L2_Simple_Adaptor<num_t, point_cloud_t>, point_cloud_t, 3 /* dim */>;
825+
826+
point_cloud_t cloud;
827+
cloud.pts.resize(16);
828+
for (size_t i = 0; i < 16; ++i)
829+
{
830+
cloud.pts[i].x = -1.;
831+
cloud.pts[i].y = 0.;
832+
cloud.pts[i].z = 1.;
833+
}
834+
835+
kdtree_t idx(3 /*dim*/, cloud);
836+
}

0 commit comments

Comments
 (0)