fn water_distribution(
    water: f64,
    has_left: bool,
    has_right: bool,
    peak_heigth: u64,
    peak_width: f64,
    left_grounds: &[u64],
    right_grounds: &[u64],
    at_left_edge: bool,
    at_right_edge: bool,
    left_edge_peaks: usize,
    right_edge_peaks: usize,
) -> WaterDistribution {
    //trivial cases
    if !has_left {
        return WaterDistribution {
            left: 0.0,
            right: water,
        };
    }
    if !has_right {
        return WaterDistribution {
            left: water,
            right: 0.0,
        };
    }

    // If both ranges have parts that are still submerged displacment is not limiting water
    // uptake. Water is distributed by ranges only, that represents the area it rains upon.
    // The peak(s) separating left and right ranges are distributed evenly.
    let f_dist_range = |gs: &[u64]| peak_width / 2.0 + gs.len() as f64;

    // distribute water from peaks evenly to either side, and correct for boundary effects:
    // (The problem has impermeable boundaries. When these are next to the ranges considered
    // here they behave differently than other tiles.)
    let left_range = if !at_left_edge {
        f_dist_range(left_grounds) + 0.5f64.max(left_edge_peaks as f64)
    } else {
        f_dist_range(left_grounds)
    };
    let right_range = if !at_right_edge {
        f_dist_range(right_grounds) + 0.5f64.max(right_edge_peaks as f64)
    } else {
        f_dist_range(right_grounds)
    };

    let f_rain = |r| r * water / (left_range + right_range);
    let left_rain = f_rain(left_range);
    let right_rain = f_rain(right_range);

    // check if well has enough space to hold water
    let left_well_volume = well_volume(left_grounds, peak_heigth);
    let right_well_volume = well_volume(right_grounds, peak_heigth);

    // if either side has not enough space to hold rain, distribute excees to the other side
    let mut left = left_rain;
    let mut right = right_rain;
    if left_rain > left_well_volume {
        left = left_well_volume;
        right = water - left;
    } else if right_rain > right_well_volume {
        right = right_well_volume;
        left = water - right;
    }

    return WaterDistribution { left, right };
}
// water_distribution function
// distributes water like rain: evenly by area. As long as there is enough room
// on both sides to take in water.  When one side reaches saturation it
// distributes water by accounting for displacment by submerged land mass.
water_distribution function
distributes water like rain: evenly by area. As long as there is enough room
on both sides to take in water.  When one side reaches saturation it
distributes water by accounting for displacment by submerged land mass.
water_distribution function distributes water like rain : evenly by area . As long as there is enough room on both sides to take in water . When one side reaches saturation it distributes water by accounting for displacment by submerged land mass .
fn water_distribution(
    water: f64,
    has_left: bool,
    has_right: bool,
    peak_heigth: u64,
    peak_width: f64,
    left_grounds: &[u64],
    right_grounds: &[u64],
    at_left_edge: bool,
    at_right_edge: bool,
    left_edge_peaks: usize,
    right_edge_peaks: usize,
) -> WaterDistribution {
    //trivial cases
    if !has_left {
        return WaterDistribution {
            left: 0.0,
            right: water,
        };
    }
    if !has_right {
        return WaterDistribution {
            left: water,
            right: 0.0,
        };
    }
    // If both ranges have parts that are still submerged displacment is not limiting water
    // uptake. Water is distributed by ranges only, that represents the area it rains upon.
    // The peak(s) separating left and right ranges are distributed evenly.
    let f_dist_range = |gs: &[u64]| peak_width / 2.0 + gs.len() as f64;
    // distribute water from peaks evenly to either side, and correct for boundary effects:
    // (The problem has impermeable boundaries. When these are next to the ranges considered
    // here they behave differently than other tiles.)
    let left_range = if !at_left_edge {
        f_dist_range(left_grounds) + 0.5f64.max(left_edge_peaks as f64)
    } else {
        f_dist_range(left_grounds)
    };
    let right_range = if !at_right_edge {
        f_dist_range(right_grounds) + 0.5f64.max(right_edge_peaks as f64)
    } else {
        f_dist_range(right_grounds)
    };
    let f_rain = |r| r * water / (left_range + right_range);
    let left_rain = f_rain(left_range);
    let right_rain = f_rain(right_range);
    // check if well has enough space to hold water
    let left_well_volume = well_volume(left_grounds, peak_heigth);
    let right_well_volume = well_volume(right_grounds, peak_heigth);
    // if either side has not enough space to hold rain, distribute excees to the other side
    let mut left = left_rain;
    let mut right = right_rain;
    if left_rain > left_well_volume {
        left = left_well_volume;
        right = water - left;
    } else if right_rain > right_well_volume {
        right = right_well_volume;
        left = water - right;
    }
    return WaterDistribution { left, right };
}
fn water_distribution ( water : f64 , has_left : bool , has_right : bool , peak_heigth : u64 , peak_width : f64 , left_grounds : & [ u64 ] , right_grounds : & [ u64 ] , at_left_edge : bool , at_right_edge : bool , left_edge_peaks : usize , right_edge_peaks : usize , ) -> WaterDistribution { //trivial cases if ! has_left { return WaterDistribution { left : 0.0 , right : water , } ; } if ! has_right { return WaterDistribution { left : water , right : 0.0 , } ; } // If both ranges have parts that are still submerged displacment is not limiting water // uptake. Water is distributed by ranges only, that represents the area it rains upon. // The peak(s) separating left and right ranges are distributed evenly. let f_dist_range = | gs : & [ u64 ] | peak_width / 2.0 + gs . len ( ) as f64 ; // distribute water from peaks evenly to either side, and correct for boundary effects: // (The problem has impermeable boundaries. When these are next to the ranges considered // here they behave differently than other tiles.) let left_range = if ! at_left_edge { f_dist_range ( left_grounds ) + 0.5f64 . max ( left_edge_peaks as f64 ) } else { f_dist_range ( left_grounds ) } ; let right_range = if ! at_right_edge { f_dist_range ( right_grounds ) + 0.5f64 . max ( right_edge_peaks as f64 ) } else { f_dist_range ( right_grounds ) } ; let f_rain = | r | r * water / ( left_range + right_range ) ; let left_rain = f_rain ( left_range ) ; let right_rain = f_rain ( right_range ) ; // check if well has enough space to hold water let left_well_volume = well_volume ( left_grounds , peak_heigth ) ; let right_well_volume = well_volume ( right_grounds , peak_heigth ) ; // if either side has not enough space to hold rain, distribute excees to the other side let mut left = left_rain ; let mut right = right_rain ; if left_rain > left_well_volume { left = left_well_volume ; right = water - left ; } else if right_rain > right_well_volume { right = right_well_volume ; left = water - right ; } return WaterDistribution { left , right } ; }
water_distribution function
distributes water like rain: evenly by area.
water_distribution function distributes water like rain : evenly by area .
water
f64
has_left
bool
has_right
bool
peak_heigth
u64
peak_width
f64
left_grounds
&[u64]
right_grounds
&[u64]
at_left_edge
bool
at_right_edge
bool
left_edge_peaks
usize
right_edge_peaks
usize
water
f64
has_left
bool
has_right
bool
peak_heigth
u64
peak_width
f64
left_grounds
&[u64]
right_grounds
&[u64]
at_left_edge
bool
at_right_edge
bool
left_edge_peaks
usize
right_edge_peaks
usize