quadgrid 0.1
simple cartesian quad grid with particles for c++/octave
Loading...
Searching...
No Matches
mmorton.h File Reference
#include <cstdint>
#include <numeric>

Go to the source code of this file.

Typedefs

using coord_t = uint_least32_t
using morton_code_t = uint_fast64_t

Functions

morton_code_t coord_2_morton (coord_t _x, coord_t _y)
void morton_2_coord (morton_code_t code, coord_t &_x, coord_t &_y)

Variables

constexpr coord_t max_level = 31
constexpr coord_t max_coord = std::numeric_limits<coord_t>::max ()

Typedef Documentation

◆ coord_t

using coord_t = uint_least32_t

Definition at line 7 of file mmorton.h.

◆ morton_code_t

using morton_code_t = uint_fast64_t

Definition at line 8 of file mmorton.h.

Function Documentation

◆ coord_2_morton()

morton_code_t coord_2_morton ( coord_t _x,
coord_t _y )

Definition at line 8 of file mmorton.cc.

8 {
9
10 morton_code_t x = static_cast<morton_code_t> (_x);
11 morton_code_t y = static_cast<morton_code_t> (_y);
12
13 x = (x | (x << S[3])) & B[3];
14 x = (x | (x << S[2])) & B[2];
15 x = (x | (x << S[1])) & B[1];
16 x = (x | (x << S[0])) & B[0];
17
18 y = (y | (y << S[3])) & B[3];
19 y = (y | (y << S[2])) & B[2];
20 y = (y | (y << S[1])) & B[1];
21 y = (y | (y << S[0])) & B[0];
22
23 return x | (y << 1);
24}
static constexpr morton_code_t B[]
Definition mmorton.cc:3
static constexpr morton_code_t S[]
Definition mmorton.cc:5
uint_fast64_t morton_code_t
Definition mmorton.h:8

◆ morton_2_coord()

void morton_2_coord ( morton_code_t code,
coord_t & _x,
coord_t & _y )

Definition at line 75 of file mmorton.cc.

75 {
76
77 morton_code_t x = code & B[0];
78 morton_code_t y = (code >> 1) & B[0];
79
80 x = x | ((x & M[0]) >> S[0]);
81 x = x | ((x & M[1]) >> S[1]);
82 x = x | ((x & M[2]) >> S[2]);
83 x = x | ((x & M[3]) >> S[3]);
84 x = x | ((x & M[4]) >> S[4]);
85 _x = x;
86
87 y = y | ((y & M[0]) >> S[0]);
88 y = y | ((y & M[1]) >> S[1]);
89 y = y | ((y & M[2]) >> S[2]);
90 y = y | ((y & M[3]) >> S[3]);
91 y = y | ((y & M[4]) >> S[4]);
92 _y = y;
93}
static constexpr morton_code_t M[]
Definition mmorton.cc:4

Variable Documentation

◆ max_coord

coord_t max_coord = std::numeric_limits<coord_t>::max ()
constexpr

Definition at line 11 of file mmorton.h.

◆ max_level

coord_t max_level = 31
constexpr

Definition at line 10 of file mmorton.h.