Make Floor use Display of Row

AfoHT
Jan 26, 2024, 11:11 PM
XUH37MABSKSSD4TOXWYX7AWFST4VYOTQGYQHJPQLOG4Y3OPJO7MQC

Dependencies

  • [2] YCLKR3RZ Use floor print as Display for Floor, add Row, Plank impls too
  • [3] VSG6UWDY Can now build floors
  • [4] ZJPL7VNQ Separate planks from main
  • [5] JPTYS433 Cleanup, clippy

Change contents

  • replacement in src/lib.rs at line 195
    [2.243][2.243:315]()
    for plank in &self.planks {
    write!(f, "{plank} ")?;
    [2.243]
    [2.315]
    let scalefactor = 50;
    // Try to compensate for the extra size taken by
    // the number printout
    let comp = 50 * self.planks_count();
    let mut length_sum = 0;
    write!(f, " ")?; // Prefix space for play
    for plank in self.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 self.get_cut_coordinates() {
    write!(f, " {cut: ^6}, ")?;
    }
    writeln!(f)?;
    write!(f, "+{PLAY}")?;
    for plank in self.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}")?;
    write!(f, " ")?; // Prefix space for play
    for plank in self.planks().iter() {
    write!(f, "|")?;
    // Print the bottom self of the plank
    for _ in 0..(plank.length() / scalefactor) {
    write!(f, "-")?;
    }
  • replacement in src/lib.rs at line 242
    [2.325][2.325:340]()
    Ok(())
    [2.325]
    [2.340]
    writeln!(f, "|")
  • edit in src/lib.rs at line 374
    [3.3157]
    [3.3157]
    }
    }
    }
    impl Display for Floor {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    for (num, row) in self.rows().iter().enumerate() {
    writeln!(f, "Row: {:#?}", num + 1)?;
    writeln!(f, "{row}")?;
  • edit in src/lib.rs at line 384
    [3.3167]
    [3.3167]
    Ok(())
  • edit in src/lib.rs at line 434
    [2.358][2.358:2320](),[3.628][3.3496:3504](),[2.2320][3.3496:3504](),[3.3496][3.3496:3504]()
    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(())
    }
    }