From 6d5b9feeb538dd4912fefa15fef5637b7c493e73 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Thu, 26 Sep 2024 10:32:39 -0400 Subject: [PATCH] Add CTAD for Triangle --- src/geometry/ArborX_Triangle.hpp | 8 ++++++++ test/tstCompileOnlyGeometry.cpp | 17 +++++++++++++++++ test/tstDetailsAlgorithms.cpp | 12 ++++++------ test/tstRay.cpp | 18 +++++++++--------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/geometry/ArborX_Triangle.hpp b/src/geometry/ArborX_Triangle.hpp index 26cf11972..2c43077f8 100644 --- a/src/geometry/ArborX_Triangle.hpp +++ b/src/geometry/ArborX_Triangle.hpp @@ -34,6 +34,14 @@ KOKKOS_FUNCTION Triangle(Point, Point, Point) -> Triangle; +template +#if KOKKOS_VERSION >= 40400 +KOKKOS_DEDUCTION_GUIDE +#else +KOKKOS_FUNCTION +#endif +Triangle(T const (&)[N], T const (&)[N], T const (&)[N]) -> Triangle; + } // namespace ArborX template diff --git a/test/tstCompileOnlyGeometry.cpp b/test/tstCompileOnlyGeometry.cpp index eaab0d06f..a44037644 100644 --- a/test/tstCompileOnlyGeometry.cpp +++ b/test/tstCompileOnlyGeometry.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace ArborX::GeometryTraits { @@ -272,4 +273,20 @@ void test_sphere_ctad() Sphere<3, double>>); } +void test_triangle_ctad() +{ + using ArborX::Point; + using ArborX::Triangle; + + static_assert(std::is_same_v>); + static_assert( + std::is_same_v>); + static_assert( + std::is_same_v>); +} + } // namespace ArborX::GeometryTraits diff --git a/test/tstDetailsAlgorithms.cpp b/test/tstDetailsAlgorithms.cpp index f525471ee..a70510778 100644 --- a/test/tstDetailsAlgorithms.cpp +++ b/test/tstDetailsAlgorithms.cpp @@ -81,8 +81,8 @@ BOOST_AUTO_TEST_CASE(distance_point_triangle) | | */ using Point2 = ArborX::Point<2>; - constexpr ArborX::Triangle<2> triangle2{Point2{-1, 0}, Point2{1, 0}, - Point2{0, 1}}; + constexpr ArborX::Triangle triangle2{Point2{-1, 0}, Point2{1, 0}, + Point2{0, 1}}; // vertices BOOST_TEST(distance(Point2{-1, 0}, triangle2) == 0); @@ -108,8 +108,8 @@ BOOST_AUTO_TEST_CASE(distance_point_triangle) BOOST_TEST(distance(Point2{1, 1}, triangle2) == std::sqrt(2.f) / 2); using Point3 = ArborX::Point<3>; - constexpr ArborX::Triangle<3> triangle3{Point3{1, 0, 0}, Point3{0, 1, 0}, - Point3{0, 0, 0}}; + constexpr ArborX::Triangle triangle3{Point3{1, 0, 0}, Point3{0, 1, 0}, + Point3{0, 0, 0}}; // same plane BOOST_TEST(distance(Point3{2, 0, 0}, triangle3) == 1); @@ -125,8 +125,8 @@ BOOST_AUTO_TEST_CASE(distance_point_triangle) BOOST_TEST(distance(Point3{0, -1, -1}, triangle3) == std::sqrt(2.f)); BOOST_TEST(distance(Point3{2, -1, -1}, triangle3) == std::sqrt(3.f)); - constexpr ArborX::Triangle<3> triangle3_2{Point3{0, 0, 0}, Point3{0, 1, 0}, - Point3{0, 0, 1}}; + constexpr ArborX::Triangle triangle3_2{Point3{0, 0, 0}, Point3{0, 1, 0}, + Point3{0, 0, 1}}; BOOST_TEST(distance(Point3{-1, 0, 1}, triangle3_2) == 1); BOOST_TEST(distance(Point3{0, -1, -1}, triangle3_2) == std::sqrt(2.f)); BOOST_TEST(distance(Point3{1, -1, -1}, triangle3_2) == std::sqrt(3.f)); diff --git a/test/tstRay.cpp b/test/tstRay.cpp index a268a9699..130df52e1 100644 --- a/test/tstRay.cpp +++ b/test/tstRay.cpp @@ -410,8 +410,8 @@ BOOST_AUTO_TEST_CASE(intersects_triangle) using ArborX::Point; using ArborX::Triangle; using ArborX::Experimental::Ray; - constexpr Triangle unit_triangle{Point{0.f, 0.f, 0.f}, Point{1.f, 0.f, 0.f}, - Point{0.f, 1.f, 0.f}}; + constexpr Triangle unit_triangle{ + {0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}}; BOOST_TEST(intersects(Ray{{.1, .2, .3}, {0, 0, -1}}, unit_triangle)); BOOST_TEST(intersects(Ray{{1.1, 1.2, 1}, {-1, -1, -1}}, unit_triangle)); @@ -457,8 +457,8 @@ BOOST_AUTO_TEST_CASE(intersects_triangle) // ray in a plane parallel to the triangle BOOST_TEST(!intersects(Ray{{-0.1, 0, 1}, {1, 0, 0}}, unit_triangle)); - constexpr Triangle tilted_triangle{Point{0.f, 0.f, 0.f}, Point{2.f, 0.f, 1.f}, - Point{0.f, 2.f, 1.f}}; + constexpr Triangle tilted_triangle{ + {0.f, 0.f, 0.f}, {2.f, 0.f, 1.f}, {0.f, 2.f, 1.f}}; // ray in the same plane as the triangle BOOST_TEST(!intersects(Ray{{10, 0, 0}, {1, 1, 1}}, tilted_triangle)); @@ -501,10 +501,10 @@ BOOST_AUTO_TEST_CASE(ray_triangle_intersection, constexpr auto inf = KokkosExt::ArithmeticTraits::infinity::value; #endif - constexpr Triangle unit_triangle{Point{0.f, 0.f, 0.f}, Point{1.f, 0.f, 0.f}, - Point{0.f, 1.f, 0.f}}; + constexpr Triangle unit_triangle{ + {0.f, 0.f, 0.f}, {1.f, 0.f, 0.f}, {0.f, 1.f, 0.f}}; constexpr Triangle narrow_triangle{ - Point{0.5f, 0.5f, 0.f}, Point{0.24f, 0.74f, 0.f}, Point{0.f, 1.f, 0.f}}; + {0.5f, 0.5f, 0.f}, {0.24f, 0.74f, 0.f}, {0.f, 1.f, 0.f}}; auto const sqrtf_3 = std::sqrt(3.f); auto const sqrtf_2 = std::sqrt(2.f); @@ -594,12 +594,12 @@ BOOST_AUTO_TEST_CASE(ray_triangle_intersection, // between the origin of the ray and the vertices. // These tests will fail if there is no normalization. float const size_s = 0.0001; - Triangle small_triangle{Point{-size_s, 0.f, 0.f}, Point{0.f, size_s, 0.f}, Point{0.f, 0.f, size_s}}; + Triangle small_triangle{{-size_s, 0.f, 0.f}, {0.f, size_s, 0.f}, {0.f, 0.f, size_s}}; ARBORX_TEST_RAY_TRIANGLE_INTERSECTION((Ray{{0.0, 0.0, 0.0}, {-size_s, size_s, size_s}}), small_triangle, size_s/sqrtf_3, size_s/sqrtf_3); ARBORX_TEST_RAY_TRIANGLE_INTERSECTION((Ray{{-2.f*size_s, -size_s, 0.0}, {size_s, size_s, 0}}), small_triangle, sqrtf_2*size_s, 2.f*sqrtf_2*size_s); float const size_l = 10000; - Triangle large_triangle{Point{-size_l, 0.f, 0.f}, Point{0.f, 10000.f, 0.f}, Point{0.f, 0.f, 10000.f}}; + Triangle large_triangle{{-size_l, 0.f, 0.f}, {0.f, 10000.f, 0.f}, {0.f, 0.f, 10000.f}}; ARBORX_TEST_RAY_TRIANGLE_INTERSECTION((Ray{{0.0, 0.0, 0.0}, {-size_l, size_l, size_l}}), large_triangle, size_l/sqrtf_3, size_l/sqrtf_3); ARBORX_TEST_RAY_TRIANGLE_INTERSECTION((Ray{{-2.f*size_l, -size_l, 0.0}, {size_l, size_l, 0}}), large_triangle, sqrtf_2*size_l, 2.f*sqrtf_2*size_l);