Skip to content

Commit

Permalink
Add tests for 2D KDOP
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed May 15, 2024
1 parent fa77eb4 commit 582f9d4
Showing 1 changed file with 74 additions and 8 deletions.
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>>));
}
}

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)
{
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

0 comments on commit 582f9d4

Please sign in to comment.