From 0beaf09541df9ef846647e870f881e91ca3c6a81 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Thu, 24 Dec 2020 13:42:28 -0500 Subject: [PATCH] Add intersects(Sphere, Point) and intersects(Point, Sphere) --- src/details/ArborX_DetailsAlgorithms.hpp | 12 ++++++++++++ test/tstDetailsAlgorithms.cpp | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/details/ArborX_DetailsAlgorithms.hpp b/src/details/ArborX_DetailsAlgorithms.hpp index 02d54389d..e45318d0d 100644 --- a/src/details/ArborX_DetailsAlgorithms.hpp +++ b/src/details/ArborX_DetailsAlgorithms.hpp @@ -171,6 +171,18 @@ bool intersects(Sphere const &sphere, Box const &box) return distance(sphere.centroid(), box) <= sphere.radius(); } +KOKKOS_INLINE_FUNCTION +bool intersects(Sphere const &sphere, Point const &point) +{ + return distance(sphere.centroid(), point) <= sphere.radius(); +} + +KOKKOS_INLINE_FUNCTION +bool intersects(Point const &point, Sphere const &sphere) +{ + return intersects(sphere, point); +} + // calculate the centroid of a box KOKKOS_INLINE_FUNCTION void centroid(Box const &box, Point &c) diff --git a/test/tstDetailsAlgorithms.cpp b/test/tstDetailsAlgorithms.cpp index 03bf144dc..0d639af31 100644 --- a/test/tstDetailsAlgorithms.cpp +++ b/test/tstDetailsAlgorithms.cpp @@ -89,8 +89,13 @@ BOOST_AUTO_TEST_CASE(intersects) // unit sphere constexpr Sphere sphere{{{0., 0., 0.}}, 1.}; - BOOST_TEST(intersects(sphere, {{{0., 0., 0.}}, {{1., 1., 1.}}})); - BOOST_TEST(!intersects(sphere, {{{1., 2., 3.}}, {{4., 5., 6.}}})); + BOOST_TEST(intersects(sphere, Box{{{0., 0., 0.}}, {{1., 1., 1.}}})); + BOOST_TEST(!intersects(sphere, Box{{{1., 2., 3.}}, {{4., 5., 6.}}})); + BOOST_TEST(intersects(sphere, Point{0., 0.5, 0.5})); + BOOST_TEST(intersects(sphere, Point{0., 0., 1.0})); + BOOST_TEST(intersects(Point{-1., 0., 0.}, sphere)); + BOOST_TEST(intersects(Point{-0.6, -0.8, 0.}, sphere)); + BOOST_TEST(!intersects(Point{-0.7, -0.8, 0.}, sphere)); } BOOST_AUTO_TEST_CASE(equals)