fn fix_dispersal_map(habitat: &Array2D<u32>, dispersal: &mut Array2D<f64>) {
    let size = habitat.num_rows() * habitat.num_columns();

    for y in 0..habitat.num_rows() {
        for x in 0..habitat.num_columns() {
            let row = y * habitat.num_columns() + x;

            if habitat[(y, x)] == 0 {
                let mut warn = false;

                // Fix dispersal from non-habitat
                for column in 0..size {
                    let d = &mut dispersal[(row, column)];

                    if *d > 0.0_f64 {
                        warn = true;

                        *d = 0.0_f64;
                    }
                }

                if warn {
                    // warn!(
                    //     "Corrected dispersal values to 0.0 at ({},{}) to fit
                    // \      habitat ...", x, y,
                    // );
                }
            } else {
                let mut total_dispersal = 0.0_f64;

                // Fix dispersal to non-habitat
                for column in 0..size {
                    let tx = column % habitat.num_columns();
                    let ty = column / habitat.num_columns();

                    let d = &mut dispersal[(row, column)];

                    if habitat[(ty, tx)] == 0 && *d > 0.0_f64 {
                        // warn!(
                        //     "Corrected dispersal value {} to 0.0 at ({},{})->({},{}) to fit \
                        //      habitat ...",
                        //     *d, x, y, tx, ty,
                        // );

                        *d = 0.0_f64;
                    }

                    total_dispersal += *d;
                }

                // Fix no dispersal from habitat with self-dispersal
                if total_dispersal <= 0.0_f64 {
                    dispersal[(row, row)] = 1.0_f64;
                }
            }
        }
    }
}
// Fix dispersal by removing dispersal to/from non-habitat
// Fix dispersal by adding self-dispersal when no dispersal exists from habitat
Fix dispersal by removing dispersal to/from non-habitat
Fix dispersal by adding self-dispersal when no dispersal exists from habitat
Fix dispersal by removing dispersal to / from non - habitat Fix dispersal by adding self - dispersal when no dispersal exists from habitat
fn fix_dispersal_map(habitat: &Array2D<u32>, dispersal: &mut Array2D<f64>) {
    let size = habitat.num_rows() * habitat.num_columns();
    for y in 0..habitat.num_rows() {
        for x in 0..habitat.num_columns() {
            let row = y * habitat.num_columns() + x;
            if habitat[(y, x)] == 0 {
                let mut warn = false;
                // Fix dispersal from non-habitat
                for column in 0..size {
                    let d = &mut dispersal[(row, column)];
                    if *d > 0.0_f64 {
                        warn = true;
                        *d = 0.0_f64;
                    }
                }
                if warn {
                    // warn!(
                    //     "Corrected dispersal values to 0.0 at ({},{}) to fit
                    // \      habitat ...", x, y,
                    // );
                }
            } else {
                let mut total_dispersal = 0.0_f64;
                // Fix dispersal to non-habitat
                for column in 0..size {
                    let tx = column % habitat.num_columns();
                    let ty = column / habitat.num_columns();
                    let d = &mut dispersal[(row, column)];
                    if habitat[(ty, tx)] == 0 && *d > 0.0_f64 {
                        // warn!(
                        //     "Corrected dispersal value {} to 0.0 at ({},{})->({},{}) to fit \
                        //      habitat ...",
                        //     *d, x, y, tx, ty,
                        // );
                        *d = 0.0_f64;
                    }
                    total_dispersal += *d;
                }
                // Fix no dispersal from habitat with self-dispersal
                if total_dispersal <= 0.0_f64 {
                    dispersal[(row, row)] = 1.0_f64;
                }
            }
        }
    }
}
fn fix_dispersal_map ( habitat : & Array2D < u32 > , dispersal : & mut Array2D < f64 > ) { let size = habitat . num_rows ( ) * habitat . num_columns ( ) ; for y in 0 .. habitat . num_rows ( ) { for x in 0 .. habitat . num_columns ( ) { let row = y * habitat . num_columns ( ) + x ; if habitat [ ( y , x ) ] == 0 { let mut warn = false ; // Fix dispersal from non-habitat for column in 0 .. size { let d = & mut dispersal [ ( row , column ) ] ; if * d > 0.0_f64 { warn = true ; * d = 0.0_f64 ; } } if warn { // warn!( //     "Corrected dispersal values to 0.0 at ({},{}) to fit // \      habitat ...", x, y, // ); } } else { let mut total_dispersal = 0.0_f64 ; // Fix dispersal to non-habitat for column in 0 .. size { let tx = column % habitat . num_columns ( ) ; let ty = column / habitat . num_columns ( ) ; let d = & mut dispersal [ ( row , column ) ] ; if habitat [ ( ty , tx ) ] == 0 && * d > 0.0_f64 { // warn!( //     "Corrected dispersal value {} to 0.0 at ({},{})->({},{}) to fit \ //      habitat ...", //     *d, x, y, tx, ty, // ); * d = 0.0_f64 ; } total_dispersal += * d ; } // Fix no dispersal from habitat with self-dispersal if total_dispersal <= 0.0_f64 { dispersal [ ( row , row ) ] = 1.0_f64 ; } } } } }
Fix dispersal by removing dispersal to/from non-habitat
Fix dispersal by adding self-dispersal when no dispersal exists from habitat
Fix dispersal by removing dispersal to / from non - habitat Fix dispersal by adding self - dispersal when no dispersal exists from habitat
habitat
&Array2D<u32>
dispersal
&mut Array2D<f64>
habitat
&Array2D<u32>
dispersal
&mut Array2D<f64>