use fxhash::hash32; use glam::IVec2; use crate::proc_gen::tileset_loader::TileOrientation; fn tile_starting_at(grid: IVec2) -> Option { match (grid.x - grid.y).rem_euclid(4) { // 1 is the right half of the horizontal tile starting at 0, // 2 is the bottom half of the vertical tile starting at 3 0 => Some(TileOrientation::Horizontal), 3 => Some(TileOrientation::Vertical), _ => None, } } pub fn tiles_overlapping(min: IVec2, max: IVec2) -> impl Iterator { ((min.y - 1)..max.y) .flat_map(move |y| ((min.x - 1)..max.x).map(move |x| IVec2::new(x, y))) .filter_map(|grid| tile_starting_at(grid).map(|orientation| (grid, orientation))) } // 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), variants) }