From 68b97bef9d8331faba7655adda0b4ff1f761f54b Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 7 May 2019 11:49:04 -0400 Subject: [PATCH] Fix compatibility with nanoflann 1.3. It looks like nanoflann switched to doing all computations with squared distances so all of our tests currently fail with the latest release. This PR fixes the problem by adding nanoflann version checks (so our interface is the same). --- source/numerics/kdtree.cc | 14 ++++++++++++++ tests/numerics/kdtree_01.cc | 2 ++ 2 files changed, 16 insertions(+) diff --git a/source/numerics/kdtree.cc b/source/numerics/kdtree.cc index 27e41afe0e..0d2bdc1658 100644 --- a/source/numerics/kdtree.cc +++ b/source/numerics/kdtree.cc @@ -48,7 +48,15 @@ KDTree::get_points_within_ball(const Point ¢er, params.sorted = sorted; std::vector> matches; +# if NANOFLANN_VERSION < 0x130 kdtree->radiusSearch(center.begin_raw(), radius, matches, params); +# else + // nanoflann 1.3 performs distance comparisons with squared distances, so + // square the radius before we query and square root after: + kdtree->radiusSearch(center.begin_raw(), radius * radius, matches, params); + for (std::pair &match : matches) + match.second = std::sqrt(match.second); +# endif return matches; } @@ -75,7 +83,13 @@ KDTree::get_closest_points(const Point & target, // convert it to the format we want to return std::vector> matches(n_points); for (unsigned int i = 0; i < n_points; ++i) +# if NANOFLANN_VERSION < 0x130 matches[i] = std::make_pair(indices[i], distances[i]); +# else + // nanoflann 1.3 performs distance comparisons with squared distances, so + // take a square root: + matches[i] = std::make_pair(indices[i], std::sqrt(distances[i])); +# endif return matches; } diff --git a/tests/numerics/kdtree_01.cc b/tests/numerics/kdtree_01.cc index 4f05bf259d..a28c22e764 100644 --- a/tests/numerics/kdtree_01.cc +++ b/tests/numerics/kdtree_01.cc @@ -50,6 +50,8 @@ main() auto res = kdtree.get_closest_points(p, 1)[0]; deallog << "P: " << p << ", distance: " << res.second << ", index: " << res.first << std::endl; + AssertThrow(std::abs(points[res.first].distance(p) - res.second) < 1e-10, + ExcInternalError()); } deallog -- 2.39.5