Skip to content

Commit

Permalink
Fix and add test for intersects(kdop, box) for 2D
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed May 16, 2024
1 parent 582f9d4 commit 5fb410e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
61 changes: 42 additions & 19 deletions src/geometry/ArborX_KDOP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,33 +250,56 @@ struct expand<KDOPTag, BoxTag, KDOP, Box>
{
KOKKOS_FUNCTION static void apply(KDOP &kdop, Box const &box)
{
constexpr int DIM = GeometryTraits::dimension_v<KDOP>;
static_assert(DIM == 2 || DIM == 3);

// NOTE if any of the ranges is invalid, the code below would actually
// expand the KDOP which is not what we want.
// We may revisit this later and decide passing a valid box becomes a
// precondition but this would be a breaking change (going from a wide to a
// narrow contract).
for (int i = 0; i < 3; ++i)
if (box.minCorner()[i] > box.maxCorner()[i])
for (int d = 0; d < DIM; ++d)
if (box.minCorner()[d] > box.maxCorner()[d])
return;

auto const xmin = box.minCorner()[0];
auto const ymin = box.minCorner()[1];
auto const zmin = box.minCorner()[2];
auto const xmax = box.maxCorner()[0];
auto const ymax = box.maxCorner()[1];
auto const zmax = box.maxCorner()[2];
for (auto const &point : {
Point{xmin, ymin, zmin},
Point{xmin, ymax, zmin},
Point{xmin, ymin, zmax},
Point{xmin, ymax, zmax},
Point{xmax, ymin, zmin},
Point{xmax, ymax, zmin},
Point{xmax, ymin, zmax},
Point{xmax, ymax, zmax},
})
using Point = std::decay_t<decltype(box.minCorner())>;
if constexpr (DIM == 3)
{
Details::expand(kdop, point);
auto const xmin = box.minCorner()[0];
auto const ymin = box.minCorner()[1];
auto const zmin = box.minCorner()[2];
auto const xmax = box.maxCorner()[0];
auto const ymax = box.maxCorner()[1];
auto const zmax = box.maxCorner()[2];
for (auto const &point : {
Point{xmin, ymin, zmin},
Point{xmin, ymax, zmin},
Point{xmin, ymin, zmax},
Point{xmin, ymax, zmax},
Point{xmax, ymin, zmin},
Point{xmax, ymax, zmin},
Point{xmax, ymin, zmax},
Point{xmax, ymax, zmax},
})
{
Details::expand(kdop, point);
}
}
else
{
auto const xmin = box.minCorner()[0];
auto const ymin = box.minCorner()[1];
auto const xmax = box.maxCorner()[0];
auto const ymax = box.maxCorner()[1];
for (auto const &point : {
Point{xmin, ymin},
Point{xmin, ymax},
Point{xmax, ymin},
Point{xmax, ymax},
})
{
Details::expand(kdop, point);
}
}
}
};
Expand Down
15 changes: 15 additions & 0 deletions test/tstKDOP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <ArborX_Box.hpp>
#include <ArborX_DetailsAlgorithms.hpp>
#include <ArborX_HyperBox.hpp>
#include <ArborX_HyperPoint.hpp>
#include <ArborX_KDOP.hpp>
#include <ArborX_Point.hpp>
Expand Down Expand Up @@ -38,6 +39,20 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_2D, KDOP_t, KDOP_2D_types)
BOOST_TEST(!intersects(x, KDOP_t{}));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_box_2D, KDOP_t, KDOP_2D_types)
{
using Point = ArborX::ExperimentalHyperGeometry::Point<2>;
using Box = ArborX::ExperimentalHyperGeometry::Box<2>;

KDOP_t x;
BOOST_TEST(!intersects(x, Box{}));
BOOST_TEST(!intersects(x, Box{{0, 0}, {1, 1}}));
expand(x, Point{1, 0});
expand(x, Point{0, 1});
BOOST_TEST(!intersects(x, Box{}));
BOOST_TEST(intersects(x, Box{{0, 0}, {1, 1}}));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop_2D, KDOP_t, KDOP_2D_types)
{
using Point = ArborX::ExperimentalHyperGeometry::Point<2>;
Expand Down

0 comments on commit 5fb410e

Please sign in to comment.