Rework everything, use references

[?]
Apr 2, 2021, 4:42 PM
OK5CKW6E72XAZTRJUWSKFPJBPZYNIWQGVXFR5ARSJHB6EIBMU6WQC

Dependencies

  • [2] AATEG4HI Remove todo, improve comment
  • [3] DBIA6R5X Fix get_plank()
  • [4] B75B3UUK Create a MaterialStorage
  • [5] SMYRM2CF Use the MaterialStorage
  • [6] CT3VONTO Introduce PLANKMIN and work with the neverending rows
  • [7] Y4AQJ5RD Other defaults
  • [8] 5TH3AA46 10 mm extra space
  • [9] ES2PMPT4 Using structures instead
  • [10] ZJPL7VNQ Separate planks from main
  • [11] F3GMCMWT Merge branch 'master' into sovrum
  • [12] RQRFFUF6 Can build the first basic row
  • [13] UPCMFGXF Print more about the room and define PLAY
  • [14] USO5PZWO Start with the print function, separate mutable and immutable functions
  • [15] MLUGR2LL Add default impl and some basic plank logic
  • [16] JBGHRTSW Use the new defaults
  • [17] NRQSXJVR Initial commit
  • [18] 3H2BGWRG WIP
  • [19] VSG6UWDY Can now build floors
  • [20] 6ODVKCN4 Fix printouts of relative lengths
  • [21] C5VVJ5SO Print how many rows
  • [22] U4JRHEA7 fmt
  • [23] 2USDM5CH WIP for more generic

