From 10195c607cfb1a3110419e8f390c4a331de426ad Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 16 Aug 2014 16:57:58 -0700 Subject: [PATCH] operator<< for pretty-printing an entire Matrix4 --- src/basics/matrix.cc | 29 +++++++++++++++++++++++++++++ src/basics/matrix.hh | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/basics/matrix.cc b/src/basics/matrix.cc index bd95a71..598ff73 100644 --- a/src/basics/matrix.cc +++ b/src/basics/matrix.cc @@ -346,6 +346,35 @@ Inverse(Matrix4 m) } +/* + * charles::basics::operator<< -- + */ +std::ostream& +operator<<(std::ostream &ost, + const Matrix4 &m) +{ + ost << "["; + for (UInt i = 0; i < 4; i++) { + if (i != 0) { + ost << " "; + } + ost << "["; + for (UInt j = 0; j < 4; j++) { + ost << m(i,j); + if (j < 3) { + ost << " "; + } + } + ost << "]"; + if (i < 3) { + ost << "\n"; + } + } + ost << "]"; + return ost; +} + + } /* namespace mespace */ } /* namespace charles */ diff --git a/src/basics/matrix.hh b/src/basics/matrix.hh index 9a93164..bd434fa 100644 --- a/src/basics/matrix.hh +++ b/src/basics/matrix.hh @@ -93,13 +93,15 @@ protected: /** Scalar multiplication, scalar factor on the left. */ Matrix4 operator*(Double lhs, const Matrix4 &rhs); - /** Transpose the given matrix. */ Matrix4 Transpose(Matrix4 m); /** Invert the given matrix. */ Matrix4 Inverse(Matrix4 m); + +std::ostream& operator<<(std::ostream &ost, const Matrix4 &m); + } /* namespace basics */ } /* namespace charles */