fn advect(density_prev: &Array2<f32>, velocity: &Array2<Vec2>, dt: f32) -> Array2<f32> {
    let shape = density_prev.shape();
    let mut output: Array2<f32> = Array2::zeros((shape[0], shape[1]));
    let v_shape = vec2(shape[0] as f32, shape[1] as f32);
    let dt_shape = dt * v_shape;
    for x in 1..(shape[0] - 1) {
        for y in 1..(shape[1] - 1) {
            let el = ((x, y), density_prev[(x, y)]);
            let pos = vec2(el.0 .0 as f32, el.0 .1 as f32) - dt_shape * velocity[el.0];
            let pos_clamp = pos.clamp(vec2(0.5, 0.5), v_shape + vec2(0.5, 0.5));
            let pos_floor = vec2(pos_clamp.x.floor(), pos_clamp.y.floor());
            let pos_frac = pos_clamp - pos_floor;
            let neg_frac = vec2(1.0, 1.0) - pos_frac;

            let index_pos = (pos_floor.x as usize, pos_floor.y as usize);

            output[el.0] = neg_frac.x
                * (neg_frac.y * density_prev[index_pos]
                    + pos_frac.y * density_prev[(index_pos.0, index_pos.1 + 1)])
                + pos_frac.x
                    * (neg_frac.y * density_prev[(index_pos.0 + 1, index_pos.1)]
                        + pos_frac.y * density_prev[(index_pos.0 + 1, index_pos.1 + 1)]);
        }
    }
    set_boundries(&mut output);
    output
}
/// Trace backwards with linear interpolation to sources of current density
/// then set value as a suitable average of the nearby densities of the past
Trace backwards with linear interpolation to sources of current density
then set value as a suitable average of the nearby densities of the past
Trace backwards with linear interpolation to sources of current density then set value as a suitable average of the nearby densities of the past
fn advect(density_prev: &Array2<f32>, velocity: &Array2<Vec2>, dt: f32) -> Array2<f32> {
    let shape = density_prev.shape();
    let mut output: Array2<f32> = Array2::zeros((shape[0], shape[1]));
    let v_shape = vec2(shape[0] as f32, shape[1] as f32);
    let dt_shape = dt * v_shape;
    for x in 1..(shape[0] - 1) {
        for y in 1..(shape[1] - 1) {
            let el = ((x, y), density_prev[(x, y)]);
            let pos = vec2(el.0 .0 as f32, el.0 .1 as f32) - dt_shape * velocity[el.0];
            let pos_clamp = pos.clamp(vec2(0.5, 0.5), v_shape + vec2(0.5, 0.5));
            let pos_floor = vec2(pos_clamp.x.floor(), pos_clamp.y.floor());
            let pos_frac = pos_clamp - pos_floor;
            let neg_frac = vec2(1.0, 1.0) - pos_frac;
            let index_pos = (pos_floor.x as usize, pos_floor.y as usize);
            output[el.0] = neg_frac.x
                * (neg_frac.y * density_prev[index_pos]
                    + pos_frac.y * density_prev[(index_pos.0, index_pos.1 + 1)])
                + pos_frac.x
                    * (neg_frac.y * density_prev[(index_pos.0 + 1, index_pos.1)]
                        + pos_frac.y * density_prev[(index_pos.0 + 1, index_pos.1 + 1)]);
        }
    }
    set_boundries(&mut output);
    output
}
fn advect ( density_prev : & Array2 < f32 > , velocity : & Array2 < Vec2 > , dt : f32 ) -> Array2 < f32 > { let shape = density_prev . shape ( ) ; let mut output : Array2 < f32 > = Array2 :: zeros ( ( shape [ 0 ] , shape [ 1 ] ) ) ; let v_shape = vec2 ( shape [ 0 ] as f32 , shape [ 1 ] as f32 ) ; let dt_shape = dt * v_shape ; for x in 1 .. ( shape [ 0 ] - 1 ) { for y in 1 .. ( shape [ 1 ] - 1 ) { let el = ( ( x , y ) , density_prev [ ( x , y ) ] ) ; let pos = vec2 ( el . 0 . 0 as f32 , el . 0 . 1 as f32 ) - dt_shape * velocity [ el . 0 ] ; let pos_clamp = pos . clamp ( vec2 ( 0.5 , 0.5 ) , v_shape + vec2 ( 0.5 , 0.5 ) ) ; let pos_floor = vec2 ( pos_clamp . x . floor ( ) , pos_clamp . y . floor ( ) ) ; let pos_frac = pos_clamp - pos_floor ; let neg_frac = vec2 ( 1.0 , 1.0 ) - pos_frac ; let index_pos = ( pos_floor . x as usize , pos_floor . y as usize ) ; output [ el . 0 ] = neg_frac . x * ( neg_frac . y * density_prev [ index_pos ] + pos_frac . y * density_prev [ ( index_pos . 0 , index_pos . 1 + 1 ) ] ) + pos_frac . x * ( neg_frac . y * density_prev [ ( index_pos . 0 + 1 , index_pos . 1 ) ] + pos_frac . y * density_prev [ ( index_pos . 0 + 1 , index_pos . 1 + 1 ) ] ) ; } } set_boundries ( & mut output ) ; output }
Trace backwards with linear interpolation to sources of current density
then set value as a suitable average of the nearby densities of the past
Trace backwards with linear interpolation to sources of current density then set value as a suitable average of the nearby densities of the past
density_prev
&Array2<f32>
velocity
&Array2<Vec2>
dt
f32
density_prev
&Array2<f32>
velocity
&Array2<Vec2>
dt
f32