Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add intersects(Sphere, Point) and intersects(Point, Sphere) #584

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/details/ArborX_DetailsAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions test/tstDetailsAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down