//! Morton code (Z-order curve) encoding for spatial locality

/// Morton code encoding trait
pub trait MortonEncode {
    /// Encode 3D position to Morton code (uses u32 for coordinates)
    fn encode_morton(x: u32, y: u32, z: u32) -> u64 {
        morton_encoding::morton_encode([x, y, z]) as u64
    }

    /// Encode f32 position to Morton code (quantized to u32)
    fn encode_morton_f32(x: f32, y: f32, z: f32, scale: f32) -> u64 {
        Self::encode_morton((x * scale) as u32, (y * scale) as u32, (z * scale) as u32)
    }
}

impl MortonEncode for () {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_morton_ordering() {
        let code1 = <()>::encode_morton(0, 0, 0);
        let code2 = <()>::encode_morton(1, 1, 1);
        let code3 = <()>::encode_morton(100, 100, 100);

        assert!(code1 < code2);
        assert!(code2 < code3);
    }
}
