fn cells_within_distance(&self, pos: &Coord, distance: usize) -> Vec<Coord> {
        let mut cells = Vec::with_capacity(
            // max possible number of cells within this distance of pos
            (distance + 1).pow(2) + distance.pow(2)
        );
        // BFS
        cells.push(pos.clone());
        let mut pre2_iter_start = 0;
        let mut pre_iter_start = 0;
        for _ in 1..=distance {
            let mut new_neighbors = Vec::with_capacity(
                // 4-1 neighbors/cell (one neighbor was stepped into in the previous step)
                // +1 for the root case, which won't have any visited neighbors
                3 * cells[pre_iter_start..].len() + 1
            );
            for pos in &cells[pre_iter_start..] {
                let neighbors = pos.neighbors().into_iter().filter(|coord| {
                    self.is_water(coord) && ! cells[pre2_iter_start..].contains(coord)
                });
                for neighbor in neighbors {
                    if ! new_neighbors.contains(&neighbor) {
                        new_neighbors.push(neighbor)
                    }
                }
            }
            pre2_iter_start = pre_iter_start;
            pre_iter_start = cells.len();
            cells.append(&mut new_neighbors);
        }

        cells
    }
// water cells_only, land cells are stepped around
water cells_only, land cells are stepped around
water cells_only land cells are stepped around
fn cells_within_distance(&self, pos: &Coord, distance: usize) -> Vec<Coord> {
        let mut cells = Vec::with_capacity(
            // max possible number of cells within this distance of pos
            (distance + 1).pow(2) + distance.pow(2)
        );
        // BFS
        cells.push(pos.clone());
        let mut pre2_iter_start = 0;
        let mut pre_iter_start = 0;
        for _ in 1..=distance {
            let mut new_neighbors = Vec::with_capacity(
                // 4-1 neighbors/cell (one neighbor was stepped into in the previous step)
                // +1 for the root case, which won't have any visited neighbors
                3 * cells[pre_iter_start..].len() + 1
            );
            for pos in &cells[pre_iter_start..] {
                let neighbors = pos.neighbors().into_iter().filter(|coord| {
                    self.is_water(coord) && ! cells[pre2_iter_start..].contains(coord)
                });
                for neighbor in neighbors {
                    if ! new_neighbors.contains(&neighbor) {
                        new_neighbors.push(neighbor)
                    }
                }
            }
            pre2_iter_start = pre_iter_start;
            pre_iter_start = cells.len();
            cells.append(&mut new_neighbors);
        }
        cells
    }
fn cells_within_distance ( & self , pos : & Coord , distance : usize ) -> Vec < Coord > { let mut cells = Vec :: with_capacity ( // max possible number of cells within this distance of pos ( distance + 1 ) . pow ( 2 ) + distance . pow ( 2 ) ) ; // BFS cells . push ( pos . clone ( ) ) ; let mut pre2_iter_start = 0 ; let mut pre_iter_start = 0 ; for _ in 1 ..= distance { let mut new_neighbors = Vec :: with_capacity ( // 4-1 neighbors/cell (one neighbor was stepped into in the previous step) // +1 for the root case, which won't have any visited neighbors 3 * cells [ pre_iter_start .. ] . len ( ) + 1 ) ; for pos in & cells [ pre_iter_start .. ] { let neighbors = pos . neighbors ( ) . into_iter ( ) . filter ( | coord | { self . is_water ( coord ) && ! cells [ pre2_iter_start .. ] . contains ( coord ) } ) ; for neighbor in neighbors { if ! new_neighbors . contains ( & neighbor ) { new_neighbors . push ( neighbor ) } } } pre2_iter_start = pre_iter_start ; pre_iter_start = cells . len ( ) ; cells . append ( & mut new_neighbors ) ; } cells }
water cells_only, land cells are stepped around
water cells_only land cells are stepped around
&self
pos
&Coord
distance
usize
&self
pos
&Coord
distance
usize