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(())
}
}