Function morton_encoding::morton_encode_array[][src]

pub fn morton_encode_array<Coordinate, Key, const N: usize>(
    input: [Coordinate; N]
) -> Key where
    Coordinate: ToPrimitive + PrimInt,
    Key: ValidKey<Coordinate>, 

Encodes an array of N Coordinates into a Key.

Receives an array of N values of Coordinate type ([Coordinate; N]), and encodes them all in a Key value. In the event that one Key is strictly larger than N Coordinates, all significant bits are gathered at the end, and extraneous bits at the beginning are cleared.

Panics

This function will panic if the Key value provided does not have enough length for all the values in the iterator.

In the future, we would like for it to fail to compile for invalid parametres, but that’s still quite far away.

let _: u32 = morton_encode_array([15u16, 256, 10000]); // Compiles, but panics.

Examples

let input = [255u8, 0];
let result: u16 = morton_encode_array(input);
assert_eq!(result, 0xAAAA);

In the event that one Key is strictly larger than all Coors put together, all significant bits are gathered at the end, and extraneous bits at the beginning are cleared. The following example illustrates the difference:

let input = [255u8; 3];
let result: u32 = morton_encode_array(input);
assert_eq!(result, 0b_0000_0000_111_111_111_111_111_111_111_111u32);
let input = [0u8, 255, 255, 255];
let result: u32 = morton_encode_array(input);
assert_eq!(result, 0b_0111_0111_0111_0111_0111_0111_0111_0111u32);