c - 2D Morton decode function 64bits -


the first function encodes [x, y] 64bit wide morton code x , y 32bit wide integers using interleave bits binary magic numbers.

what reverse function?

void xy2d_morton_64bits(uint64_t x, uint64_t y, uint64_t *d) {     x = (x | (x << 16)) & 0x0000ffff0000ffff;     x = (x | (x << 8)) & 0x00ff00ff00ff00ff;        x = (x | (x << 4)) & 0x0f0f0f0f0f0f0f0f;      x = (x | (x << 2)) & 0x3333333333333333;     x = (x | (x << 1)) & 0x5555555555555555;      y = (y | (y << 16)) & 0x0000ffff0000ffff;     y = (y | (y << 8)) & 0x00ff00ff00ff00ff;     y = (y | (y << 4)) & 0x0f0f0f0f0f0f0f0f;     y = (y | (y << 2)) & 0x3333333333333333;     y = (y | (y << 1)) & 0x5555555555555555;      *d = x | (y << 1); }  void d2xy_morton_64bits(uint64_t d, uint64_t *x, uint64_t *y) {     // ???? } 

void xy2d_morton(uint64_t x, uint64_t y, uint64_t *d) {     x = (x | (x << 16)) & 0x0000ffff0000ffff;     x = (x | (x << 8)) & 0x00ff00ff00ff00ff;     x = (x | (x << 4)) & 0x0f0f0f0f0f0f0f0f;     x = (x | (x << 2)) & 0x3333333333333333;     x = (x | (x << 1)) & 0x5555555555555555;      y = (y | (y << 16)) & 0x0000ffff0000ffff;     y = (y | (y << 8)) & 0x00ff00ff00ff00ff;     y = (y | (y << 4)) & 0x0f0f0f0f0f0f0f0f;     y = (y | (y << 2)) & 0x3333333333333333;     y = (y | (y << 1)) & 0x5555555555555555;      *d = x | (y << 1); }  // morton_1 - extract bits  uint64_t morton_1(uint64_t x) {     x = x & 0x5555555555555555;     x = (x | (x >> 1)) & 0x3333333333333333;     x = (x | (x >> 2)) & 0x0f0f0f0f0f0f0f0f;     x = (x | (x >> 4)) & 0x00ff00ff00ff00ff;     x = (x | (x >> 8)) & 0x0000ffff0000ffff;     x = (x | (x >> 16)) & 0xffffffffffffffff;     return x; }  void d2xy_morton(uint64_t d, uint64_t *x, uint64_t *y) {     *x = morton_1(d);     *y = morton_1(d >> 1); } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -