aboutsummaryrefslogtreecommitdiff
path: root/libpsi-core/src/maths/vector.rs
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2024-10-03 21:48:56 +0200
committerhachem <im@hachem.wtf>2024-10-03 21:48:56 +0200
commitca9fc67ccf7899244ba484c9c99a55985f1f36ac (patch)
tree8e11a7eea1581084585aad43e48c036ef571a191 /libpsi-core/src/maths/vector.rs
parentd442a1159d9d29e70e7f80eccf4902655a0df8f4 (diff)
Better printing
Diffstat (limited to 'libpsi-core/src/maths/vector.rs')
-rw-r--r--libpsi-core/src/maths/vector.rs22
1 files changed, 17 insertions, 5 deletions
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<T: Float + fmt::Display> fmt::Display for RowVector<T> {
impl<T: Float + fmt::Display> fmt::Display for ColumnVector<T> {
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(())
}
}