mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
improved print method
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -296,15 +297,20 @@ namespace omath
|
|||||||
std::string ToString() const noexcept
|
std::string ToString() const noexcept
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
oss << "[[";
|
||||||
|
|
||||||
for (size_t i = 0; i < Rows; ++i)
|
for (size_t i = 0; i < Rows; ++i)
|
||||||
{
|
{
|
||||||
|
if (i > 0)
|
||||||
|
oss << " [";
|
||||||
|
|
||||||
for (size_t j = 0; j < Columns; ++j)
|
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)
|
if (j != Columns - 1)
|
||||||
oss << ' ';
|
oss << ", ";
|
||||||
}
|
}
|
||||||
oss << '\n';
|
oss << (i == Rows - 1 ? "]]" : "]\n");
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ TEST_F(UnitTestMat, ToString)
|
|||||||
{
|
{
|
||||||
const std::string str = m2.ToString();
|
const std::string str = m2.ToString();
|
||||||
EXPECT_FALSE(str.empty());
|
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
|
// Test assignment operators
|
||||||
|
|||||||
Reference in New Issue
Block a user