Use floor print as Display for Floor, add Row, Plank impls too

AfoHT
Jan 26, 2024, 10:56 PM
YCLKR3RZLNY4LPVNMIQM2IOQCJKMAJBM5QUBPLVWSWFK5VZDIGKQC

Dependencies

  • [2] VDT54RTY Print cut coordinates too
  • [3] E6F2AEXP Fix floorbuilding
  • [4] 6ODVKCN4 Fix printouts of relative lengths
  • [5] ZP2CTPQI Delete debug printout
  • [6] RQRFFUF6 Can build the first basic row
  • [7] 6Z5FXY2J Print includes play on each side
  • [8] 5TH3AA46 10 mm extra space
  • [9] OK5CKW6E Rework everything, use references
  • [10] F3GMCMWT Merge branch 'master' into sovrum
  • [11] Y4AQJ5RD Other defaults
  • [12] JBGHRTSW Use the new defaults
  • [13] VSG6UWDY Can now build floors
  • [14] ES2PMPT4 Using structures instead
  • [15] C5VVJ5SO Print how many rows
  • [16] USO5PZWO Start with the print function, separate mutable and immutable functions
  • [17] SMYRM2CF Use the MaterialStorage
  • [18] MLUGR2LL Add default impl and some basic plank logic
  • [19] JPTYS433 Cleanup, clippy
  • [20] BPPZAX3G Cleanup debug printouts
  • [21] 4IFBDTVW Store and print row total length
  • [22] OWEKMGGT Rework printout to use double rows
  • [23] 3H2BGWRG WIP
  • [24] 2USDM5CH WIP for more generic
  • [25] XSS4V63L Change scale factor wider for more detail
  • [*] ZJPL7VNQ Separate planks from main

