Crates.io | hilbert_2d |
lib.rs | hilbert_2d |
version | 1.1.0 |
source | src |
created_at | 2020-09-01 18:03:33.202133 |
updated_at | 2023-01-06 12:20:08.871714 |
description | Functions for mapping between 1D and 2D space using the Hilbert curve, and its approximations. |
homepage | |
repository | https://github.com/hbertoduarte/hilbert_2d/ |
max_upload_size | |
id | 283489 |
size | 167,163 |
Rust functions for mapping between 1D and 2D space using the Hilbert curve, and its approximations.
Add this to your Cargo.toml
:
[dependencies]
hilbert_2d = "1.1.0"
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)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.