From ca9fc67ccf7899244ba484c9c99a55985f1f36ac Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 3 Oct 2024 21:48:56 +0200 Subject: Better printing --- libpsi-core/src/maths/vector.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'libpsi-core/src/maths/vector.rs') diff --git a/libpsi-core/src/maths/vector.rs b/libpsi-core/src/maths/vector.rs index 07ff7fb..f424e4e 100644 --- a/libpsi-core/src/maths/vector.rs +++ b/libpsi-core/src/maths/vector.rs @@ -256,13 +256,25 @@ impl fmt::Display for RowVector { impl fmt::Display for ColumnVector { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "[")?; + let max_width = self + .0 + .iter() + .map(|x| format!("{:.2}", x).split('.').next().unwrap().len()) // Length of integer part + .max() + .unwrap_or(0); + for (i, x) in self.0.iter().enumerate() { - if i > 0 { - write!(f, ",\n ")?; + let formatted_x = format!("{:>width$.2}", x, width = max_width + 3); // +3 for ".00" + + if i == 0 { + write!(f, "┌{}┐\n", formatted_x)?; + } else if i == self.0.len() - 1 { + write!(f, "└{}┘\n", formatted_x)?; + } else { + write!(f, "│{}│\n", formatted_x)?; } - write!(f, "{}", x)?; } - write!(f, "]") + + Ok(()) } } -- cgit v1.3