From: David Wells Date: Tue, 7 May 2019 15:49:04 +0000 (-0400) Subject: Fix compatibility with nanoflann 1.3. X-Git-Tag: v9.1.0-rc1~91^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68b97bef9d8331faba7655adda0b4ff1f761f54b;p=dealii.git 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). --- 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