[][src]Function moore_hilbert::index_to_coordinates

pub fn index_to_coordinates(
    bits_per_dimension: BitsPerDimensionType,
    index: HilbertIndex,
    coords: &mut [HilbertCoordinate]
)

Convert an index into a Hilbert curve to a set of coordinates

Arguments

  • bits_per_dimension - Number of bits per dimension
  • index - The index, contains the number of dimensions * nBits bits (so nDims * nBits must be <= BITS_PER_BYTE * sizeof(HilbertIndex)).
  • coords - The slice where the coordinates will be written

Assumptions

number of dimesions * bits_per_dimension <= (sizeof HilbertIndex) * (bits_per_byte)

Example

let bits_per_dimension = 8;

// Start by getting an index along the Hilbert curve for this point
let start_vec = vec![1,2,3];
let r = moore_hilbert::coordinates_to_index(bits_per_dimension, &start_vec).unwrap();
assert_eq!(r, 36);

// A place to put the coordinates from the Hilbert curve index
let mut extracted_coords = [0,0,0];
moore_hilbert::index_to_coordinates(bits_per_dimension, r, &mut extracted_coords);

/// The coordinates should match.
assert_eq!(start_vec, extracted_coords);

// increment the index and make sure the coords don't match
moore_hilbert::index_to_coordinates(bits_per_dimension, r+1, &mut extracted_coords);
assert_ne!(start_vec, extracted_coords);