use crate::math::Vector;
#[inline]
fn split_by_3_u64(a: u32) -> u64 {
let mut x = a as u64 & 0x1fffff; x = (x | x << 32) & 0x1f00000000ffff;
x = (x | x << 16) & 0x1f0000ff0000ff;
x = (x | x << 8) & 0x100f00f00f00f00f;
x = (x | x << 4) & 0x10c30c30c30c30c3;
x = (x | x << 2) & 0x1249249249249249;
x
}
#[inline]
fn morton_encode_u64(x: u32, y: u32, z: u32) -> u64 {
split_by_3_u64(x) | split_by_3_u64(y) << 1 | split_by_3_u64(z) << 2
}
#[inline]
pub fn morton_encode_u64_unorm(p: Vector) -> u64 {
#[cfg(feature = "dim2")]
#[cfg_attr(feature = "f64", expect(clippy::unnecessary_cast))]
let p = glamx::DVec2::new(p.x as f64, p.y as f64) * (1 << 21) as f64;
#[cfg(feature = "dim3")]
#[cfg_attr(feature = "f64", expect(clippy::unnecessary_cast))]
let p = glamx::DVec3::new(p.x as f64, p.y as f64, p.z as f64) * (1 << 21) as f64;
#[cfg(feature = "dim2")]
return morton_encode_u64(p.x as u32, p.y as u32, 0);
#[cfg(feature = "dim3")]
return morton_encode_u64(p.x as u32, p.y as u32, p.z as u32);
}