Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add unit test for Matrix4::translateBy()
  • Loading branch information
Matthew Mott committed Mar 31, 2021
1 parent 8418aa4 commit 0a71ad4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/math/Matrix4.cpp
Expand Up @@ -494,4 +494,29 @@ TEST(MathTest, MatrixFullInverse)
EXPECT_DOUBLE_EQ(inv.tw(), 0.3571428571428571) << "Matrix inversion failed on tw";
}

TEST(MathTest, MatrixTranslateBy)
{
const Vector3 TRANS(27, -16, 0.84);

// Add a translation to a matrix which already includes a transformation
const Vector3 SCALE(2, 3, 2);
Matrix4 m = Matrix4::getScale(SCALE);
m.translateBy(TRANS);

// Because translateBy() does a post-multiplication, the scale will affect
// the translation
EXPECT_EQ(m.translation(), SCALE*TRANS /* Componentwise product */);
EXPECT_EQ(m, Matrix4::byRows(2, 0, 0, SCALE.x() * TRANS.x(),
0, 3, 0, SCALE.y() * TRANS.y(),
0, 0, 2, SCALE.z() * TRANS.z(),
0, 0, 0, 1));

// Add further translations and ensure the result is cumulative
const Vector3 ONE(1, 1, 1);
m.translateBy(ONE);
expectNear(m.translation(), SCALE * (TRANS+ONE));
m.translateBy(-TRANS);
expectNear(m.translation(), SCALE * ONE);
}

}

0 comments on commit 0a71ad4

Please sign in to comment.