Index: cc/math_util_unittest.cc |
diff --git a/cc/math_util_unittest.cc b/cc/math_util_unittest.cc |
index c9daf9c12704f345aa881d92bd4d643c65d58894..1ec88ebe77cbdf7967e0073ca46b38b6d674ab79 100644 |
--- a/cc/math_util_unittest.cc |
+++ b/cc/math_util_unittest.cc |
@@ -21,27 +21,27 @@ TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases) |
gfx::Transform transform; |
transform.MakeIdentity(); |
- EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); |
+ EXPECT_FALSE(transform.IsBackFaceVisible()); |
transform.MakeIdentity(); |
MathUtil::rotateEulerAngles(&transform, 0, 80, 0); |
- EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); |
+ EXPECT_FALSE(transform.IsBackFaceVisible()); |
transform.MakeIdentity(); |
MathUtil::rotateEulerAngles(&transform, 0, 100, 0); |
- EXPECT_TRUE(MathUtil::isBackFaceVisible(transform)); |
+ EXPECT_TRUE(transform.IsBackFaceVisible()); |
// Edge case, 90 degree rotation should return false. |
transform.MakeIdentity(); |
MathUtil::rotateEulerAngles(&transform, 0, 90, 0); |
- EXPECT_FALSE(MathUtil::isBackFaceVisible(transform)); |
+ EXPECT_FALSE(transform.IsBackFaceVisible()); |
} |
TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) |
{ |
gfx::Transform layerSpaceToProjectionPlane; |
- // This tests if isBackFaceVisible works properly under perspective transforms. |
+ // This tests if IsBackFaceVisible works properly under perspective transforms. |
// Specifically, layers that may have their back face visible in orthographic |
// projection, may not actually have back face visible under perspective projection. |
@@ -52,7 +52,7 @@ TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) |
layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); |
layerSpaceToProjectionPlane.Translate3d(0, 0, 0); |
MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); |
- EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); |
+ EXPECT_TRUE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
// Case 2: Layer is rotated by slightly more than 90 degrees, but shifted off to the |
// side of the camera. Because of the wide field-of-view, the layer's front |
@@ -72,12 +72,12 @@ TEST(MathUtilTest, verifyBackfaceVisibilityForPerspective) |
layerSpaceToProjectionPlane.ApplyPerspectiveDepth(1); |
layerSpaceToProjectionPlane.Translate3d(-10, 0, 0); |
MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 100, 0); |
- EXPECT_FALSE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); |
+ EXPECT_FALSE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
// Case 3: Additionally rotating the layer by 180 degrees should of course show the |
// opposite result of case 2. |
MathUtil::rotateEulerAngles(&layerSpaceToProjectionPlane, 0, 180, 0); |
- EXPECT_TRUE(MathUtil::isBackFaceVisible(layerSpaceToProjectionPlane)); |
+ EXPECT_TRUE(layerSpaceToProjectionPlane.IsBackFaceVisible()); |
} |
TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane) |
@@ -733,7 +733,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) |
// Check rotation about z-axis |
A.MakeIdentity(); |
- MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); |
+ A.RotateAbout(gfx::Vector3dF::ZAxis(), 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); |
@@ -741,7 +741,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) |
// Check rotation about x-axis |
A.MakeIdentity(); |
- MathUtil::rotateAxisAngle(&A, 1, 0, 0, 90); |
+ A.RotateAbout(gfx::Vector3dF::XAxis(), 90); |
EXPECT_ROW1_EQ(1, 0, 0, 0, A); |
EXPECT_ROW2_NEAR(0, 0, -1, 0, A, ERROR_THRESHOLD); |
EXPECT_ROW3_NEAR(0, 1, 0, 0, A, ERROR_THRESHOLD); |
@@ -750,7 +750,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) |
// Check rotation about y-axis. |
// Note carefully, the expected pattern is inverted compared to rotating about x axis or z axis. |
A.MakeIdentity(); |
- MathUtil::rotateAxisAngle(&A, 0, 1, 0, 90); |
+ A.RotateAbout(gfx::Vector3dF::YAxis(), 90); |
EXPECT_ROW1_NEAR(0, 0, 1, 0, A, ERROR_THRESHOLD); |
EXPECT_ROW2_EQ(0, 1, 0, 0, A); |
EXPECT_ROW3_NEAR(-1, 0, 0, 0, A, ERROR_THRESHOLD); |
@@ -759,7 +759,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForAlignedAxes) |
// Verify that rotate3d(axis, angle) post-multiplies the existing matrix. |
A.MakeIdentity(); |
A.Scale3d(6, 7, 8); |
- MathUtil::rotateAxisAngle(&A, 0, 0, 1, 90); |
+ A.RotateAbout(gfx::Vector3dF::ZAxis(), 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); |
@@ -770,7 +770,7 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForArbitraryAxis) |
{ |
// Check rotation about an arbitrary non-axis-aligned vector. |
gfx::Transform A; |
- MathUtil::rotateAxisAngle(&A, 1, 1, 1, 90); |
+ A.RotateAbout(gfx::Vector3dF(1, 1, 1), 90); |
EXPECT_ROW1_NEAR(0.3333333333333334258519187, |
-0.2440169358562924717404030, |
0.9106836025229592124219380, |
@@ -792,12 +792,12 @@ TEST(MathUtilGfxTransformTest, verifyRotateAxisAngleForDegenerateAxis) |
// It is expected to skip applying the rotation. |
gfx::Transform A; |
- MathUtil::rotateAxisAngle(&A, 0, 0, 0, 45); |
+ A.RotateAbout(gfx::Vector3dF(0, 0, 0), 45); |
// Verify that A remains unchanged. |
EXPECT_TRUE(A.IsIdentity()); |
initializeTestMatrix(&A); |
- MathUtil::rotateAxisAngle(&A, 0, 0, 0, 35); |
+ A.RotateAbout(gfx::Vector3dF(0, 0, 0), 35); |
// Verify that A remains unchanged. |
EXPECT_ROW1_EQ(10, 14, 18, 22, A); |
@@ -869,31 +869,31 @@ TEST(MathUtilGfxTransformTest, verifyHasPerspective) |
{ |
gfx::Transform A; |
A.ApplyPerspectiveDepth(1); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
A.MakeIdentity(); |
A.ApplyPerspectiveDepth(0); |
- EXPECT_FALSE(MathUtil::hasPerspective(A)); |
+ EXPECT_FALSE(A.HasPerspective()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 0, -1); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 1, -1); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 2, -0.3); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 3, 0.5); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 3, 0); |
- EXPECT_TRUE(MathUtil::hasPerspective(A)); |
+ EXPECT_TRUE(A.HasPerspective()); |
} |
TEST(MathUtilGfxTransformTest, verifyIsInvertible) |
@@ -1033,80 +1033,166 @@ TEST(MathUtilGfxTransformTest, verifyIsIdentityOrTranslation) |
gfx::Transform A; |
initializeTestMatrix(&A); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
A.MakeIdentity(); |
- EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsIdentityOrTranslation()); |
- // Modifying any non-translation components should cause isIdentityOrTranslation() to |
+ // Modifying any non-translation components should cause IsIdentityOrTranslation() to |
// return false. NOTE: (0, 3), (1, 3), and (2, 3) are the translation components, so |
- // modifying them should still return true for isIdentityOrTranslation(). |
+ // modifying them should still return true. |
A.MakeIdentity(); |
A.matrix().setDouble(0, 0, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(1, 0, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(2, 0, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 0, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
A.MakeIdentity(); |
+ A.matrix().setDouble(0, 1, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(1, 1, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(2, 1, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(3, 1, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(0, 2, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(1, 2, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(2, 2, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(3, 2, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+ |
+ // Note carefully - expecting true here. |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(0, 3, 2); |
+ EXPECT_TRUE(A.IsIdentityOrTranslation()); |
+ |
+ // Note carefully - expecting true here. |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(1, 3, 2); |
+ EXPECT_TRUE(A.IsIdentityOrTranslation()); |
+ |
+ // Note carefully - expecting true here. |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(2, 3, 2); |
+ EXPECT_TRUE(A.IsIdentityOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(3, 3, 2); |
+ EXPECT_FALSE(A.IsIdentityOrTranslation()); |
+} |
+ |
+TEST(MathUtilGfxTransformTest, verifyIsScaleOrTranslation) |
+{ |
+ gfx::Transform A; |
+ |
+ initializeTestMatrix(&A); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
+ |
+ // Modifying any non-scale or non-translation components should cause |
+ // IsScaleOrTranslation() to return false. (0, 0), (1, 1), (2, 2), (0, 3), |
+ // (1, 3), and (2, 3) are the scale and translation components, so |
+ // modifying them should still return true. |
+ |
+ // Note carefully - expecting true here. |
+ A.MakeIdentity(); |
A.matrix().setDouble(0, 0, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(1, 0, 2); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
+ A.matrix().setDouble(2, 0, 2); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(3, 0, 2); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
+ |
+ A.MakeIdentity(); |
+ A.matrix().setDouble(0, 1, 2); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
+ |
+ // Note carefully - expecting true here. |
+ A.MakeIdentity(); |
A.matrix().setDouble(1, 1, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(2, 1, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 1, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(0, 2, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(1, 2, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
+ // Note carefully - expecting true here. |
A.MakeIdentity(); |
A.matrix().setDouble(2, 2, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 2, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
// Note carefully - expecting true here. |
A.MakeIdentity(); |
A.matrix().setDouble(0, 3, 2); |
- EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
// Note carefully - expecting true here. |
A.MakeIdentity(); |
A.matrix().setDouble(1, 3, 2); |
- EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
// Note carefully - expecting true here. |
A.MakeIdentity(); |
A.matrix().setDouble(2, 3, 2); |
- EXPECT_TRUE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_TRUE(A.IsScaleOrTranslation()); |
A.MakeIdentity(); |
A.matrix().setDouble(3, 3, 2); |
- EXPECT_FALSE(MathUtil::isIdentityOrTranslation(A)); |
+ EXPECT_FALSE(A.IsScaleOrTranslation()); |
} |
} // namespace |