29constexpr T
threeToOneD(T x, T y, T z,
const std::array<T, 3> &dims) {
30 static_assert(std::is_integral_v<T>,
"threeToOneD requires integral types");
31 return (z * dims[1] + y) * dims[0] + x;
42constexpr T
threeToOneD(
const std::array<T, 3> &index3d,
const std::array<T, 3> &dims) {
43 static_assert(std::is_integral_v<T>,
"threeToOneD requires integral types");
44 return (index3d[2] * dims[1] + index3d[1]) * dims[0] + index3d[0];
55constexpr std::array<T, 3>
oneToThreeD(T ind,
const std::array<T, 3> &dims) {
56 static_assert(std::is_integral_v<T>,
"oneToThreeD requires integral types");
57 std::array<T, 3> pos{};
58 pos[2] = ind / (dims[0] * dims[1]);
59 pos[1] = (ind - pos[2] * dims[0] * dims[1]) / dims[0];
60 pos[0] = ind - dims[0] * (pos[1] + dims[1] * pos[2]);
Namespace to handle the conversion between one dimensional and three dimensional indices.
Definition: namespaces.h:70
constexpr std::array< T, 3 > oneToThreeD(T ind, const std::array< T, 3 > &dims)
Convert a 1d index to a 3d index.
Definition: ThreeDimensionalMapping.h:55
constexpr T threeToOneD(T x, T y, T z, const std::array< T, 3 > &dims)
Convert a 3d index to a 1d index.
Definition: ThreeDimensionalMapping.h:29