/// Performs flood fill starting at `start` and travelling up
/// to `max_dist` blocks.
///
/// For each block iterated over, the provided closure will be invoked.
/// No block will be iterated more than once.
Performs flood fill starting at `start` and travelling up
to `max_dist` blocks.

For each block iterated over, the provided closure will be invoked.
No block will be iterated more than once.
Performs flood fill starting at ` start ` and travelling up to ` max_dist ` blocks . For each block iterated over the provided closure will be invoked . No block will be iterated more than once .
fn flood_fill<F>(context: &mut Context, start: BlockPosition, max_dist: u8, mut func: F)
where
    F: FnMut(&mut Context, BlockPosition),
{
    // Don't iterate over same block more than once
    let mut touched = HashSet::with_capacity(64);
    touched.insert(start);
    // We use a queue-based algorithm rather than a recursive
    // one.
    let mut queue = VecDeque::with_capacity(64);
    queue.push_back(start);
    let mut finished = false;
    while let Some(pos) = queue.pop_front() {
        if finished {
            break;
        }
        let blocks = adjacent_blocks(pos);
        blocks.into_iter().for_each(|pos| {
            if pos.manhattan_distance(start) > max_dist as i32 {
                // Finished
                finished = true;
                return;
            }
            // Skip if we already went over this block
            if !touched.insert(pos) {
                return;
            }
            let block = context.block_at(pos);
            if block.is_opaque() {
                return; // Stop iterating
            }
            // Call closure
            func(context, pos);
            // Add block to queue
            queue.push_back(pos);
        });
    }
}
fn flood_fill < F > ( context : & mut Context , start : BlockPosition , max_dist : u8 , mut func : F ) where F : FnMut ( & mut Context , BlockPosition ) , { // Don't iterate over same block more than once let mut touched = HashSet :: with_capacity ( 64 ) ; touched . insert ( start ) ; // We use a queue-based algorithm rather than a recursive // one. let mut queue = VecDeque :: with_capacity ( 64 ) ; queue . push_back ( start ) ; let mut finished = false ; while let Some ( pos ) = queue . pop_front ( ) { if finished { break ; } let blocks = adjacent_blocks ( pos ) ; blocks . into_iter ( ) . for_each ( | pos | { if pos . manhattan_distance ( start ) > max_dist as i32 { // Finished finished = true ; return ; } // Skip if we already went over this block if ! touched . insert ( pos ) { return ; } let block = context . block_at ( pos ) ; if block . is_opaque ( ) { return ; // Stop iterating } // Call closure func ( context , pos ) ; // Add block to queue queue . push_back ( pos ) ; } ) ; } }
Performs flood fill starting at `start` and travelling up
to `max_dist` blocks.
Performs flood fill starting at ` start ` and travelling up to ` max_dist ` blocks .
context
&mut Context
start
BlockPosition
max_dist
u8
func
F