summaryrefslogtreecommitdiffstats
path: root/cc/math_util_unittest.cc
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-26 20:13:08 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-26 20:13:08 +0000
commitf7c321eb19e1dd8a2f8b154cacb7e13788f1fc28 (patch)
treee1f1c285d359f728fd9d270267b881a836dbea0e /cc/math_util_unittest.cc
parenteb052c93fa488df29314bcb70bb2458982fc94c8 (diff)
downloadchromium_src-f7c321eb19e1dd8a2f8b154cacb7e13788f1fc28.zip
chromium_src-f7c321eb19e1dd8a2f8b154cacb7e13788f1fc28.tar.gz
chromium_src-f7c321eb19e1dd8a2f8b154cacb7e13788f1fc28.tar.bz2
gfx::Transform API clean-up
We have too many ways to do the same thing in gfx::Transform, and their names can lead to confusion. We have the notion of Concat-ing and Preconcat-ing. We've borrowed this verbage from skia. a.preConcat(b) means a = a * b. This may seem counter-intuitive, but is the correct definition if we are multiplying our points/vectors on the right. That said, we almost always want to pre-concat. This what is done throughout WebKit. To simplify matters, rather than having ConcatFoo and PreconcatFoo, we will now only have Foo which does what PreconcatFoo used to. Furthermore, we also have SetFoo which is almost always used immediately after a transform is created, so Foo would do fine (with the optimization mentioned below). Another bit of redundant code eliminated by this CL is InterpolatedTransform::FactorTRS. This function was brittle and naive, and now that gfx::Transform::Blend exists, it needs to go away. Other minor changes rolled into this cleanup: - RotateAbout now takes the newly minted Vector3dF - The Foo functions mentioned above also check for identity to avoid needless matrix multiplications. BUG=159972 Review URL: https://chromiumcodereview.appspot.com/11418040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/math_util_unittest.cc')
-rw-r--r--cc/math_util_unittest.cc108
1 files changed, 65 insertions, 43 deletions
diff --git a/cc/math_util_unittest.cc b/cc/math_util_unittest.cc
index 93a980f..92c4405 100644
--- a/cc/math_util_unittest.cc
+++ b/cc/math_util_unittest.cc
@@ -331,7 +331,7 @@ TEST(MathUtilGfxTransformTest, verifyMatrixInversion)
{
// Invert a translation
gfx::Transform translation;
- translation.PreconcatTranslate3d(2, 3, 4);
+ translation.Translate3d(2, 3, 4);
EXPECT_TRUE(MathUtil::isInvertible(translation));
gfx::Transform inverseTranslation = MathUtil::inverse(translation);
@@ -348,7 +348,7 @@ TEST(MathUtilGfxTransformTest, verifyMatrixInversion)
// Invert a non-uniform scale
gfx::Transform scale;
- scale.PreconcatScale3d(4, 10, 100);
+ scale.Scale3d(4, 10, 100);
EXPECT_TRUE(MathUtil::isInvertible(scale));
gfx::Transform inverseScale = MathUtil::inverse(scale);
@@ -512,6 +512,28 @@ TEST(MathUtilGfxTransformTest, verifyMultiplyOperator)
EXPECT_FALSE(A * B == B * A);
}
+TEST(MathUtilGfxTransformTest, verifyMultiplyAndAssignOperator)
+{
+ gfx::Transform A;
+ initializeTestMatrix(&A);
+
+ gfx::Transform B;
+ initializeTestMatrix2(&B);
+
+ A *= B;
+ EXPECT_ROW1_EQ(2036, 2292, 2548, 2804, A);
+ EXPECT_ROW2_EQ(2162, 2434, 2706, 2978, A);
+ EXPECT_ROW3_EQ(2288, 2576, 2864, 3152, A);
+ EXPECT_ROW4_EQ(2414, 2718, 3022, 3326, A);
+
+ // Just an additional sanity check; matrix multiplication is not commutative.
+ gfx::Transform C = A;
+ C *= B;
+ gfx::Transform D = B;
+ D *= A;
+ EXPECT_FALSE(C == D);
+}
+
TEST(MathUtilGfxTransformTest, verifyMatrixMultiplication)
{
gfx::Transform A;
@@ -542,16 +564,16 @@ TEST(MathUtilGfxTransformTest, verifyMakeIdentiy)
TEST(MathUtilGfxTransformTest, verifyTranslate)
{
gfx::Transform A;
- A.PreconcatTranslate(2, 3);
+ A.Translate(2, 3);
EXPECT_ROW1_EQ(1, 0, 0, 2, A);
EXPECT_ROW2_EQ(0, 1, 0, 3, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
EXPECT_ROW4_EQ(0, 0, 0, 1, A);
- // Verify that PreconcatTranslate() post-multiplies the existing matrix.
+ // Verify that Translate() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatScale(5, 5);
- A.PreconcatTranslate(2, 3);
+ A.Scale(5, 5);
+ A.Translate(2, 3);
EXPECT_ROW1_EQ(5, 0, 0, 10, A);
EXPECT_ROW2_EQ(0, 5, 0, 15, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
@@ -561,16 +583,16 @@ TEST(MathUtilGfxTransformTest, verifyTranslate)
TEST(MathUtilGfxTransformTest, verifyTranslate3d)
{
gfx::Transform A;
- A.PreconcatTranslate3d(2, 3, 4);
+ A.Translate3d(2, 3, 4);
EXPECT_ROW1_EQ(1, 0, 0, 2, A);
EXPECT_ROW2_EQ(0, 1, 0, 3, A);
EXPECT_ROW3_EQ(0, 0, 1, 4, A);
EXPECT_ROW4_EQ(0, 0, 0, 1, A);
- // Verify that PreconcatTranslate3d() post-multiplies the existing matrix.
+ // Verify that Translate3d() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
- A.PreconcatTranslate3d(2, 3, 4);
+ A.Scale3d(6, 7, 8);
+ A.Translate3d(2, 3, 4);
EXPECT_ROW1_EQ(6, 0, 0, 12, A);
EXPECT_ROW2_EQ(0, 7, 0, 21, A);
EXPECT_ROW3_EQ(0, 0, 8, 32, A);
@@ -580,16 +602,16 @@ TEST(MathUtilGfxTransformTest, verifyTranslate3d)
TEST(MathUtilGfxTransformTest, verifyScale)
{
gfx::Transform A;
- A.PreconcatScale(6, 7);
+ A.Scale(6, 7);
EXPECT_ROW1_EQ(6, 0, 0, 0, A);
EXPECT_ROW2_EQ(0, 7, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
EXPECT_ROW4_EQ(0, 0, 0, 1, A);
- // Verify that PreconcatScale() post-multiplies the existing matrix.
+ // Verify that Scale() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatTranslate3d(2, 3, 4);
- A.PreconcatScale(6, 7);
+ A.Translate3d(2, 3, 4);
+ A.Scale(6, 7);
EXPECT_ROW1_EQ(6, 0, 0, 2, A);
EXPECT_ROW2_EQ(0, 7, 0, 3, A);
EXPECT_ROW3_EQ(0, 0, 1, 4, A);
@@ -599,7 +621,7 @@ TEST(MathUtilGfxTransformTest, verifyScale)
TEST(MathUtilGfxTransformTest, verifyScale3d)
{
gfx::Transform A;
- A.PreconcatScale3d(6, 7, 8);
+ A.Scale3d(6, 7, 8);
EXPECT_ROW1_EQ(6, 0, 0, 0, A);
EXPECT_ROW2_EQ(0, 7, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 8, 0, A);
@@ -607,8 +629,8 @@ TEST(MathUtilGfxTransformTest, verifyScale3d)
// Verify that scale3d() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatTranslate3d(2, 3, 4);
- A.PreconcatScale3d(6, 7, 8);
+ A.Translate3d(2, 3, 4);
+ A.Scale3d(6, 7, 8);
EXPECT_ROW1_EQ(6, 0, 0, 2, A);
EXPECT_ROW2_EQ(0, 7, 0, 3, A);
EXPECT_ROW3_EQ(0, 0, 8, 4, A);
@@ -618,16 +640,16 @@ TEST(MathUtilGfxTransformTest, verifyScale3d)
TEST(MathUtilGfxTransformTest, verifyRotate)
{
gfx::Transform A;
- A.PreconcatRotate(90);
+ A.Rotate(90);
EXPECT_ROW1_NEAR(0, -1, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW2_NEAR(1, 0, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
EXPECT_ROW4_EQ(0, 0, 0, 1, A);
- // Verify that PreconcatRotate() post-multiplies the existing matrix.
+ // Verify that Rotate() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
- A.PreconcatRotate(90);
+ A.Scale3d(6, 7, 8);
+ A.Rotate(90);
EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW3_EQ(0, 0, 8, 0, A);
@@ -665,7 +687,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateEulerAngles)
// Verify that rotate3d(rx, ry, rz) post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
+ A.Scale3d(6, 7, 8);
MathUtil::rotateEulerAngles(&A, 0, 0, 90);
EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
@@ -738,7 +760,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes)
// Verify that rotate3d(axis, angle) post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
+ A.Scale3d(6, 7, 8);
MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90);
EXPECT_ROW1_NEAR(0, -6, 0, 0, A, ERROR_THRESHOLD);
EXPECT_ROW2_NEAR(7, 0, 0, 0, A, ERROR_THRESHOLD);
@@ -789,7 +811,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis)
TEST(MathUtilGfxTransformTest, verifySkewX)
{
gfx::Transform A;
- A.PreconcatSkewX(45);
+ A.SkewX(45);
EXPECT_ROW1_EQ(1, 1, 0, 0, A);
EXPECT_ROW2_EQ(0, 1, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
@@ -798,8 +820,8 @@ TEST(MathUtilGfxTransformTest, verifySkewX)
// Verify that skewX() post-multiplies the existing matrix.
// Row 1, column 2, would incorrectly have value "7" if the matrix is pre-multiplied instead of post-multiplied.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
- A.PreconcatSkewX(45);
+ A.Scale3d(6, 7, 8);
+ A.SkewX(45);
EXPECT_ROW1_EQ(6, 6, 0, 0, A);
EXPECT_ROW2_EQ(0, 7, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 8, 0, A);
@@ -809,7 +831,7 @@ TEST(MathUtilGfxTransformTest, verifySkewX)
TEST(MathUtilGfxTransformTest, verifySkewY)
{
gfx::Transform A;
- A.PreconcatSkewY(45);
+ A.SkewY(45);
EXPECT_ROW1_EQ(1, 0, 0, 0, A);
EXPECT_ROW2_EQ(1, 1, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
@@ -818,8 +840,8 @@ TEST(MathUtilGfxTransformTest, verifySkewY)
// Verify that skewY() post-multiplies the existing matrix.
// Row 2, column 1, would incorrectly have value "6" if the matrix is pre-multiplied instead of post-multiplied.
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
- A.PreconcatSkewY(45);
+ A.Scale3d(6, 7, 8);
+ A.SkewY(45);
EXPECT_ROW1_EQ(6, 0, 0, 0, A);
EXPECT_ROW2_EQ(7, 7, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 8, 0, A);
@@ -829,16 +851,16 @@ TEST(MathUtilGfxTransformTest, verifySkewY)
TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth)
{
gfx::Transform A;
- A.PreconcatPerspectiveDepth(1);
+ A.ApplyPerspectiveDepth(1);
EXPECT_ROW1_EQ(1, 0, 0, 0, A);
EXPECT_ROW2_EQ(0, 1, 0, 0, A);
EXPECT_ROW3_EQ(0, 0, 1, 0, A);
EXPECT_ROW4_EQ(0, 0, -1, 1, A);
- // Verify that PreconcatPerspectiveDepth() post-multiplies the existing matrix.
+ // Verify that PerspectiveDepth() post-multiplies the existing matrix.
MathUtil::makeIdentity(&A);
- A.PreconcatTranslate3d(2, 3, 4);
- A.PreconcatPerspectiveDepth(1);
+ A.Translate3d(2, 3, 4);
+ A.ApplyPerspectiveDepth(1);
EXPECT_ROW1_EQ(1, 0, -2, 2, A);
EXPECT_ROW2_EQ(0, 1, -3, 3, A);
EXPECT_ROW3_EQ(0, 0, -3, 4, A);
@@ -848,11 +870,11 @@ TEST(MathUtilGfxTransformTest, verifyPerspectiveDepth)
TEST(MathUtilGfxTransformTest, verifyHasPerspective)
{
gfx::Transform A;
- A.PreconcatPerspectiveDepth(1);
+ A.ApplyPerspectiveDepth(1);
EXPECT_TRUE(MathUtil::hasPerspective(A));
MathUtil::makeIdentity(&A);
- A.PreconcatPerspectiveDepth(0);
+ A.ApplyPerspectiveDepth(0);
EXPECT_FALSE(MathUtil::hasPerspective(A));
MathUtil::makeIdentity(&A);
@@ -885,11 +907,11 @@ TEST(MathUtilGfxTransformTest, verifyIsInvertible)
EXPECT_TRUE(MathUtil::isInvertible(A));
MathUtil::makeIdentity(&A);
- A.PreconcatTranslate3d(2, 3, 4);
+ A.Translate3d(2, 3, 4);
EXPECT_TRUE(MathUtil::isInvertible(A));
MathUtil::makeIdentity(&A);
- A.PreconcatScale3d(6, 7, 8);
+ A.Scale3d(6, 7, 8);
EXPECT_TRUE(MathUtil::isInvertible(A));
MathUtil::makeIdentity(&A);
@@ -897,30 +919,30 @@ TEST(MathUtilGfxTransformTest, verifyIsInvertible)
EXPECT_TRUE(MathUtil::isInvertible(A));
MathUtil::makeIdentity(&A);
- A.PreconcatSkewX(45);
+ A.SkewX(45);
EXPECT_TRUE(MathUtil::isInvertible(A));
// A perspective matrix (projection plane at z=0) is invertible. The intuitive
// explanation is that perspective is eqivalent to a skew of the w-axis; skews are
// invertible.
MathUtil::makeIdentity(&A);
- A.PreconcatPerspectiveDepth(1);
+ A.ApplyPerspectiveDepth(1);
EXPECT_TRUE(MathUtil::isInvertible(A));
// A "pure" perspective matrix derived by similar triangles, with m44() set to zero
// (i.e. camera positioned at the origin), is not invertible.
MathUtil::makeIdentity(&A);
- A.PreconcatPerspectiveDepth(1);
+ A.ApplyPerspectiveDepth(1);
A.matrix().setDouble(3, 3, 0);
EXPECT_FALSE(MathUtil::isInvertible(A));
// Adding more to a non-invertible matrix will not make it invertible in the general case.
MathUtil::makeIdentity(&A);
- A.PreconcatPerspectiveDepth(1);
+ A.ApplyPerspectiveDepth(1);
A.matrix().setDouble(3, 3, 0);
- A.PreconcatScale3d(6, 7, 8);
+ A.Scale3d(6, 7, 8);
MathUtil::rotateEulerAngles(&A, 10, 20, 30);
- A.PreconcatTranslate3d(6, 7, 8);
+ A.Translate3d(6, 7, 8);
EXPECT_FALSE(MathUtil::isInvertible(A));
// A degenerate matrix of all zeros is not invertible.