unsafe fn process_sections(mut sections: [Section; 4], color: u32) {
    for pair in sections.chunks_mut(2) {
        if pair[0].x_start > pair[1].x_start {
            continue;
        }

        if pair[0].y_start < 0 {
            let diff = (-pair[0].y_start) as f64;
            for sec in pair.iter_mut() {
                sec.x_start += diff * sec.x_step;
                sec.br_start += diff * sec.br_step;
                sec.z_start += diff * sec.z_step;
            }
            pair[0].y_start = 0;
        }

        for y in (pair[0].y_start..=pair[0].y_end)
            .filter(|&elem| elem < constants::HEIGHT as i16)
            .map(|y| y as usize)
        {
            let x_from = f64::round(pair[0].x_start) as usize;
            let x_to = f64::round(pair[1].x_start) as usize;
            let diff_x = (x_to - x_from) as f64;

            let mut br = pair[0].br_start;
            let br_diff = (pair[1].br_start - br) / diff_x;
            let mut z = pair[0].z_start;
            let z_diff = (pair[1].z_start - z) / diff_x;

            for x in (x_from..=x_to).filter(|&x| x < constants::WIDTH) {
                if z > Z_BUFFER[y][x] {
                    Z_BUFFER[y][x] = z;
                    put_color(x, y, color, br);
                }

                br += br_diff;
                z += z_diff;
            }

            for sec in pair.iter_mut() {
                sec.x_start += sec.x_step;
                sec.br_start += sec.br_step;
                sec.z_start += sec.z_step;
            }
        }
    }
}
// application of Gouraud and Z-buffer algorithms for 2 processed triangles
application of Gouraud and Z-buffer algorithms for 2 processed triangles
application of Gouraud and Z - buffer algorithms for 2 processed triangles
unsafe fn process_sections(mut sections: [Section; 4], color: u32) {
    for pair in sections.chunks_mut(2) {
        if pair[0].x_start > pair[1].x_start {
            continue;
        }
        if pair[0].y_start < 0 {
            let diff = (-pair[0].y_start) as f64;
            for sec in pair.iter_mut() {
                sec.x_start += diff * sec.x_step;
                sec.br_start += diff * sec.br_step;
                sec.z_start += diff * sec.z_step;
            }
            pair[0].y_start = 0;
        }
        for y in (pair[0].y_start..=pair[0].y_end)
            .filter(|&elem| elem < constants::HEIGHT as i16)
            .map(|y| y as usize)
        {
            let x_from = f64::round(pair[0].x_start) as usize;
            let x_to = f64::round(pair[1].x_start) as usize;
            let diff_x = (x_to - x_from) as f64;
            let mut br = pair[0].br_start;
            let br_diff = (pair[1].br_start - br) / diff_x;
            let mut z = pair[0].z_start;
            let z_diff = (pair[1].z_start - z) / diff_x;
            for x in (x_from..=x_to).filter(|&x| x < constants::WIDTH) {
                if z > Z_BUFFER[y][x] {
                    Z_BUFFER[y][x] = z;
                    put_color(x, y, color, br);
                }
                br += br_diff;
                z += z_diff;
            }
            for sec in pair.iter_mut() {
                sec.x_start += sec.x_step;
                sec.br_start += sec.br_step;
                sec.z_start += sec.z_step;
            }
        }
    }
}
unsafe fn process_sections ( mut sections : [ Section ; 4 ] , color : u32 ) { for pair in sections . chunks_mut ( 2 ) { if pair [ 0 ] . x_start > pair [ 1 ] . x_start { continue ; } if pair [ 0 ] . y_start < 0 { let diff = ( - pair [ 0 ] . y_start ) as f64 ; for sec in pair . iter_mut ( ) { sec . x_start += diff * sec . x_step ; sec . br_start += diff * sec . br_step ; sec . z_start += diff * sec . z_step ; } pair [ 0 ] . y_start = 0 ; } for y in ( pair [ 0 ] . y_start ..= pair [ 0 ] . y_end ) . filter ( | & elem | elem < constants :: HEIGHT as i16 ) . map ( | y | y as usize ) { let x_from = f64 :: round ( pair [ 0 ] . x_start ) as usize ; let x_to = f64 :: round ( pair [ 1 ] . x_start ) as usize ; let diff_x = ( x_to - x_from ) as f64 ; let mut br = pair [ 0 ] . br_start ; let br_diff = ( pair [ 1 ] . br_start - br ) / diff_x ; let mut z = pair [ 0 ] . z_start ; let z_diff = ( pair [ 1 ] . z_start - z ) / diff_x ; for x in ( x_from ..= x_to ) . filter ( | & x | x < constants :: WIDTH ) { if z > Z_BUFFER [ y ] [ x ] { Z_BUFFER [ y ] [ x ] = z ; put_color ( x , y , color , br ) ; } br += br_diff ; z += z_diff ; } for sec in pair . iter_mut ( ) { sec . x_start += sec . x_step ; sec . br_start += sec . br_step ; sec . z_start += sec . z_step ; } } } }
application of Gouraud and Z-buffer algorithms for 2 processed triangles
application of Gouraud and Z - buffer algorithms for 2 processed triangles
sections
[Section; 4]
color
u32
sections
[Section; 4]
color
u32