8template<
int I,
int End,
class F>
10constexpr void static_for(F&& f) {
11 if constexpr (I < End) {
12 f(std::integral_constant<int, I>{});
13 static_for<I+1, End>(std::forward<F>(f));
20void sort2(T& a, T& b) {
if (a > b) { T t=a; a=b; b=t; } }
25void sort3(T& a, T& b, T& c) { sort2(a,b); sort2(b,c); sort2(a,b); }
28template<
unsigned Dim,
typename T>
33 for (
unsigned a=0; a<Dim; ++a) out[a] = A[a] + (B[a]-A[a]) * t;
38template<
unsigned Dim,
typename T>
41template<
unsigned Dim,
typename T>
50 for (
unsigned a=0; a<Dim; ++a) cuts.t[a] = (T)2;
52 const T eps1 = (T)1e-12, one = (T)1;
54 auto axis_cut = [&](
auto Ax) {
55 constexpr int a =
decltype(Ax)::value;
56 const T dist = B[a] - A[a];
57 const T eps = eps1 * h[a];
58 if (Kokkos::fabs(dist) <= eps)
return;
60 const T nA = (A[a] - origin[a]) / h[a];
62 const T k = (dist > 0) ? Kokkos::ceil(nA - eps1) : Kokkos::floor(nA + eps1);
63 const T pa = origin[a] + k * h[a];
65 const T t = (pa - A[a]) / dist;
66 if (t > eps1 && t < one - eps1) cuts.t[a] = t;
70 static_for<0,Dim>(axis_cut);
75template<
unsigned Dim,
typename T>
77void make_endpoints_fixed(
const CutTimes<Dim,T>& cuts,
78 Kokkos::Array<T,Dim+2>& Tcuts )
81 T t1 = (Dim>=2) ? cuts.t[1] : (T)2;
82 T t2 = (Dim==3) ? cuts.t[2] : (T)2;
84 if constexpr (Dim==2) {
91 auto clamp_or_one = [&](T v)->T {
return (v >= one) ? one : v; };
94 Tcuts[1] = clamp_or_one(t0);
95 if constexpr (Dim>=2) Tcuts[2] = clamp_or_one(t1);
96 if constexpr (Dim==3) Tcuts[3] = clamp_or_one(t2);
104template<
unsigned Dim,
typename T,
typename Rule>
105KOKKOS_INLINE_FUNCTION
106Kokkos::Array<Segment<Dim,T>, Dim+1>
107GridPathSegmenter<Dim,T,Rule>::split(
113 const auto cuts = compute_axis_cuts_default<Dim,T>(A,B,origin,h);
115 Kokkos::Array<T,Dim+2> Tcuts{};
116 make_endpoints_fixed<Dim,T>(cuts, Tcuts);
118 Kokkos::Array<Segment<Dim,T>, Dim+1> segs{};
119 for (
unsigned i = 0; i < Dim + 1; ++i) {
120 const T ta = Tcuts[i];
121 const T tb = Tcuts[i+1];
122 segs[i].p0 = lerp_point<Dim,T>(A,B,ta);
123 segs[i].p1 = lerp_point<Dim,T>(A,B,tb);
Definition GridPathSegmenter.hpp:39