I want to navigate in a Z-order curve by moving up, down, left or right.
The Wikipedia page has this section :
This property can be used to offset a Z-value, for example in two dimensions the coordinates to the top (decreasing y), bottom (increasing y), left (decreasing x) and right (increasing x) from the current Z-value z are:
top = (((z & 0b10101010) − 1) & 0b10101010) | (z & 0b01010101)
bottom = (((z | 0b01010101) + 1) & 0b10101010) | (z & 0b01010101)
left = (((z & 0b01010101) − 1) & 0b01010101) | (z & 0b10101010)
right = (((z | 0b10101010) + 1) & 0b01010101) | (z & 0b10101010)
However this page describes the Z order as being :
0|1
---
2|3
My curve however has order :
2|3
---
0|1
and has 14 levels max (i.e. in base 4 the identifier of a location is maximum 14 digits long, so 28 bits).
How to adapt these formulas ? Simply calling "top" "bottom" and vice versa doesn't work.
EDIT : never mind, this is exactly what you should do, it was a typo on my end.
Simply call "top" "bottom" and vice versa.