Rework everything, use references
[?]
Apr 2, 2021, 4:42 PM
OK5CKW6E72XAZTRJUWSKFPJBPZYNIWQGVXFR5ARSJHB6EIBMU6WQCDependencies
- [2]
AATEG4HIRemove todo, improve comment - [3]
DBIA6R5XFix get_plank() - [4]
B75B3UUKCreate a MaterialStorage - [5]
SMYRM2CFUse the MaterialStorage - [6]
CT3VONTOIntroduce PLANKMIN and work with the neverending rows - [7]
Y4AQJ5RDOther defaults - [8]
5TH3AA4610 mm extra space - [9]
ES2PMPT4Using structures instead - [10]
ZJPL7VNQSeparate planks from main - [11]
F3GMCMWTMerge branch 'master' into sovrum - [12]
RQRFFUF6Can build the first basic row - [13]
UPCMFGXFPrint more about the room and define PLAY - [14]
USO5PZWOStart with the print function, separate mutable and immutable functions - [15]
MLUGR2LLAdd default impl and some basic plank logic - [16]
JBGHRTSWUse the new defaults - [17]
NRQSXJVRInitial commit - [18]
3H2BGWRGWIP - [19]
VSG6UWDYCan now build floors - [20]
6ODVKCN4Fix printouts of relative lengths - [21]
C5VVJ5SOPrint how many rows - [22]
U4JRHEA7fmt - [23]
2USDM5CHWIP for more generic
Change contents
- file addition: bin[6.487]
- file move: main.rs → main.rs
- 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 plankstatic PLANKMAX: u32 = 2200;//static PLANKMAX: u32 = 1900;/// The smallest allowable plank lengthstatic 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;use parkett::constants::{PLANKMAX, PLANKMIN, PLANKWIDTH, PLAY, ROOMDEPTH, ROOMLENGTH, SAWBLADE,};use parkett::{Floor, MaterialStorage, Row}; - edit in src/bin/main.rs at line 8
// How many planks are available?// Add ability to add "used"/pre-cut planksstatic AVAILABLEPLANKS: u32 = 10; - replacement in src/bin/main.rs at line 19
// Create a pool of planks, modify the constant AVAILABLEPLANKS// to the total number of full length available plankslet ms = MaterialStorage::default();// Create a pool of planks// To change, modify constants.rslet mut ms = MaterialStorage::default();//println!("MS: {:#?}", ms); - replacement in src/bin/main.rs at line 24
let floor: Floor = Floor::default();// Create an empty "room", floor with no plankslet mut floor: Floor = Floor::default(); - replacement in src/bin/main.rs at line 27
//println!("Material storage:\n {:#?}", ms);floor_build(&mut floor, &mut ms);//println!("Floor: {:#?}", finished_floor); - replacement in src/bin/main.rs at line 30
let (finished_floor, ms) = floor_build(floor, ms);//println!("Floor: {:#?}", finished_floor);floor_print(&finished_floor);floor_print(&floor, &ms); - edit in src/bin/main.rs at line 33
//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
let mut plank_count_sum = 0;fn floor_print(floor: &Floor, ms: &MaterialStorage) -> () {let scalefactor = 100; - replacement in src/bin/main.rs at line 40
plank_count_sum += row.planks_count();// 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
for _ in 0..(plank.length() / printmax) / 2 {for _ in 0..((plank.length() - comp) / scalefactor) / 2 { - replacement in src/bin/main.rs at line 54
print!("{:-^5}", plank.length());print!("{:-^8}", plank.length()); - replacement in src/bin/main.rs at line 57
for _ in 0..(plank.length() / printmax) / 2 {for _ in 0..((plank.length() - comp) / scalefactor) / 2 { - edit in src/bin/main.rs at line 60
print!("|"); - replacement in src/bin/main.rs at line 61
println!("row: {:#?}", num + 1);// Print the end of the row of planksprint!("|");println!("\t\trow: {:#?}", num + 1); - replacement in src/bin/main.rs at line 68
println!("Number of planks required: {}", plank_count_sum);println!("Number of planks required: {}",ms.total_planks - ms.planks_new.len() as u32); - replacement in src/bin/main.rs at line 74
fn floor_build(mut floor: Floor, mut ms: MaterialStorage) -> (Floor, MaterialStorage) {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 unwrapfloor.add(build_row(&mut ms).unwrap());floor.add_coverage(PLANKWIDTH);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
//let mut plank: Plank = Default::default();// - edit in src/bin/main.rs at line 103
//} else {//println!("No more planks available!");//plank = None;//} - edit in src/bin/main.rs at line 106
// Check if the plank is too short, then take a new one - edit in src/bin/main.rs at line 107
// Check if the plank is too short, then take a new onems.discard_unusable(plank); - replacement in src/bin/main.rs at line 110
let newplank: Plank = Default::default();plank = newplank;plank = ms.try_get_used()?; - replacement in src/bin/main.rs at line 122
// Set the leftover as the new plankplank = leftover;// Add the remaining plank to material storagems.store_used(leftover); - replacement in src/bin/main.rs at line 132
let newplank: Plank = Default::default();plank = ms.try_get_used()?; - edit in src/bin/main.rs at line 134
plank = newplank; - replacement in src/bin/main.rs at line 142
let newplank: Plank = Default::default();plank = ms.try_get_used()?; - edit in src/bin/main.rs at line 144
plank = newplank; - edit in src/bin/main.rs at line 145
//println!("Row: {:#?}", row); - edit in src/bin/main.rs at line 148
// Set first and last planks as endpiecesrow.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 endpiecesif let Some(plank) = row.planks_mut().first_mut() {plank.set_endpiece()}if let Some(plank) = row.planks_mut().last_mut() {plank.set_endpiece()}//println!("Row: {:#?}", row); - file addition: constants.rs[6.487]
/// The length of a new plankpub static PLANKMAX: u32 = 2200;/// The smallest allowable plank lengthpub static PLANKMIN: u32 = 200;/// Width of a plankpub static PLANKWIDTH: u32 = 185;/// Amount of desired play between end planks/// and the wallsspub static PLAY: u32 = 5;/// Size of the sawblade, how much material is lostpub static SAWBLADE: u32 = 10;/// Length of the roompub static ROOMLENGTH: u32 = 4760;/// Depth of the roompub static ROOMDEPTH: u32 = 2800;/// How many planks are available?pub static AVAILABLEPLANKS: u32 = 30; - file move: floor.rs → lib.rs
- 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;pub mod constants;use constants::{PLANKMAX, PLANKMIN, SAWBLADE, AVAILABLEPLANKS}; - replacement in src/lib.rs at line 8
total_planks: u32,planks_new: Vec<Plank>,planks_used: Vec<Plank>,planks_too_short: Vec<Plank>,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
}/// Store a used plankpub fn store_used(&mut self, plank: Plank) {self.planks_used.push(plank) - edit in src/lib.rs at line 41
/// Try get a used plank, fallback by getting a newpub 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
}/// Put a too short plank asidepub fn discard_unusable(&mut self, plank: Plank) {self.planks_too_short.push(plank) - edit in src/lib.rs at line 174
pub fn set_first_and_last_as_endpieces(&mut self) -> () {// #TODO Remove unwrapself.planks.first_mut().unwrap().set_endpiece();self.planks.last_mut().unwrap().set_endpiece();}