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 KDOP<2,4> and KDOP<2,8> #1088

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 32 additions & 0 deletions src/geometry/ArborX_KDOP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ namespace Details
template <int DIM, int k, typename Coordinate>
struct KDOP_Directions;

template <typename Coordinate>
struct KDOP_Directions<2, 4, Coordinate>
{
static constexpr int n_directions = 2;
static KOKKOS_FUNCTION auto const &directions()
{
using Direction = Vector<2, Coordinate>;
static constexpr Kokkos::Array<Direction, n_directions> directions = {
Direction{1, 0},
Direction{0, 1},
};
return directions;
}
};

template <typename Coordinate>
struct KDOP_Directions<2, 8, Coordinate>
{
static constexpr int n_directions = 4;
static KOKKOS_FUNCTION auto const &directions()
{
using Direction = Vector<2, Coordinate>;
static constexpr Kokkos::Array<Direction, n_directions> directions = {
Direction{1, 0},
Direction{0, 1},
Direction{1, 1},
Direction{1, -1},
};
return directions;
}
};

template <typename Coordinate>
struct KDOP_Directions<3, 6, Coordinate>
{
Expand Down
82 changes: 74 additions & 8 deletions test/tstKDOP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,88 @@
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#include <ArborX_Box.hpp>
#include <ArborX_DetailsAlgorithms.hpp>
#include <ArborX_HyperPoint.hpp>
#include <ArborX_KDOP.hpp>
#include <ArborX_Point.hpp>

#include "BoostTest_CUDA_clang_workarounds.hpp"
#include <boost/test/unit_test.hpp>

#include <tuple>
#include <type_traits>

using ArborX::Box;
using ArborX::Point;
using ArborX::Experimental::KDOP;

using KDOP_types =
std::tuple<KDOP<3, 6>, KDOP<3, 14>, KDOP<3, 18>, KDOP<3, 26>>;

BOOST_AUTO_TEST_SUITE(DiscreteOrientedPolytopes)

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_KDOP, KDOP_t, KDOP_types)
using KDOP_2D_types = std::tuple<KDOP<2, 4>, KDOP<2, 8>>;

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_2D, KDOP_t, KDOP_2D_types)
{
using Point = ArborX::ExperimentalHyperGeometry::Point<2>;
KDOP_t x;
BOOST_TEST(!intersects(x, x));
expand(x, Point{1, 0});
expand(x, Point{0, 1});
BOOST_TEST(intersects(x, x));
BOOST_TEST(!intersects(x, KDOP_t{}));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop_2D, KDOP_t, KDOP_2D_types)
{
using Point = ArborX::ExperimentalHyperGeometry::Point<2>;
{
KDOP_t x;
BOOST_TEST(!intersects(Point{1, 1}, x));
}
{
KDOP_t x; // rombus
expand(x, Point{0.5f, 0});
expand(x, Point{0.5f, 1});
expand(x, Point{0, 0.5f});
expand(x, Point{1, 0.5f});
// unit square corners
BOOST_TEST(intersects(Point{0, 0}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{1, 0}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{0, 1}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{1, 1}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
// rombus corners
BOOST_TEST(intersects(Point{0.5f, 0}, x));
BOOST_TEST(intersects(Point{0.5f, 1}, x));
BOOST_TEST(intersects(Point{0, 0.5f}, x));
BOOST_TEST(intersects(Point{1, 0.5f}, x));
// unit square center
BOOST_TEST(intersects(Point{0.5f, 0.5f}, x));
// mid rombus diagonals
BOOST_TEST(intersects(Point{0.75f, 0.25f}, x));
BOOST_TEST(intersects(Point{0.25f, 0.25f}, x));
BOOST_TEST(intersects(Point{0.25f, 0.75f}, x));
BOOST_TEST(intersects(Point{0.75f, 0.75f}, x));
// slightly outside of the diagonals
BOOST_TEST(intersects(Point{0.8f, 0.2f}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{0.2f, 0.2f}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{0.2f, 0.8f}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
BOOST_TEST(intersects(Point{0.8f, 0.8f}, x) ==
(std::is_same_v<KDOP_t, KDOP<2, 4>>));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test for intersection with regular 2D box?

Copy link
Contributor Author

@aprokop aprokop May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess I could add it. I'm not sure if it adds much.

Nevermind. Not only it was a good idea, it also uncovered a bug.


using KDOP_3D_types =
std::tuple<KDOP<3, 6>, KDOP<3, 14>, KDOP<3, 18>, KDOP<3, 26>>;

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_kdop_3D, KDOP_t, KDOP_3D_types)
{
using ArborX::Point;

KDOP_t x;
BOOST_TEST(!intersects(x, x));
expand(x, Point{1, 0, 0});
Expand All @@ -38,8 +100,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_KDOP, KDOP_t, KDOP_types)
BOOST_TEST(!intersects(x, KDOP_t{}));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_box, KDOP_t, KDOP_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop_box_3D, KDOP_t, KDOP_3D_types)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself that the ordering kdop_box here is accurate even though at first sight it looked inconsistent with point_kdop below.

{
using ArborX::Box;
using ArborX::Point;

KDOP_t x;
BOOST_TEST(!intersects(x, Box{}));
BOOST_TEST(!intersects(x, Box{{0, 0, 0}, {1, 1, 1}}));
Expand All @@ -50,8 +115,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_box, KDOP_t, KDOP_types)
BOOST_TEST(intersects(x, Box{{0, 0, 0}, {1, 1, 1}}));
}

BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point, KDOP_t, KDOP_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_point_kdop, KDOP_t, KDOP_3D_types)
{
using ArborX::Point;
{
KDOP_t x;
BOOST_TEST(!intersects(Point{1, 1, 1}, x));
Expand Down
Loading