Change contents

  • file addition: bin (d--r------)
    [6.487]
  • file move: main.rs (----------)main.rs (----------)
    [0.1]
    [6.1]
  • replacement in src/bin/main.rs at line 3
    [6.3565][6.3565:3576](),[6.3576][4.1408:1457](),[6.32][6.3608:3609](),[4.1457][6.3608:3609](),[6.3608][6.3608:3609](),[6.3609][6.478:508](),[6.508][6.3609:3640](),[6.3609][6.3609:3640](),[6.3640][6.0:347](),[6.347][5.0:60](),[6.51][6.509:577](),[5.60][6.509:577](),[6.406][6.509:577](),[6.3669][6.509:577](),[6.577][6.407:437](),[6.437][5.61:83](),[5.83][6.3670:3697](),[6.82][6.3670:3697](),[6.3697][6.0:33](),[6.82][6.0:33](),[6.33][6.438:499](),[6.499][6.199:231](),[6.199][6.199:231]()
    mod floor;
    use floor::{Floor, MaterialStorage, Plank, Row};
    /// The length of a new plank
    //static PLANKMAX: u32 = 2200;
    //static PLANKMAX: u32 = 2010;
    /// The smallest allowable plank length
    //static PLANKMIN: u32 = 200;
    //static PLANKWIDTH: u32 = 185;
    //static PLAY: u32 = 20;
    //static SAWBLADE: u32 = 10;
    //static ROOMLENGTH: u32 = 3800;
    //static ROOMLENGTH: u32 = 1000;
    //static ROOMDEPTH: u32 = 555;
    //static ROOMDEPTH: u32 = 2800;
    /// The length of a new plank
    static PLANKMAX: u32 = 2200;
    //static PLANKMAX: u32 = 1900;
    /// The smallest allowable plank length
    static PLANKMIN: u32 = 200;
    static PLANKWIDTH: u32 = 100;
    static PLAY: u32 = 5;
    static SAWBLADE: u32 = 10;
    //static ROOMLENGTH: u32 = 3800;
    static ROOMLENGTH: u32 = 5000;
    static ROOMDEPTH: u32 = 1000;
    //static ROOMDEPTH: u32 = 2800;
    [6.3565]
    [5.84]
    use parkett::constants::{
    PLANKMAX, PLANKMIN, PLANKWIDTH, PLAY, ROOMDEPTH, ROOMLENGTH, SAWBLADE,
    };
    use parkett::{Floor, MaterialStorage, Row};
  • edit in src/bin/main.rs at line 8
    [5.85][5.85:198]()
    // How many planks are available?
    // Add ability to add "used"/pre-cut planks
    static AVAILABLEPLANKS: u32 = 10;
  • replacement in src/bin/main.rs at line 19
    [5.241][5.241:409]()
    // Create a pool of planks, modify the constant AVAILABLEPLANKS
    // to the total number of full length available planks
    let ms = MaterialStorage::default();
    [5.241]
    [6.186]
    // Create a pool of planks
    // To change, modify constants.rs
    let mut ms = MaterialStorage::default();
    //println!("MS: {:#?}", ms);
  • replacement in src/bin/main.rs at line 24
    [6.187][5.410:451]()
    let floor: Floor = Floor::default();
    [6.187]
    [5.451]
    // Create an empty "room", floor with no planks
    let mut floor: Floor = Floor::default();
  • replacement in src/bin/main.rs at line 27
    [5.452][5.452:501]()
    //println!("Material storage:\n {:#?}", ms);
    [5.452]
    [6.296]
    floor_build(&mut floor, &mut ms);
    //println!("Floor: {:#?}", finished_floor);
  • replacement in src/bin/main.rs at line 30
    [6.297][5.502:557](),[5.557][6.496:544](),[6.496][6.496:544](),[6.544][6.539:573]()
    let (finished_floor, ms) = floor_build(floor, ms);
    //println!("Floor: {:#?}", finished_floor);
    floor_print(&finished_floor);
    [6.297]
    [5.558]
    floor_print(&floor, &ms);
  • edit in src/bin/main.rs at line 33
    [5.631]
    [6.1250]
    //println!("Material storage:\n {:#?}", ms);
  • edit in src/bin/main.rs at line 35
    [6.133][6.354:355](),[6.161][6.354:355](),[6.538][6.354:355](),[6.1252][6.354:355](),[6.354][6.354:355](),[6.355][6.574:612](),[6.613][6.613:637]()
    fn floor_print(floor: &Floor) -> () {
    let printmax = 100;
  • replacement in src/bin/main.rs at line 36
    [6.667][6.667:700]()
    let mut plank_count_sum = 0;
    [6.638]
    [6.700]
    fn floor_print(floor: &Floor, ms: &MaterialStorage) -> () {
    let scalefactor = 100;
  • replacement in src/bin/main.rs at line 40
    [6.757][6.265:312]()
    plank_count_sum += row.planks_count();
    [6.757]
    [6.720]
    // Try to compensate for the extra size taken by
    // the number printout
    //let comp = 30 * row.planks_count();
    let comp = 0;
  • replacement in src/bin/main.rs at line 49
    [6.398][6.398:456]()
    for _ in 0..(plank.length() / printmax) / 2 {
    [6.398]
    [6.456]
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
  • replacement in src/bin/main.rs at line 54
    [6.540][6.540:586]()
    print!("{:-^5}", plank.length());
    [6.540]
    [6.809]
    print!("{:-^8}", plank.length());
  • replacement in src/bin/main.rs at line 57
    [6.648][6.648:706]()
    for _ in 0..(plank.length() / printmax) / 2 {
    [6.648]
    [6.706]
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
  • edit in src/bin/main.rs at line 60
    [6.1392][6.736:761]()
    print!("|");
  • replacement in src/bin/main.rs at line 61
    [6.1425][6.1046:1087]()
    println!("row: {:#?}", num + 1);
    [6.1425]
    [6.1425]
    // Print the end of the row of planks
    print!("|");
    println!("\t\trow: {:#?}", num + 1);
  • replacement in src/bin/main.rs at line 68
    [6.1144][5.632:696]()
    println!("Number of planks required: {}", plank_count_sum);
    [6.1144]
    [6.1476]
    println!(
    "Number of planks required: {}",
    ms.total_planks - ms.planks_new.len() as u32
    );
  • replacement in src/bin/main.rs at line 74
    [6.1479][5.697:785]()
    fn floor_build(mut floor: Floor, mut ms: MaterialStorage) -> (Floor, MaterialStorage) {
    [6.1479]
    [6.629]
    fn floor_build(floor: &mut Floor, mut ms: &mut MaterialStorage) -> () {
  • replacement in src/bin/main.rs at line 76
    [6.674][6.762:823](),[6.823][5.786:868](),[5.868][6.675:715](),[6.1349][6.675:715]()
    //println!("coverage: {:#?}", floor.get_coverage());
    // TODO, deal with unwrap
    floor.add(build_row(&mut ms).unwrap());
    floor.add_coverage(PLANKWIDTH);
    [6.674]
    [6.1349]
    match build_row(&mut ms) {
    Some(row) => {
    floor.add(row);
    floor.add_coverage(PLANKWIDTH);
    }
    None => {
    println!("Error: Unable to add more rows.\nExiting");
    return ();
    }
    }
  • edit in src/bin/main.rs at line 88
    [6.73][6.449:450](),[6.191][6.449:450](),[6.208][6.449:450](),[6.637][6.449:450](),[6.742][6.449:450](),[6.1325][6.449:450](),[6.1355][6.449:450](),[6.449][6.449:450](),[6.450][5.869:885]()
    (floor, ms)
  • replacement in src/bin/main.rs at line 95
    [6.1452][5.943:992]()
    //let mut plank: Plank = Default::default();
    [6.1452]
    [5.992]
    //
  • edit in src/bin/main.rs at line 103
    [5.1216][5.1216:1328]()
    //} else {
    //println!("No more planks available!");
    //plank = None;
    //}
  • edit in src/bin/main.rs at line 106
    [6.787][2.0:64]()
    // Check if the plank is too short, then take a new one
  • edit in src/bin/main.rs at line 107
    [6.617]
    [6.3901]
    // Check if the plank is too short, then take a new one
    ms.discard_unusable(plank);
  • replacement in src/bin/main.rs at line 110
    [6.3946][6.3946:4030]()
    let newplank: Plank = Default::default();
    plank = newplank;
    [6.3946]
    [6.299]
    plank = ms.try_get_used()?;
  • replacement in src/bin/main.rs at line 122
    [6.1889][6.1889:1969]()
    // Set the leftover as the new plank
    plank = leftover;
    [6.1889]
    [6.4288]
    // Add the remaining plank to material storage
    ms.store_used(leftover);
  • replacement in src/bin/main.rs at line 132
    [6.4610][6.4610:4664]()
    let newplank: Plank = Default::default();
    [6.4610]
    [6.335]
    plank = ms.try_get_used()?;
  • edit in src/bin/main.rs at line 134
    [6.370][6.4664:4694](),[6.4664][6.4664:4694]()
    plank = newplank;
  • replacement in src/bin/main.rs at line 142
    [6.4949][6.4949:5003]()
    let newplank: Plank = Default::default();
    [6.4949]
    [6.371]
    plank = ms.try_get_used()?;
  • edit in src/bin/main.rs at line 144
    [6.406][6.5003:5033](),[6.5003][6.5003:5033]()
    plank = newplank;
  • edit in src/bin/main.rs at line 145
    [6.1979][6.788:827]()
    //println!("Row: {:#?}", row);
  • edit in src/bin/main.rs at line 148
    [6.5119]
    [6.5119]
    // Set first and last planks as endpieces
    row.set_first_and_last_as_endpieces();
  • replacement in src/bin/main.rs at line 151
    [6.5120][6.5120:5185](),[6.5185][6.1524:1580](),[6.1580][6.5237:5272](),[6.5237][6.5237:5272](),[6.5272][6.1581:1636](),[6.1636][6.5323:5358](),[6.5323][6.5323:5358]()
    // Annotate the planks in the beginning and end as endpieces
    if let Some(plank) = row.planks_mut().first_mut() {
    plank.set_endpiece()
    }
    if let Some(plank) = row.planks_mut().last_mut() {
    plank.set_endpiece()
    }
    [6.5120]
    [6.5358]
    //println!("Row: {:#?}", row);
  • file addition: constants.rs (----------)
    [6.487]
    /// The length of a new plank
    pub static PLANKMAX: u32 = 2200;
    /// The smallest allowable plank length
    pub static PLANKMIN: u32 = 200;
    /// Width of a plank
    pub static PLANKWIDTH: u32 = 185;
    /// Amount of desired play between end planks
    /// and the wallss
    pub static PLAY: u32 = 5;
    /// Size of the sawblade, how much material is lost
    pub static SAWBLADE: u32 = 10;
    /// Length of the room
    pub static ROOMLENGTH: u32 = 4760;
    /// Depth of the room
    pub static ROOMDEPTH: u32 = 2800;
    /// How many planks are available?
    pub static AVAILABLEPLANKS: u32 = 30;
  • file move: floor.rs (----------)lib.rs (----------)
    [6.487]
    [6.1]
  • replacement in src/lib.rs at line 2
    [6.35][6.35:56](),[6.56][6.0:21](),[6.21][6.56:77](),[6.56][6.56:77](),[6.77][4.0:28]()
    use crate::PLANKMAX;
    use crate::PLANKMIN;
    use crate::SAWBLADE;
    use crate::AVAILABLEPLANKS;
    [6.35]
    [6.77]
    pub mod constants;
    use constants::{PLANKMAX, PLANKMIN, SAWBLADE, AVAILABLEPLANKS};
  • replacement in src/lib.rs at line 8
    [4.58][4.58:172]()
    total_planks: u32,
    planks_new: Vec<Plank>,
    planks_used: Vec<Plank>,
    planks_too_short: Vec<Plank>,
    [4.58]
    [4.172]
    pub total_planks: u32,
    pub planks_new: Vec<Plank>,
    pub planks_used: Vec<Plank>,
    pub planks_too_short: Vec<Plank>,
  • edit in src/lib.rs at line 36
    [4.824]
    [4.824]
    }
    /// Store a used plank
    pub fn store_used(&mut self, plank: Plank) {
    self.planks_used.push(plank)
  • edit in src/lib.rs at line 41
    [4.830]
    [4.830]
    /// Try get a used plank, fallback by getting a new
    pub fn try_get_used(&mut self) -> Option<Plank> {
    if let Some(plank) = self.planks_used.pop() {
    Some(plank)
    } else {
    self.planks_new.pop()
    }
    }
  • edit in src/lib.rs at line 60
    [4.1175]
    [4.1175]
    }
    /// Put a too short plank aside
    pub fn discard_unusable(&mut self, plank: Plank) {
    self.planks_too_short.push(plank)
  • edit in src/lib.rs at line 174
    [6.2205]
    [3.0]
    pub fn set_first_and_last_as_endpieces(&mut self) -> () {
    // #TODO Remove unwrap
    self.planks.first_mut().unwrap().set_endpiece();
    self.planks.last_mut().unwrap().set_endpiece();
    }