[−][src]Function hilbert_2d::h2xy_discrete
pub const fn h2xy_discrete(
h: usize,
order: usize,
variant: Variant
) -> (usize, usize)
Maps from a 1D index to a 2D coordinate, using a discrete approximation of the Hilbert curve. Recommended for images and matrices.
Given h
, this method calculates the (x, y)
coordinates for that index, in the Hilbert curve approximation of
order
.
The value of h
must be in the range 0 <= h < 2^(2 * order)
. The coordinates returned will be in the range
0 <= x/y < 2^order
.
With b
being the number of bits in a usize
for the target platform, the highest approximation order achievable
by this method is b / 2
. Therefore, the parameter order
must be in the range 1 <= order <= b / 2
.
The pattern of the Hilbert curve to be constructed must be indicated by the variant
parameter. See Variant
for more details.
Examples
Basic usage:
use hilbert_2d::{h2xy_discrete, Variant}; // Hilbert curve of order 2: // 5 ―― 6 9 ― 10 // | | | | // 4 7 ―― 8 11 // | | // 3 ―― 2 13 ― 12 // | | // 0 ―― 1 14 ― 15 let (x, y) = h2xy_discrete(7, 2, Variant::Hilbert); assert_eq!(x, 1); assert_eq!(y, 2);