const DIRS: [(i32, i32); 8] = [
(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1), ];
#[inline(always)]
pub fn reverse_dir(dir: u8) -> u8 {
(dir + 4) % 8
}
pub fn find_next_pixel(
edges: &[u8],
width: u32,
height: u32,
cx: u32,
cy: u32,
start_dir: u8,
) -> Option<(u32, u32, u8)> {
let cx = cx as i32;
let cy = cy as i32;
let w = width as i32;
let h = height as i32;
for step in 0..8 {
let current_dir = (start_dir + step) % 8;
let nx = cx + DIRS[current_dir as usize].0;
let ny = cy + DIRS[current_dir as usize].1;
if nx >= 0 && nx < w && ny >= 0 && ny < h {
let idx = (ny * w + nx) as usize;
if edges[idx] != 0 {
return Some((nx as u32, ny as u32, current_dir));
}
}
}
None
}