Fix floorbuilding

AfoHT
Jan 21, 2024, 10:47 PM
E6F2AEXPQX2ST5SKAAUQ3KXOAHKXRJJZHYOYY3R7RNQRUGAJDCNAC

Dependencies

  • [2] XSS4V63L Change scale factor wider for more detail
  • [3] 4YYL4VTY Introduce Cut
  • [4] WT7LSRGI Each Row stores its maximum length
  • [5] JEHKAQUU Simplify by using match
  • [6] MLUGR2LL Add default impl and some basic plank logic
  • [7] SMYRM2CF Use the MaterialStorage
  • [8] LXMNVVD2 Change to proper measurements
  • [9] OK5CKW6E Rework everything, use references
  • [10] VSG6UWDY Can now build floors
  • [11] JPTYS433 Cleanup, clippy
  • [12] 5TH3AA46 10 mm extra space
  • [13] ES2PMPT4 Using structures instead
  • [14] ZJPL7VNQ Separate planks from main
  • [15] C5VVJ5SO Print how many rows
  • [16] AATEG4HI Remove todo, improve comment
  • [17] USO5PZWO Start with the print function, separate mutable and immutable functions
  • [18] Y4AQJ5RD Other defaults
  • [19] DUC7IKTF Pass in the previous row during building
  • [20] Q7IWKL57 Calculate required length once and reuse
  • [21] CT3VONTO Introduce PLANKMIN and work with the neverending rows

Change contents

  • replacement in src/lib.rs at line 210
    [6.2464][6.29:85](),[6.85][6.2157:2197](),[6.2197][6.131:162](),[6.131][6.131:162]()
    /// Increase the number of planks used for this row
    pub fn add_used_planks(&mut self) {
    self.planks_used += 1;
    [6.2464]
    [6.162]
    /// Return how many planks/pieces are in this row
    pub fn get_used_planks(&mut self) {
    self.planks.len();
  • replacement in src/lib.rs at line 216
    [6.2511][6.2198:2250]()
    pub fn add_coverage(&mut self, coverage: u32) {
    [6.2511]
    [6.2569]
    fn add_coverage(&mut self, coverage: u32) {
  • replacement in src/lib.rs at line 220
    [6.2611][6.2611:2663]()
    /// Get the number of plank rows for this floor
    [6.2611]
    [6.2663]
    /// Get the coverage so far of this row
  • edit in src/lib.rs at line 232
    [6.2293]
    [6.2811]
    // Add the new plank to coverage, coverage is
    // thus the coordinate from origin
    self.add_coverage(plank.length());
    // There is always a cut at the end of a row
    // only add Cut if less than this
    let coordinate = self.get_coverage();
    if coordinate < self.row_max_length {
    self.cut_coordinates.push(Cut::new(coordinate));
    }
  • replacement in src/lib.rs at line 246
    [3.418][3.418:463]()
    return self.cut_coordinates.clone();
    [3.418]
    [3.463]
    self.cut_coordinates.clone()
  • replacement in src/lib.rs at line 260
    [3.949][3.949:970]()
    return true;
    [3.949]
    [3.970]
    true
  • replacement in src/constants.rs at line 21
    [6.2504][6.2504:2539]()
    pub static ROOMLENGTH: u32 = 4760;
    [6.2504]
    [6.2539]
    // pub static ROOMLENGTH: u32 = 4760;
    pub static ROOMLENGTH: u32 = 2220;
  • replacement in src/bin/main.rs at line 34
    [6.319][2.0:26]()
    let scalefactor = 50;
    [6.319]
    [6.700]
    let scalefactor = 100;
  • replacement in src/bin/main.rs at line 97
    [6.1452][6.1647:1654](),[6.1654][6.992:1095](),[6.992][6.992:1095](),[6.1095][5.0:110]()
    //
    // Check if some started plank is available
    // otherwise grab a new plank from MaterialStorage
    let mut plank = match ms.get_used() {
    Some(plank) => plank,
    None => ms.get_new()?,
    };
    [6.1452]
    [6.1551]
    let mut plank;
  • replacement in src/bin/main.rs at line 100
    [6.64][6.578:617](),[4.251][6.578:617](),[6.3867][6.578:617](),[6.617][6.1655:1763](),[6.617][6.3901:3946](),[6.1763][6.3901:3946](),[6.3901][6.3901:3946](),[6.3946][6.1764:1804](),[6.1804][6.299:334](),[6.4030][6.299:334](),[6.334][6.4030:4040](),[6.657][6.4030:4040](),[6.4030][6.4030:4040]()
    if plank.length() < PLANKMIN {
    // Check if the plank is too short, then take a new one
    ms.discard_unusable(plank);
    // Take a new plank and continue
    plank = ms.try_get_used()?;
    row.add_used_planks();
    }
    [4.251]
    [3.1113]
    // Get a plank, used or new, and continue
    plank = ms.try_get_used()?;
  • edit in src/bin/main.rs at line 116
    [3.1744]
    [6.412]
  • edit in src/bin/main.rs at line 118
    [6.443]
    [4.252]
    length if length < PLANKMIN => {
    // Check if the plank is too short, then take a new one
    ms.discard_unusable(plank);
    }
  • edit in src/bin/main.rs at line 127
    [6.719][6.719:823]()
    // also increase the row coverage
    row.add_coverage(plankpart.length());
  • replacement in src/bin/main.rs at line 134
    [6.4434][6.1128:1238]()
    // Use the whole plank, add to row coverage
    row.add_coverage(plank.length());
    [6.4434]
    [6.1238]
    // Use the whole plank
  • edit in src/bin/main.rs at line 136
    [6.1270][6.4564:4565](),[6.4564][6.4564:4565](),[6.4565][6.1271:1403]()
    // Take a new plank and continue
    plank = ms.try_get_used()?;
    row.add_used_planks();
  • replacement in src/bin/main.rs at line 140
    [6.4773][6.1502:1612]()
    // Use the whole plank, add to row coverage
    row.add_coverage(plank.length());
    [6.4773]
    [6.1612]
    // Use the whole plank
  • edit in src/bin/main.rs at line 142
    [6.1644][6.4903:4904](),[6.4903][6.4903:4904](),[6.4904][6.1645:1777]()
    // Take a new plank and continue
    plank = ms.try_get_used()?;
    row.add_used_planks();