use fxhash::hash32; use glam::IVec2; use crate::proc_gen::tileset_loader::TileOrientation; const SEED: u32 = 100000; pub fn split_position(pixel: IVec2, short: i32) -> (IVec2, IVec2, TileOrientation) { let grid = pixel.div_euclid(IVec2::splat(short)); let local = pixel.rem_euclid(IVec2::splat(short)); match (grid.x - grid.y).rem_euclid(4) { 0 => (grid, local, TileOrientation::Horizontal), 1 => ( grid - IVec2::X, local + IVec2::new(short, 0), TileOrientation::Horizontal, ), 3 => (grid, local, TileOrientation::Vertical), 2 => ( grid - IVec2::Y, local + IVec2::new(0, short), TileOrientation::Vertical, ), _ => unreachable!(), } } // better "%" for hashes since it prefers the high bits #[inline] fn reduce(h: u32, n: usize) -> usize { (((h as u128) * (n as u128)) >> 32) as usize } pub fn variant_index(grid: IVec2, variants: usize) -> usize { reduce(hash32(&(grid, SEED)), variants) }