Add default impl and some basic plank logic
[?]
Jul 11, 2020, 7:24 PM
MLUGR2LLRTENFPCXBML4VQKWNE5QURMC7RJDE3AQYZXAJWOWILDQCDependencies
- [2]
ES2PMPT4Using structures instead - [3]
2USDM5CHWIP for more generic - [4]
5TH3AA4610 mm extra space
Change contents
- replacement in src/main.rs at line 4
static ROOMLENGTH: u32 = 3800;//static ROOMLENGTH: u32 = 3800;static ROOMLENGTH: u32 = 1000; - edit in src/main.rs at line 14
new: bool, - edit in src/main.rs at line 17
impl Default for Plank {/// Create a new, default plankfn 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 floorfn 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 lengthself.length = measure;// In case the plank was new, mark it as cutif self.new {self.new = false;}// Return the original plank and the leftover(self, leftover_plank)}} - edit in src/main.rs at line 59
coverage: u32, - edit in src/main.rs at line 62
impl Default for Row {/// Create a new, empty rowfn default() -> Self {Self {planks: vec![],coverage: 0,full: false,}}} - edit in src/main.rs at line 91
coverage: u32, - edit in src/main.rs at line 127
coverage: 0, - edit in src/main.rs at line 132
coverage: 0, - replacement in src/main.rs at line 141
floor.add(build_row());while floor.coverage <= ROOMDEPTH {floor.add(build_row());} - replacement in src/main.rs at line 149
Row {planks: vec![],full: false,// New empty rowlet mut row: Row = Default::default();// Create an initial planklet 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 plankplank = leftover;} - edit in src/main.rs at line 169
row - edit in src/main.rs at line 171
fn calc_new_length(prev: u32, next: u32) -> u32 {prev - next}