diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-31 19:43:16 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-31 19:43:16 -0700 |
| commit | 9e0ec02fcbb3b82a2a73d2713c41af5a6c4523f9 (patch) | |
| tree | 6c1dc26b67b62997e286eb7db2e09d8ffbd98e6a /src/proc_gen/herringbone.rs | |
| parent | 8a4dabfc1196e6263dcc6ed64f4abbb5965a9c34 (diff) | |
remove ms, use noise + lerp
Diffstat (limited to 'src/proc_gen/herringbone.rs')
| -rw-r--r-- | src/proc_gen/herringbone.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/proc_gen/herringbone.rs b/src/proc_gen/herringbone.rs index e8569c8..0a67b0c 100644 --- a/src/proc_gen/herringbone.rs +++ b/src/proc_gen/herringbone.rs @@ -3,22 +3,27 @@ use glam::IVec2; use crate::proc_gen::tileset_loader::TileOrientation; -fn tile_starting_at(grid: IVec2) -> Option<TileOrientation> { +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) { - // 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, + 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!(), } } -pub fn tiles_overlapping(min: IVec2, max: IVec2) -> impl Iterator<Item = (IVec2, TileOrientation)> { - ((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 { |
