Introduce Cut

AfoHT
Jan 21, 2024, 10:29 PM
4YYL4VTYM7SVQG5KUT6AJHMABLCOC4LQESBUWHUZ7OQCKJTM4MAQC

Dependencies

  • [2] LXMNVVD2 Change to proper measurements
  • [3] Q7IWKL57 Calculate required length once and reuse
  • [4] JCYHD3FD Minimum size plank is 300mm
  • [5] ZJPL7VNQ Separate planks from main
  • [6] SMYRM2CF Use the MaterialStorage
  • [7] OK5CKW6E Rework everything, use references
  • [8] C5VVJ5SO Print how many rows
  • [9] MLUGR2LL Add default impl and some basic plank logic
  • [10] VSG6UWDY Can now build floors
  • [11] JPTYS433 Cleanup, clippy
  • [12] CT3VONTO Introduce PLANKMIN and work with the neverending rows
  • [*] B75B3UUK Create a MaterialStorage
  • [*] 5TH3AA46 10 mm extra space

Change contents

  • replacement in src/lib.rs at line 3
    [5.2757][5.1859:1923]()
    use constants::{AVAILABLEPLANKS, PLANKMAX, PLANKMIN, SAWBLADE};
    [5.2757]
    [5.77]
    use constants::{AVAILABLEPLANKS, CUTADJACENCY, PLANKMAX, PLANKMIN, PLAY, ROOMLENGTH, SAWBLADE};
  • edit in src/lib.rs at line 65
    [5.3468]
    [14.1175]
    }
    }
    // Define a plank cut structure
    #[derive(Debug, Clone, Copy)]
    pub struct Cut {
    pub coordinate: u32,
    }
    impl Cut {
    pub fn new(coordinate: u32) -> Self {
    Cut { coordinate }
  • replacement in src/lib.rs at line 160
    [5.1762][5.108:130]()
    planks_used: u32,
    [5.1762]
    [5.1762]
    cut_coordinates: Vec<Cut>,
  • replacement in src/lib.rs at line 170
    [5.1924][5.0:28]()
    planks_used: 1,
    [5.1924]
    [5.1924]
    cut_coordinates: vec![],
  • edit in src/lib.rs at line 244
    [5.2850]
    [5.2850]
    pub fn get_cut_coordinates(&self) -> Vec<Cut> {
    return self.cut_coordinates.clone();
    }
    pub fn check_if_cut_is_valid(&self, new_cut: Cut) -> bool {
    // If we have no cuts, no need to check them
    if !self.cut_coordinates.is_empty() {
    for cut in &self.cut_coordinates {
    println!("Cut coordinate {}", cut.coordinate);
    if cut.coordinate.abs_diff(new_cut.coordinate) < CUTADJACENCY {
    // Invalid, cut is too close!
    return false;
    }
    }
    }
    return true;
    }
  • edit in src/constants.rs at line 7
    [4.33]
    [5.2248]
    /// The smalles allowed space between plank cuts
    pub static CUTADJACENCY: u32 = 400;
  • replacement in src/bin/main.rs at line 4
    [2.97][5.152:196](),[5.152][5.152:196]()
    use parkett::{Floor, MaterialStorage, Row};
    [2.97]
    [5.84]
    use parkett::{Cut, Floor, MaterialStorage, Row};
  • replacement in src/bin/main.rs at line 112
    [5.4040][3.0:63]()
    let required_length = ROOMLENGTH - row.get_coverage();
    [5.4040]
    [5.412]
    let required_length = row.get_max_length() - row.get_coverage();
    if let Some(adjacent_row) = adjacent_row {
    println!("Cut coordinates: {:?}", row.get_cut_coordinates());
    // Check if the new plank lands too close to a previous cut
    // Or a new one
    if !adjacent_row.check_if_cut_is_valid(Cut::new(required_length)) {
    println!("Invalid cut at {required_length}!!! Handle this");
    } else if !adjacent_row.check_if_cut_is_valid(Cut::new(PLANKMAX)) {
    println!("Invalid cut at {PLANKMAX}!!! Handle this");
    }
    }