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

Go to the source code of this file.

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

static constexpr morton_code_t B [] = {0x5555555555555555, 0x3333333333333333, 0x0F0F0F0F0F0F0F0F, 0x00FF00FF00FF00FF, 0x0000FFFF0000FFFF}
static constexpr morton_code_t M [] = {0x4444444444444444, 0x3030303030303030, 0x0F000F000F000F00, 0x00FF000000FF0000, 0x0000FFFF00000000}
static constexpr morton_code_t S [] = {1, 2, 4, 8, 16}

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

◆ B

morton_code_t B[] = {0x5555555555555555, 0x3333333333333333, 0x0F0F0F0F0F0F0F0F, 0x00FF00FF00FF00FF, 0x0000FFFF0000FFFF}
staticconstexpr

Definition at line 3 of file mmorton.cc.

◆ M

morton_code_t M[] = {0x4444444444444444, 0x3030303030303030, 0x0F000F000F000F00, 0x00FF000000FF0000, 0x0000FFFF00000000}
staticconstexpr

Definition at line 4 of file mmorton.cc.

◆ S

morton_code_t S[] = {1, 2, 4, 8, 16}
staticconstexpr

Definition at line 5 of file mmorton.cc.