Add default impl and some basic plank logic

[?]
Jul 11, 2020, 7:24 PM
MLUGR2LLRTENFPCXBML4VQKWNE5QURMC7RJDE3AQYZXAJWOWILDQC

Dependencies

Change contents

  • replacement in src/main.rs at line 4
    [3.82][3.82:113]()
    static ROOMLENGTH: u32 = 3800;
    [3.82]
    [3.113]
    //static ROOMLENGTH: u32 = 3800;
    static ROOMLENGTH: u32 = 1000;
  • edit in src/main.rs at line 14
    [3.283]
    [2.35]
    new: bool,
  • edit in src/main.rs at line 17
    [2.38]
    [2.38]
    impl Default for Plank {
    /// Create a new, default plank
    fn default() -> Self {
    Self {
    length: PLANKMAX,
    endpiece: false,
    new: true,
    }
    }
    }
    impl Plank {
    /// Is this row considered complete?
    fn is_new(&self) -> bool {
    self.new
    }
    /// Get the number of plank rows for this floor
    fn is_endpiece(&self) -> bool {
    self.endpiece
    }
    fn cut_to_length(mut self, measure: u32) -> (Plank, Plank) {
    let leftover_plank = Plank {
    length: self.length - measure,
    endpiece: false,
    new: false,
    };
    // Trim self to the new length
    self.length = measure;
    // In case the plank was new, mark it as cut
    if self.new {
    self.new = false;
    }
    // Return the original plank and the leftover
    (self, leftover_plank)
    }
    }
  • edit in src/main.rs at line 59
    [2.118]
    [2.118]
    coverage: u32,
  • edit in src/main.rs at line 62
    [2.136]
    [2.136]
    impl Default for Row {
    /// Create a new, empty row
    fn default() -> Self {
    Self {
    planks: vec![],
    coverage: 0,
    full: false,
    }
    }
    }
  • edit in src/main.rs at line 91
    [2.529]
    [2.529]
    coverage: u32,
  • edit in src/main.rs at line 127
    [2.1070]
    [2.1070]
    coverage: 0,
  • edit in src/main.rs at line 132
    [2.1151]
    [2.1151]
    coverage: 0,
  • replacement in src/main.rs at line 141
    [2.1297][2.1297:1325]()
    floor.add(build_row());
    [2.1297]
    [3.449]
    while floor.coverage <= ROOMDEPTH {
    floor.add(build_row());
    }
  • replacement in src/main.rs at line 149
    [2.1363][2.1363:1418]()
    Row {
    planks: vec![],
    full: false,
    [2.1363]
    [2.1418]
    // New empty row
    let mut row: Row = Default::default();
    // Create an initial plank
    let mut plank: Plank = Default::default();
    //let mut leftover: Plank = Default::default();
    while row.coverage <= ROOMLENGTH {
    if plank.length > ROOMLENGTH {
    // Planks are longer than the room, need to cut them
    //let leftover;
    let (plankpart, leftover) = plank.cut_to_length(ROOMLENGTH);
    // Add the remainder of plank to the row (move)
    row.add(plankpart);
    // Set the leftover as the new plank
    plank = leftover;
    }
  • edit in src/main.rs at line 169
    [2.1424]
    [2.1424]
    row
  • edit in src/main.rs at line 171
    [2.1426][2.1426:1494]()
    fn calc_new_length(prev: u32, next: u32) -> u32 {
    prev - next
    }