# Crate hilbert_2d

Expand description

Rust functions for mapping between 1D and 2D space using the Hilbert curve, and its approximations.

When working with images and matrices, use the `h2xy_discrete` and `xy2h_discrete` functions:

``````use hilbert_2d::{h2xy_discrete, xy2h_discrete, Variant};

let (x, y) = h2xy_discrete(7, 2, Variant::Hilbert); // (1, 2)
let h = xy2h_discrete(2, 1, 2, Variant::Hilbert); // 13``````

When performing real-valued calculations, use the continuous functions instead:

``````use hilbert_2d::{h2xy_continuous_f64, Variant};

// Approaches the bottom-left corner
let (x1, y1) = h2xy_continuous_f64(0.0, Variant::Hilbert);
// Approaches the bottom-right corner
let (x2, y2) = h2xy_continuous_f64(1.0, Variant::Hilbert); ``````

Some of the pattern variants of the Hilbert curve have also been implemented:

``````use hilbert_2d::{h2xy_continuous_f64, Variant};

// In the Liu L1 variant, both ends of the curve approach the center of the square
let (x1, y1) = h2xy_continuous_f64(0.0, Variant::Liu1); // (~0.5, ~0.5)
let (x2, y2) = h2xy_continuous_f64(1.0, Variant::Liu1); // (~0.5, ~0.5)``````

## Re-exports

`pub use crate::usize::h2xy_discrete;`
`pub use crate::usize::xy2h_discrete;`

## Modules

Discrete functions for the 8-bit unsigned integer type.
Discrete functions for the 16-bit unsigned integer type.
Discrete functions for the 32-bit unsigned integer type.
Discrete functions for the 64-bit unsigned integer type.
Discrete functions for the 128-bit unsigned integer type.
Discrete functions for the pointer-sized unsigned integer type.

## Enums

Indicates the pattern variant of the Hilbert curve to be constructed.

## Functions

Maps from a 1D value to an approximate 2D coordinate, using the closest approachable limit of the Hilbert curve. Recommended for real-valued calculations.
Maps from a 1D value to an approximate 2D coordinate, using the closest approachable limit of the Hilbert curve. Recommended for real-valued calculations.
Maps from a 2D coordinate to an approximate 1D value, using the closest approachable limit of the Hilbert curve. Recommended for real-valued calculations.
Maps from a 2D coordinate to an approximate 1D value, using the closest approachable limit of the Hilbert curve. Recommended for real-valued calculations.