Function bitwise::word::morton::encode_2d
[−]
[src]
pub fn encode_2d<T: Word>(x: T, y: T) -> T
Encode coordinates x
and y
into an interleaved Morton index for a
z-Curve.
Using _.i
to denote the i
-th bit in a word, given the x
and y
coordinates with the following bit patterns:
x: |x.M|...|x.1|x.0|
y: |y.M|...|y.1|y.0|
where M == T::bit_size()
,
this function encodes the bits of x
and y
into a value v
using the
Morton z-Curve encoding:
v = |y.N|x.N|...|y.1|x.1|y.0|x.0|
where N == T::bit_size() / 2
.
Example
use bitwise::word::morton; let x = 0b0000_1010u8; let y = 0b0000_0011u8; let r = 0b01_00_11_10u8; assert_eq!(morton::encode_2d(x, y), r); assert_eq!(morton::encode_2d(x as u32, y as u32), r as u32); assert_eq!(morton::encode_2d(x as u64, y as u64), r as u64);