Function bitwise::word::morton::encode_3d [] [src]

pub fn encode_3d<T: Word>(x: T, y: T, z: T) -> T

Encode coordinates x, y, and z into an interleaved Morton index for a z-Curve.

Using _.i to denote the i-th bit in a word, given the x, y, and z coordinates with the following bit patterns:

x: |x.M|...|x.1|x.0| y: |y.M|...|y.1|y.0| z: |z.M|...|z.1|z.0|

where M == T::bit_size(),

this function encodes the bits of x, y, and z into a value v using the Morton z-Curve encoding:

v = |z.N|y.N|x.N|...|z.1|y.1|x.1|z.0|y.0|x.0|

where N == T::bit_size() / 3.

Note: the encoded Morton index is always invertible to the coordinates using the encode_3d function.

Example

use bitwise::word::morton;

let x = 0b0000_1010u8;
let y = 0b0000_0011u8;
let z = 0b0000_1110u8;
let r = 0b00_111_010u8;
let r32 = 0b101_100_111_010u32;
assert_eq!(morton::encode_3d(x, y, z), r);
assert_eq!(morton::encode_3d(x as u32, y as u32, z as u32), r32);