common: add test for matrix inverse

This commit is contained in:
Eric Wasylishen 2017-04-23 16:08:58 -06:00
parent 8a4d1ff218
commit efd48b48f5
1 changed files with 44 additions and 0 deletions

View File

@ -867,3 +867,47 @@ TEST(mathlib, octree_basic) {
EXPECT_EQ(objsTouchingObj_i, objsTouchingObj_i_octree);
}
}
TEST(qvec, matrix2x2inv) {
std::mt19937 engine(0);
std::uniform_real_distribution<float> dis(-4096, 4096);
qmat2x2f randMat;
for (int i=0; i<2; i++)
for (int j=0; j<2; j++)
randMat[i][j] = dis(engine);
bool ok;
qmat2x2f randInv = qv::invert(randMat, &ok);
ASSERT_TRUE(ok);
qmat2x2f prod = randMat * randInv;
for (int i=0; i<2; i++) {
for (int j=0; j<2; j++) {
float exp = (i == j) ? 1.0f : 0.0f;
ASSERT_TRUE(fabs(exp - prod[i][j]) < 0.001);
}
}
}
TEST(qvec, matrix4x4inv) {
std::mt19937 engine(0);
std::uniform_real_distribution<float> dis(-4096, 4096);
qmat4x4f randMat;
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
randMat[i][j] = dis(engine);
bool ok;
qmat4x4f randInv = qv::invert(randMat, &ok);
ASSERT_TRUE(ok);
qmat4x4f prod = randMat * randInv;
for (int i=0; i<4; i++) {
for (int j=0; j<4; j++) {
float exp = (i == j) ? 1.0f : 0.0f;
ASSERT_TRUE(fabs(exp - prod[i][j]) < 0.001);
}
}
}