From f85243e8923bc5581051713bab618fd0016a332e Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 19 Mar 2025 00:56:39 +0300 Subject: [PATCH] improved print method --- include/omath/Mat.hpp | 12 +++++++++--- tests/general/UnitTestMat.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/omath/Mat.hpp b/include/omath/Mat.hpp index 17964cf..864ad58 100644 --- a/include/omath/Mat.hpp +++ b/include/omath/Mat.hpp @@ -8,6 +8,7 @@ #include #include #include "Vector3.hpp" +#include namespace omath { @@ -296,15 +297,20 @@ namespace omath std::string ToString() const noexcept { std::ostringstream oss; + oss << "[["; + for (size_t i = 0; i < Rows; ++i) { + if (i > 0) + oss << " ["; + for (size_t j = 0; j < Columns; ++j) { - oss << At(i, j); + oss << std::setw(9) << std::fixed << std::setprecision(3) << At(i, j); if (j != Columns - 1) - oss << ' '; + oss << ", "; } - oss << '\n'; + oss << (i == Rows - 1 ? "]]" : "]\n"); } return oss.str(); } diff --git a/tests/general/UnitTestMat.cpp b/tests/general/UnitTestMat.cpp index cdaecfc..710a2a2 100644 --- a/tests/general/UnitTestMat.cpp +++ b/tests/general/UnitTestMat.cpp @@ -127,7 +127,7 @@ TEST_F(UnitTestMat, ToString) { const std::string str = m2.ToString(); EXPECT_FALSE(str.empty()); - EXPECT_EQ(str, "1 2\n3 4\n"); + EXPECT_EQ(str, "[[ 1.000, 2.000]\n [ 3.000, 4.000]]"); } // Test assignment operators