fn generate_next_building<R: Rng>(rng: &mut R, grid: &SparseGrid<Value>) -> Option<BuildingShape> {
    let size_x = rng.gen_range(MIN_BUILDING_SIZE..MAX_BUILDING_SIZE);
    let size_y = rng.gen_range(MIN_BUILDING_SIZE..MAX_BUILDING_SIZE);
    let size = IVec2::new(size_x as i32, size_y as i32);

    grid.cells()
      .filter_map(|(pos, _)| {
        let building = BuildingShape {
          edge_min: pos,
          edge_max: pos + size - IVec2::ONE
        };

        // The number of adjacent building cells is used to 'score'
        // each position when picking a spot to place the next building
        get_neighbor_count_if_vacant(grid, &building)
          .map(|n| (n, building))
      })
      .max_by_key(|e| e.0)
      .map(|(_, building)| building)
  }
/// Finds the most optimal spot to place the next building if possible
Finds the most optimal spot to place the next building if possible
Finds the most optimal spot to place the next building if possible
fn generate_next_building<R: Rng>(rng: &mut R, grid: &SparseGrid<Value>) -> Option<BuildingShape> {
    let size_x = rng.gen_range(MIN_BUILDING_SIZE..MAX_BUILDING_SIZE);
    let size_y = rng.gen_range(MIN_BUILDING_SIZE..MAX_BUILDING_SIZE);
    let size = IVec2::new(size_x as i32, size_y as i32);
    grid.cells()
      .filter_map(|(pos, _)| {
        let building = BuildingShape {
          edge_min: pos,
          edge_max: pos + size - IVec2::ONE
        };
        // The number of adjacent building cells is used to 'score'
        // each position when picking a spot to place the next building
        get_neighbor_count_if_vacant(grid, &building)
          .map(|n| (n, building))
      })
      .max_by_key(|e| e.0)
      .map(|(_, building)| building)
  }
fn generate_next_building < R : Rng > ( rng : & mut R , grid : & SparseGrid < Value > ) -> Option < BuildingShape > { let size_x = rng . gen_range ( MIN_BUILDING_SIZE .. MAX_BUILDING_SIZE ) ; let size_y = rng . gen_range ( MIN_BUILDING_SIZE .. MAX_BUILDING_SIZE ) ; let size = IVec2 :: new ( size_x as i32 , size_y as i32 ) ; grid . cells ( ) . filter_map ( | ( pos , _ ) | { let building = BuildingShape { edge_min : pos , edge_max : pos + size - IVec2 :: ONE } ; // The number of adjacent building cells is used to 'score' // each position when picking a spot to place the next building get_neighbor_count_if_vacant ( grid , & building ) . map ( | n | ( n , building ) ) } ) . max_by_key ( | e | e . 0 ) . map ( | ( _ , building ) | building ) }
Finds the most optimal spot to place the next building if possible
Finds the most optimal spot to place the next building if possible
rng
&mut R
grid
&SparseGrid<Value>
rng
&mut R
grid
&SparseGrid<Value>