pub fn copy_2d<T: Clone>(
    source: &Vec<T>,
    target: &mut Vec<T>,
    old_cols: usize,
    new_cols: usize,
    factor: usize,
    margin: usize,
) {
    let source_len = source.len();
    let target_len = target.len();

    // Calculate minimum / maximum amount of rows and cols
    let (min_cols, max_cols) = min_max(old_cols, new_cols);
    let (min_rows, max_rows) = min_max(source_len / old_cols, target_len / new_cols);

    // Calculate horizontal and vertical padding, used to center values
    let col_offset = floor_to((max_cols - min_cols) / 2, factor);
    let col_limit = floor_to(col_offset + min_cols, factor);
    let row_offset = (max_rows - min_rows) / 2;
    let row_limit = row_offset + min_rows;

    // Copy values, max is always the destination and min the source.
    // If the target is smaller both indices need to swapped.
    // It took me like 12h to code the following part, I'm super tired and I don't
    // even know how it works anymore - I beg your pardon.
    let swap = target_len > source_len;
    for row in (row_offset + margin)..(row_limit - margin) {
        let min_offset = (row - row_offset) * min_cols;
        let max_offset = row * max_cols;

        for col in (col_offset + margin)..(col_limit - margin) {
            let min_index = min_offset + (col - col_offset);
            let max_index = max_offset + col;

            if swap {
                target[max_index] = source[min_index].clone();
            } else {
                target[min_index] = source[max_index].clone();
            }
        }
    }
}
/// Copies values from a source-vector into the target vector without
/// losing the aspect-ration defined by old_cols and new_cols.
/// factor is used in case the vector contains value-pairs and, in case of
/// resizing, only entire pairs should be copied.
Copies values from a source-vector into the target vector without
losing the aspect-ration defined by old_cols and new_cols.
factor is used in case the vector contains value-pairs and, in case of
resizing, only entire pairs should be copied.
Copies values from a source - vector into the target vector without losing the aspect - ration defined by old_cols and new_cols . factor is used in case the vector contains value - pairs and in case of resizing only entire pairs should be copied .
pub fn copy_2d<T: Clone>(
    source: &Vec<T>,
    target: &mut Vec<T>,
    old_cols: usize,
    new_cols: usize,
    factor: usize,
    margin: usize,
) {
    let source_len = source.len();
    let target_len = target.len();
    // Calculate minimum / maximum amount of rows and cols
    let (min_cols, max_cols) = min_max(old_cols, new_cols);
    let (min_rows, max_rows) = min_max(source_len / old_cols, target_len / new_cols);
    // Calculate horizontal and vertical padding, used to center values
    let col_offset = floor_to((max_cols - min_cols) / 2, factor);
    let col_limit = floor_to(col_offset + min_cols, factor);
    let row_offset = (max_rows - min_rows) / 2;
    let row_limit = row_offset + min_rows;
    // Copy values, max is always the destination and min the source.
    // If the target is smaller both indices need to swapped.
    // It took me like 12h to code the following part, I'm super tired and I don't
    // even know how it works anymore - I beg your pardon.
    let swap = target_len > source_len;
    for row in (row_offset + margin)..(row_limit - margin) {
        let min_offset = (row - row_offset) * min_cols;
        let max_offset = row * max_cols;
        for col in (col_offset + margin)..(col_limit - margin) {
            let min_index = min_offset + (col - col_offset);
            let max_index = max_offset + col;
            if swap {
                target[max_index] = source[min_index].clone();
            } else {
                target[min_index] = source[max_index].clone();
            }
        }
    }
}
pub fn copy_2d < T : Clone > ( source : & Vec < T > , target : & mut Vec < T > , old_cols : usize , new_cols : usize , factor : usize , margin : usize , ) { let source_len = source . len ( ) ; let target_len = target . len ( ) ; // Calculate minimum / maximum amount of rows and cols let ( min_cols , max_cols ) = min_max ( old_cols , new_cols ) ; let ( min_rows , max_rows ) = min_max ( source_len / old_cols , target_len / new_cols ) ; // Calculate horizontal and vertical padding, used to center values let col_offset = floor_to ( ( max_cols - min_cols ) / 2 , factor ) ; let col_limit = floor_to ( col_offset + min_cols , factor ) ; let row_offset = ( max_rows - min_rows ) / 2 ; let row_limit = row_offset + min_rows ; // Copy values, max is always the destination and min the source. // If the target is smaller both indices need to swapped. // It took me like 12h to code the following part, I'm super tired and I don't // even know how it works anymore - I beg your pardon. let swap = target_len > source_len ; for row in ( row_offset + margin ) .. ( row_limit - margin ) { let min_offset = ( row - row_offset ) * min_cols ; let max_offset = row * max_cols ; for col in ( col_offset + margin ) .. ( col_limit - margin ) { let min_index = min_offset + ( col - col_offset ) ; let max_index = max_offset + col ; if swap { target [ max_index ] = source [ min_index ] . clone ( ) ; } else { target [ min_index ] = source [ max_index ] . clone ( ) ; } } } }
Copies values from a source-vector into the target vector without
losing the aspect-ration defined by old_cols and new_cols.
Copies values from a source - vector into the target vector without losing the aspect - ration defined by old_cols and new_cols .
source
&Vec<T>
target
&mut Vec<T>
old_cols
usize
new_cols
usize
factor
usize
margin
usize
source
&Vec<T>
target
&mut Vec<T>
old_cols
usize
new_cols
usize
factor
usize
margin
usize