Function hilbert_2d::h2xy_continuous_f64
source · Expand description
Maps from a 1D value to an approximate 2D coordinate, using the closest approachable limit of the Hilbert curve. Recommended for real-valued calculations.
Given a value h
, this method calculates an approximation of it’s corresponding limit point (x, y)
, in the
Hilbert curve of the highest achievable order for the target platform.
The value of h
must be in the range 0.0 <= h < 1.0
. A value h >= 1.0
can be given, but functionally, it will
be clipped to the closest value to one possible. The coordinates returned will be in the range 0.0 <= x/y < 1.0
.
The pattern of the Hilbert curve to be constructed must be indicated by the variant
parameter. See Variant
for more details.
Internally, this method uses h2xy_discrete
for the calculation, coupled with a trick using the fractional parts
of binary/quaternary numbers. In short, the precision of the calculation, as well as the closest approximation
possible, both depend on the number of bits in a usize
for the target platform. See h2xy_discrete
for more
details.
Examples
Basic usage:
use hilbert_2d::{h2xy_continuous_f64, Variant};
// In the traditional pattern, the edges of the Hilbert curve are horizontally distant...
let (x_a, _) = h2xy_continuous_f64(0.0, Variant::Hilbert);
let (x_b, _) = h2xy_continuous_f64(1.0, Variant::Hilbert);
assert!(x_b - x_a > 0.999);
// ...but in the Moore pattern, the edges of the curve close up.
let (x_a, _) = h2xy_continuous_f64(0.0, Variant::Moore);
let (x_b, _) = h2xy_continuous_f64(1.0, Variant::Moore);
assert!(x_b - x_a < 0.001);