use xxhash_rust::xxh3::xxh3_64_with_seed;
use crate::coord::WorldPos;
#[inline]
pub fn world_seed(pos: WorldPos, salt: u32) -> u64 {
let mut bytes = [0u8; 16];
bytes[0..8].copy_from_slice(&pos.x.to_bits().to_le_bytes());
bytes[8..16].copy_from_slice(&pos.y.to_bits().to_le_bytes());
xxh3_64_with_seed(&bytes, salt as u64)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn same_position_same_seed() {
let a = world_seed(WorldPos::new(0.123, 0.456), 1);
let b = world_seed(WorldPos::new(0.123, 0.456), 1);
assert_eq!(a, b);
}
#[test]
fn different_salt_different_seed() {
let pos = WorldPos::new(0.5, 0.5);
assert_ne!(world_seed(pos, 1), world_seed(pos, 2));
}
}