pub fn invert_2d_vec<T>(v: &mut Vec<Vec<T>>)
where
    Vec<T>: Clone,
    T: Default + Clone,
{
    let height = v.len();
    let width = v.iter().map(|v| v.len()).max().unwrap();

    // expand the vector into a square
    let size = if height > width {
        for u in v.iter_mut() {
            u.resize_with(height, Default::default);
        }
        height
    } else {
        for u in v.iter_mut() {
            u.resize_with(width, Default::default);
        }
        v.resize(
            width,
            std::iter::repeat_with(Default::default)
                .take(width)
                .collect(),
        );
        width
    };

    // swap the values
    for i in 0..(size - 1) {
        for j in (1 + i)..(size) {
            swap_2d_vec(v, (i, j), (j, i));
        }
    }

    // truncate the vector
    if height > width {
        v.truncate(width)
    } else {
        for u in v.iter_mut() {
            u.truncate(height);
        }
    }
}
// invert a 2-dimensional vector
invert a 2-dimensional vector
invert a 2 - dimensional vector
pub fn invert_2d_vec<T>(v: &mut Vec<Vec<T>>)
where
    Vec<T>: Clone,
    T: Default + Clone,
{
    let height = v.len();
    let width = v.iter().map(|v| v.len()).max().unwrap();
    // expand the vector into a square
    let size = if height > width {
        for u in v.iter_mut() {
            u.resize_with(height, Default::default);
        }
        height
    } else {
        for u in v.iter_mut() {
            u.resize_with(width, Default::default);
        }
        v.resize(
            width,
            std::iter::repeat_with(Default::default)
                .take(width)
                .collect(),
        );
        width
    };
    // swap the values
    for i in 0..(size - 1) {
        for j in (1 + i)..(size) {
            swap_2d_vec(v, (i, j), (j, i));
        }
    }
    // truncate the vector
    if height > width {
        v.truncate(width)
    } else {
        for u in v.iter_mut() {
            u.truncate(height);
        }
    }
}
pub fn invert_2d_vec < T > ( v : & mut Vec < Vec < T > > ) where Vec < T > : Clone , T : Default + Clone , { let height = v . len ( ) ; let width = v . iter ( ) . map ( | v | v . len ( ) ) . max ( ) . unwrap ( ) ; // expand the vector into a square let size = if height > width { for u in v . iter_mut ( ) { u . resize_with ( height , Default :: default ) ; } height } else { for u in v . iter_mut ( ) { u . resize_with ( width , Default :: default ) ; } v . resize ( width , std :: iter :: repeat_with ( Default :: default ) . take ( width ) . collect ( ) , ) ; width } ; // swap the values for i in 0 .. ( size - 1 ) { for j in ( 1 + i ) .. ( size ) { swap_2d_vec ( v , ( i , j ) , ( j , i ) ) ; } } // truncate the vector if height > width { v . truncate ( width ) } else { for u in v . iter_mut ( ) { u . truncate ( height ) ; } } }
invert a 2-dimensional vector
invert a 2 - dimensional vector
v
&mut Vec<Vec<T>>
v
&mut Vec<Vec<T>>