Skip to main content

position_to_morton

Function position_to_morton 

Source
pub fn position_to_morton(
    pos: [f64; 3],
    grid_spacing: f64,
) -> Result<u64, CacheLayoutError>
Expand description

Convert a floating-point position to a Morton code using the given grid_spacing.

Each coordinate is quantised to floor(coord / grid_spacing) and clamped to the 21-bit range [0, 2^21 - 1].

Returns Err if grid_spacing is not positive and finite.

ยงExamples

use oxiphysics_core::cache_layout::position_to_morton;
let code = position_to_morton([1.5, 2.5, 3.5], 1.0).expect("valid spacing");
assert_ne!(code, 0);