diff --git a/Octree/include/CGAL/Octree.h b/Octree/include/CGAL/Octree.h index 8a9ac95c15f..4916fb7f794 100644 --- a/Octree/include/CGAL/Octree.h +++ b/Octree/include/CGAL/Octree.h @@ -383,11 +383,6 @@ public: // Invoking the recursive function adds those points to the vector (passed by reference) nearest_k_neighbours_recursive(search_point, points_list, m_root, std::numeric_limits::max()); - // Sort the list by distance - std::sort(points_list.begin(), points_list.end(), [=](auto &left, auto &right) { - return left.second < right.second; - }); - // Add all the points found to the output for (auto &item : points_list) *output++ = item.first; diff --git a/Octree/test/Octree/test_octree_nearest_neighbour.cpp b/Octree/test/Octree/test_octree_nearest_neighbour.cpp index e36b592a66d..9311981cb2f 100644 --- a/Octree/test/Octree/test_octree_nearest_neighbour.cpp +++ b/Octree/test/Octree/test_octree_nearest_neighbour.cpp @@ -123,18 +123,23 @@ void kdtree_vs_octree(std::size_t dataset_size) { Kd_tree kd_tree(points.points().begin(), points.points().end()); { Kd_tree_search search(kd_tree, random_point, K); + for (auto p : search) kd_tree_nearest_neighbours.push_back(p.first); } + // Sort the list by distance + std::sort(kd_tree_nearest_neighbours.begin(), kd_tree_nearest_neighbours.end(), [=](auto &left, auto &right) { + return CGAL::squared_distance(random_point, left) < CGAL::squared_distance(random_point, right); + }); + + std::cout << "Kd_tree --> " - << "Closest point to " - << "(" << random_point << ") " - << "is " - << "(" << kd_tree_nearest_neighbours[0] << ") " - << "at a distance^2 of " - << CGAL::squared_distance(kd_tree_nearest_neighbours[0], random_point) - << std::endl; + << kd_tree_nearest_neighbours.size() << " points " + << "at distances "; + for (int k = 0; k < kd_tree_nearest_neighbours.size(); ++k) + std::cout << CGAL::squared_distance(kd_tree_nearest_neighbours[k], random_point) << ", "; + std::cout << std::endl; // Do the same using the octree std::vector octree_nearest_neighbours; @@ -145,14 +150,17 @@ void kdtree_vs_octree(std::size_t dataset_size) { octree.nearest_k_neighbours(random_point, K, std::back_inserter(octree_nearest_neighbours)); } + // Sort the list by distance + std::sort(octree_nearest_neighbours.begin(), octree_nearest_neighbours.end(), [=](auto &left, auto &right) { + return CGAL::squared_distance(random_point, left) < CGAL::squared_distance(random_point, right); + }); + std::cout << "Octree --> " - << "Closest point to " - << "(" << random_point << ") " - << "is " - << "(" << octree_nearest_neighbours[0] << ") " - << "at a distance^2 of " - << CGAL::squared_distance(octree_nearest_neighbours[0], random_point) - << std::endl; + << octree_nearest_neighbours.size() << " points " + << "at distances "; + for (int k = 0; k < octree_nearest_neighbours.size(); ++k) + std::cout << CGAL::squared_distance(octree_nearest_neighbours[k], random_point) << ", "; + std::cout << std::endl; // Check that they produce the same answer for (int j = 0; j < K; ++j) {