Skip to content

Commit

Permalink
Change Point CTAD
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Sep 16, 2024
1 parent f553a85 commit d8f2d94
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
14 changes: 9 additions & 5 deletions src/geometry/ArborX_Point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ struct Point
Coordinate _coords[DIM] = {};
};

template <typename... T>
Point(T...)
-> Point<sizeof...(T), std::conditional_t<
(... || std::is_same_v<std::decay_t<T>, double>),
double, float>>;
template <typename T, typename... Ts>
Point(T, Ts...) -> Point<
sizeof...(Ts) + 1,
std::conditional_t<
std::is_integral_v<std::decay_t<T>> &&
(... && std::is_integral_v<std::decay_t<Ts>>),
double,
std::enable_if_t<
(... && std::is_same_v<std::decay_t<T>, std::decay_t<Ts>>), T>>>;

} // namespace ArborX

Expand Down
14 changes: 9 additions & 5 deletions test/tstCompileOnlyGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,20 @@ void test_point_cv_compile_only()
void test_point_ctad()
{
using ArborX::Point;
static_assert(std::is_same_v<decltype(Point{1}), Point<1, float>>);

static_assert(std::is_same_v<decltype(Point{1}), Point<1, double>>);
static_assert(std::is_same_v<decltype(Point{1.}), Point<1, double>>);
static_assert(std::is_same_v<decltype(Point{1., 2}), Point<2, double>>);
static_assert(std::is_same_v<decltype(Point{1, 2.}), Point<2, double>>);
static_assert(std::is_same_v<decltype(Point{2, 2}), Point<2, float>>);
static_assert(std::is_same_v<decltype(Point{2., 3.f, 2.}), Point<3, double>>);
static_assert(std::is_same_v<decltype(Point{2, 2}), Point<2, double>>);
static_assert(
std::is_same_v<decltype(Point{1.0L, 0.3L, 0.5L}), Point<3, long double>>);
static_assert(
std::is_same_v<decltype(Point{2.f, 3.f, 2.f}), Point<3, float>>);
static_assert(
std::is_same_v<decltype(Point<2, float>{1, 4}), Point<2, float>>);
static_assert(
std::is_same_v<decltype(Point<3, int>{2, 3, 2}), Point<3, int>>);
static_assert(std::is_same_v<decltype(Point<3, double>{2.f, 3.f, 2.f}),
Point<3, double>>);
}

} // namespace ArborX::GeometryTraits
28 changes: 14 additions & 14 deletions test/tstRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ BOOST_AUTO_TEST_CASE(intersects_triangle)
using ArborX::Point;
using ArborX::Experimental::Ray;
using ArborX::ExperimentalHyperGeometry::Triangle;
constexpr Triangle unit_triangle{Point{0, 0, 0}, Point{1, 0, 0},
Point{0, 1, 0}};
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}};

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));
Expand Down Expand Up @@ -462,8 +462,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, 0, 0}, Point{2, 0, 1},
Point{0, 2, 1}};
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}};

// ray in the same plane as the triangle
BOOST_TEST(!intersects(Ray{{10, 0, 0}, {1, 1, 1}}, tilted_triangle));
Expand Down Expand Up @@ -506,10 +506,10 @@ BOOST_AUTO_TEST_CASE(ray_triangle_intersection,
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#endif

constexpr Triangle unit_triangle{Point{0, 0, 0}, Point{1, 0, 0},
Point{0, 1, 0}};
constexpr Triangle narrow_triangle{Point{0.5f, 0.5f, 0},
Point{0.24f, 0.74f, 0}, Point{0, 1.f, 0}};
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 narrow_triangle{
Point{0.5f, 0.5f, 0.f}, Point{0.24f, 0.74f, 0.f}, Point{0.f, 1.f, 0.f}};

auto const sqrtf_3 = std::sqrt(3.f);
auto const sqrtf_2 = std::sqrt(2.f);
Expand Down Expand Up @@ -563,10 +563,10 @@ BOOST_AUTO_TEST_CASE(ray_triangle_intersection,
// test would fail the "Plucker coordinates"-based algorithm, thus it is necessary to
// keep them here to show the watertightness of the current algorithm implemented.
constexpr Point O{1.f, 1.f, 1.f};
constexpr Point A{2.f, 2.f, 0};
constexpr Point B{2.f, -1.f, 0};
constexpr Point C{-1.f, -1.f, 0};
constexpr Point D{-1.f, 2.f, 0};
constexpr Point A{2.f, 2.f, 0.f};
constexpr Point B{2.f, -1.f, 0.f};
constexpr Point C{-1.f, -1.f, 0.f};
constexpr Point D{-1.f, 2.f, 0.f};

constexpr Triangle triangle_up{D, A, O};
constexpr Triangle triangle_right{O, A, B};
Expand Down Expand Up @@ -599,12 +599,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, 0}, Point{0, size_s, 0}, Point{0, 0, size_s}};
Triangle small_triangle{Point{-size_s, 0.f, 0.f}, Point{0.f, size_s, 0.f}, Point{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, 0}, Point{0, 10000, 0}, Point{0, 0, 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}};
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);

Expand Down

0 comments on commit d8f2d94

Please sign in to comment.