Change contents

  • edit in src/lib.rs at line 104
    [27.398]
    [27.398]
    }
    }
    impl Display for Plank {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "{}", self.length)
  • edit in src/lib.rs at line 112
    [27.406]
    [27.406]
  • edit in src/lib.rs at line 193
    [27.1993]
    [27.1993]
    impl Display for Row {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    for plank in &self.planks {
    write!(f, "{plank} ")?;
    }
    Ok(())
    }
    }
  • edit in src/lib.rs at line 378
    [3.628]
    [27.3496]
    }
    }
    impl Display for Floor {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    let scalefactor = 50;
    for (num, row) in self.rows().iter().enumerate() {
    // Try to compensate for the extra size taken by
    // the number printout
    let comp = 50 * row.planks_count();
    let mut length_sum = 0;
    write!(f, " ")?; // Prefix space for play
    for plank in row.planks().iter() {
    length_sum += plank.length;
    write!(f, "|")?;
    // Print the relative length of the plank
    for _ in 0..((plank.length()) / scalefactor) {
    write!(f, "-")?;
    }
    }
    write!(f, "|")?;
    write!(f, " Cut coordinates: ")?;
    for cut in row.get_cut_coordinates() {
    write!(f, " {cut: ^6}, ")?;
    }
    writeln!(f)?;
    write!(f, "+{PLAY}")?;
    for plank in row.planks().iter() {
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
    write!(f, " ")?;
    }
    // Print the numeric length
    write!(f, "{: ^6}", plank.length())?;
    // Remainder of the plank
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
    write!(f, " ")?;
    }
    }
    write!(f, "+{PLAY}")?;
    writeln!(f, "\t Row length: {length_sum}\trow: {:#?}", num + 1)?;
    write!(f, " ")?; // Prefix space for play
    for plank in row.planks().iter() {
    write!(f, "|")?;
    // Print the bottom row of the plank
    for _ in 0..(plank.length() / scalefactor) {
    write!(f, "-")?;
    }
    }
    writeln!(f, "|")?;
    writeln!(f)?;
    }
    Ok(())
  • edit in src/bin/main.rs at line 27
    [3.280][3.296:297](),[3.474][3.296:297](),[3.501][3.296:297](),[3.529][3.296:297](),[3.1158][3.296:297](),[3.296][3.296:297](),[3.297][3.530:560](),[3.560][3.558:631](),[3.573][3.558:631](),[3.298][3.1250:1252](),[3.610][3.1250:1252](),[3.631][3.1250:1252](),[3.645][3.1250:1252](),[3.1250][3.1250:1252](),[3.637][3.637:638](),[3.638][3.265:319](),[3.319][3.0:26](),[3.26][3.700:757](),[3.26][3.700:757](),[3.698][3.700:757](),[3.769][3.700:757](),[3.700][3.700:757](),[3.757][3.699:787](),[3.787][3.27:71](),[3.71][3.0:32](),[3.855][3.0:32](),[3.32][3.72:120](),[3.27][3.720:763](),[3.32][3.720:763](),[3.120][3.720:763](),[3.312][3.720:763](),[3.839][3.720:763](),[3.855][3.720:763](),[3.720][3.720:763](),[3.763][3.33:73](),[3.73][3.0:0](),[3.763][3.0:0](),[3.0][3.313:338](),[3.887][3.313:338](),[3.338][3.936:937](),[3.936][3.936:937](),[3.937][3.121:234](),[3.234][3.456:499](),[3.926][3.456:499](),[3.456][3.456:499](),[3.499][3.235:245](),[3.245][2.0:172](),[2.172][3.808:809](),[3.268][3.808:809](),[3.499][3.808:809](),[3.1045][3.808:809](),[3.808][3.808:809](),[3.809][3.269:452](),[3.452][3.500:540](),[3.809][3.500:540](),[3.540][3.453:499](),[3.499][3.809:810](),[3.586][3.809:810](),[3.973][3.809:810](),[3.809][3.809:810](),[3.810][3.500:538](),[3.538][3.974:1044](),[3.648][3.974:1044](),[3.1044][3.539:568](),[3.568][3.1378:1392](),[3.735][3.1378:1392](),[3.1378][3.1378:1392](),[3.761][3.1415:1425](),[3.1415][3.1415:1425]()
    floor_print(&floor, &ms);
    println!("Number of leftover cut planks: {}", ms.get_used_count());
    }
    fn floor_print(floor: &Floor, ms: &MaterialStorage) {
    let scalefactor = 50;
    for (num, row) in floor.rows().iter().enumerate() {
    // Try to compensate for the extra size taken by
    // the number printout
    let comp = 50 * row.planks_count();
    let mut length_sum = 0;
    print!(" "); // Prefix space for play
    for plank in row.planks().iter() {
    length_sum += plank.length;
    print!("|");
    // Print the relative length of the plank
    for _ in 0..((plank.length()) / scalefactor) {
    print!("-");
    }
    }
    print!("|");
    print!(" Cut coordinates: ");
    for cut in row.get_cut_coordinates() {
    print!(" {cut: ^6}, ");
    }
    println!();
    print!("+{PLAY}");
    for plank in row.planks().iter() {
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
    print!(" ");
    }
    // Print the numeric length
    print!("{: ^6}", plank.length());
    // Remainder of the plank
    for _ in 0..((plank.length() - comp) / scalefactor) / 2 {
    print!(" ");
    }
    }
  • replacement in src/bin/main.rs at line 28
    [3.570][3.28:55](),[3.1112][3.28:55](),[3.55][3.74:144](),[3.1112][3.74:144](),[3.144][3.571:890](),[3.144][3.1425:1447](),[3.890][3.1425:1447](),[3.1087][3.1425:1447](),[3.1157][3.1425:1447](),[3.1425][3.1425:1447]()
    print!("+{PLAY}");
    println!("\t Row length: {length_sum}\trow: {:#?}", num + 1);
    print!(" "); // Prefix space for play
    for plank in row.planks().iter() {
    print!("|");
    // Print the bottom row of the plank
    for _ in 0..(plank.length() / scalefactor) {
    print!("-");
    }
    }
    println!("|");
    println!();
    }
    println!();
    [3.570]
    [3.1447]
    println!("{floor}");
  • edit in src/bin/main.rs at line 35
    [3.1273]
    [3.1476]
    println!("Number of leftover cut planks: {}", ms.get_used_count());