From 9e0ec02fcbb3b82a2a73d2713c41af5a6c4523f9 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 31 Aug 2026 19:43:16 -0700 Subject: remove ms, use noise + lerp --- src/proc_gen/herringbone.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/proc_gen/herringbone.rs') 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 { +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 { - ((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 { -- cgit v1.3.1