added operator<<(std::ostream, Matrix) to util/Matrix

git-svn-id: svn://anubis/fart/trunk@15 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-01-20 03:46:11 +00:00
parent 160d6998d6
commit 746b17227c
2 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#include "Matrix.h"
#include <math.h> /* fabs() */
#include <iostream>
#include <iomanip> /* setprecision() */
#define FP_EQ(x,y) (fabs((x)-(y)) < 0.00001)
@ -209,3 +211,21 @@ bool operator==(const Matrix & m1, const Matrix & m2)
}
return true;
}
std::ostream & operator<<(std::ostream & out, const Matrix & m)
{
out << std::setprecision(3);
for (int i = 0; i < 4; i++)
{
out << (i == 0 ? "[ " : " ");
out << "[ ";
for (int j = 0; j < 4; j++)
{
out << m[i][j];
if (j < 3)
out << ", ";
}
out << "]" << std::endl;
}
return out;
}

View File

@ -3,6 +3,7 @@
#define MATRIX_H MATRIX_H
#include "Vector.h"
#include <iostream>
class Matrix
{
@ -25,6 +26,7 @@ class Matrix
Matrix operator*(const Matrix & m1, const Matrix & m2);
Vector operator*(const Matrix & m, const Vector & v);
bool operator==(const Matrix & m1, const Matrix & m2);
std::ostream & operator<<(std::ostream & out, const Matrix & m);
#endif