From f20e1602d64b03397bc54425ff7f5be2e3214aff Mon Sep 17 00:00:00 2001 From: Owen Thompson Date: Mon, 30 Mar 2020 14:04:07 -0400 Subject: [PATCH] Implementation of operator << on Matrix22 for stream output. Signed-off-by: Owen Thompson --- IlmBase/Imath/ImathMatrix.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/IlmBase/Imath/ImathMatrix.h b/IlmBase/Imath/ImathMatrix.h index d458d4fcf8..0c74404156 100644 --- a/IlmBase/Imath/ImathMatrix.h +++ b/IlmBase/Imath/ImathMatrix.h @@ -4076,6 +4076,35 @@ Matrix44::shear (const Shear6 &h) // Implementation of stream output //-------------------------------- +template +std::ostream & +operator << (std::ostream &s, const Matrix22 &m) +{ + std::ios_base::fmtflags oldFlags = s.flags(); + int width; + + if (s.flags() & std::ios_base::fixed) + { + s.setf (std::ios_base::showpoint); + width = static_cast(s.precision()) + 5; + } + else + { + s.setf (std::ios_base::scientific); + s.setf (std::ios_base::showpoint); + width = static_cast(s.precision()) + 8; + } + + s << "(" << std::setw (width) << m[0][0] << + " " << std::setw (width) << m[0][1] << "\n" << + + " " << std::setw (width) << m[1][0] << + " " << std::setw (width) << m[1][1] << ")\n"; + + s.flags (oldFlags); + return s; +} + template std::ostream & operator << (std::ostream &s, const Matrix33 &m)