From ac7b54866395544aa52bf4d15b47b1b97c44d3d4 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Mon, 30 Sep 2024 17:06:35 -0400 Subject: [PATCH] Add Segment tests --- test/tstCompileOnlyGeometry.cpp | 13 ++++++++++++ test/tstDetailsAlgorithms.cpp | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/tstCompileOnlyGeometry.cpp b/test/tstCompileOnlyGeometry.cpp index eaab0d06f..20b89b2d5 100644 --- a/test/tstCompileOnlyGeometry.cpp +++ b/test/tstCompileOnlyGeometry.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace ArborX::GeometryTraits @@ -248,6 +249,18 @@ void test_point_ctad() Point<3, double>>); } +void test_segment_ctad() +{ + using ArborX::Point; + using ArborX::Experimental::Segment; + + static_assert(std::is_same_v>); + static_assert(std::is_same_v{0.f, 2.f}, + Point<2, double>{2.f, 3.f}}), + Segment<2, double>>); +} + void test_box_ctad() { using ArborX::Box; diff --git a/test/tstDetailsAlgorithms.cpp b/test/tstDetailsAlgorithms.cpp index f525471ee..003b34925 100644 --- a/test/tstDetailsAlgorithms.cpp +++ b/test/tstDetailsAlgorithms.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,27 @@ BOOST_AUTO_TEST_CASE(distance_point_sphere) BOOST_TEST(distance(Point{{1., 1., 1.}}, sphere) == std::sqrt(3.f) - 1.f); } +BOOST_AUTO_TEST_CASE(distance_point_segment) +{ + using ArborX::Details::distance; + + using ArborX::Point; + using ArborX::Experimental::Segment; + + constexpr Segment segment0{{0.f, 0.f}, {0.f, 0.f}}; + BOOST_TEST(distance(Point{0.f, 0.f}, segment0) == 0.f); + BOOST_TEST(distance(Point{1.f, 0.f}, segment0) == 1.f); + BOOST_TEST(distance(Point{-1.f, 0.f}, segment0) == 1.f); + + constexpr Segment segment1{{0.f, 0.f}, {1.f, 1.f}}; + BOOST_TEST(distance(Point{0.f, 0.f}, segment1) == 0.f); + BOOST_TEST(distance(Point{1.f, 1.f}, segment1) == 0.f); + BOOST_TEST(distance(Point{0.5f, 0.5f}, segment1) == 0.f); + BOOST_TEST(distance(Point{1.0f, 0.f}, segment1) == std::sqrt(0.5f)); + BOOST_TEST(distance(Point{0.f, -1.f}, segment1) == 1.f); + BOOST_TEST(distance(Point{1.5f, 1.f}, segment1) == 0.5f); +} + BOOST_AUTO_TEST_CASE(distance_point_triangle) { using ArborX::Details::distance; @@ -346,6 +368,14 @@ BOOST_AUTO_TEST_CASE(expand) BOOST_TEST(equals(box, Box{{-5, -2, 2}, {1, 4, 7}})); expand(box, Tetrahedron{{-3, -5, 2}, {2, 6, -1}, {3, 2, 3}, {5, 8, -3}}); BOOST_TEST(equals(box, Box{{-5, -5, -3}, {5, 8, 7}})); + + // expand box with segments + using ArborX::Experimental::Segment; + box = Box{}; + expand(box, Segment{{0.f, 0.f, 0.f}, {1.f, 1.f, 1.f}}); + BOOST_TEST(equals(box, Box{{0, 0, 0}, {1, 1, 1}})); + expand(box, Segment{{-1.f, 3.0f, 0.0f}, {2.f, 1.f, 0.f}}); + BOOST_TEST(equals(box, Box{{-1, 0, 0}, {2, 3, 1}})); } BOOST_AUTO_TEST_CASE(convert) @@ -362,7 +392,9 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_AUTO_TEST_CASE(centroid) { + using ArborX::Details::equals; using ArborX::Details::returnCentroid; + Box box{{{-10.0, 0.0, 10.0}}, {{0.0, 10.0, 20.0}}}; auto center = returnCentroid(box); BOOST_TEST(center[0] == -5.0); @@ -385,6 +417,11 @@ BOOST_AUTO_TEST_CASE(centroid) BOOST_TEST(tet_center[0] == -1); BOOST_TEST(tet_center[1] == 3); BOOST_TEST(tet_center[2] == 2); + + using ArborX::Experimental::Segment; + Segment segment{{-1.f, -1.f}, {3.f, 3.f}}; + auto seg_center = returnCentroid(segment); + BOOST_TEST(equals(seg_center, ArborX::Point{1.f, 1.f})); } BOOST_AUTO_TEST_CASE(is_valid)