pub fn xy2h_continuous_f64(x: f64, y: f64, variant: Variant) -> f64
Expand description

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

Given x and y, this method calculates an approximation of it’s corresponding limit h, in the Hilbert curve of the highest achievable order for the target platform.

The value of x and y must be in the range 0.0 <= x/y < 1.0. A value x/y >= 1.0 can be given, but functionally, it will be clipped to the closest value to one possible. The value returned will be in the range 0.0 <= h <= 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 xy2h_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 xy2h_discrete for more details.

Examples

Basic usage:

use hilbert_2d::{xy2h_continuous_f64, Variant};

// In the third pattern presented by Liu, the curve begins at the lower left corner...
let h = xy2h_continuous_f64(0.0, 0.0, Variant::Liu3);
assert!(h < 0.001);

// ...but ends near the center of the square.
let h = xy2h_continuous_f64(0.5001, 0.4999, Variant::Liu3);
assert!(h > 0.999);