Index: tests/MatrixTest.cpp |
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp |
index cbec021b405273c2301a3629c790906f11d6b5d3..fc7ac42a99690d1269d1f2c04f360a918011b25a 100644 |
--- a/tests/MatrixTest.cpp |
+++ b/tests/MatrixTest.cpp |
@@ -245,88 +245,96 @@ static void test_matrix_min_max_scale(skiatest::Reporter* reporter) { |
} |
} |
-static void test_matrix_is_similarity(skiatest::Reporter* reporter) { |
+static void test_matrix_preserve_shape(skiatest::Reporter* reporter) { |
SkMatrix mat; |
// identity |
mat.setIdentity(); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// translation only |
mat.reset(); |
mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// scale with same size |
mat.reset(); |
mat.setScale(SkIntToScalar(15), SkIntToScalar(15)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// scale with one negative |
mat.reset(); |
mat.setScale(SkIntToScalar(-15), SkIntToScalar(15)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// scale with different size |
mat.reset(); |
mat.setScale(SkIntToScalar(15), SkIntToScalar(20)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// scale with same size at a pivot point |
mat.reset(); |
mat.setScale(SkIntToScalar(15), SkIntToScalar(15), |
SkIntToScalar(2), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// scale with different size at a pivot point |
mat.reset(); |
mat.setScale(SkIntToScalar(15), SkIntToScalar(20), |
SkIntToScalar(2), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// skew with same size |
mat.reset(); |
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// skew with different size |
mat.reset(); |
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// skew with same size at a pivot point |
mat.reset(); |
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15), |
SkIntToScalar(2), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// skew with different size at a pivot point |
mat.reset(); |
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20), |
SkIntToScalar(2), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// perspective x |
mat.reset(); |
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// perspective y |
mat.reset(); |
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// rotate |
for (int angle = 0; angle < 360; ++angle) { |
mat.reset(); |
mat.setRotate(SkIntToScalar(angle)); |
-#ifndef SK_CPU_ARM64 |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
-#else |
- // 64-bit ARM devices built with -O2 and -ffp-contract=fast have a loss |
- // of precision and require that we have a higher tolerance |
- REPORTER_ASSERT(reporter, mat.isSimilarity(SK_ScalarNearlyZero + 0.00010113f)); |
-#endif |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
} |
// see if there are any accumulated precision issues |
@@ -335,38 +343,60 @@ static void test_matrix_is_similarity(skiatest::Reporter* reporter) { |
mat.postRotate(SkIntToScalar(1)); |
} |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// rotate + translate |
mat.reset(); |
mat.setRotate(SkIntToScalar(30)); |
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// rotate + uniform scale |
mat.reset(); |
mat.setRotate(SkIntToScalar(30)); |
mat.postScale(SkIntToScalar(2), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// rotate + non-uniform scale |
mat.reset(); |
mat.setRotate(SkIntToScalar(30)); |
mat.postScale(SkIntToScalar(3), SkIntToScalar(2)); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
+ |
+ // non-uniform scale + rotate |
+ mat.reset(); |
+ mat.setScale(SkIntToScalar(3), SkIntToScalar(2)); |
+ mat.postRotate(SkIntToScalar(30)); |
+ REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
// all zero |
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
// all zero except perspective |
+ mat.reset(); |
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1); |
REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
+ |
+ // scales zero, only skews (rotation) |
+ mat.setAll(0, SK_Scalar1, 0, |
+ -SK_Scalar1, 0, 0, |
+ 0, 0, SkMatrix::I()[8]); |
+ REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
- // scales zero, only skews |
+ // scales zero, only skews (reflection) |
mat.setAll(0, SK_Scalar1, 0, |
SK_Scalar1, 0, 0, |
0, 0, SkMatrix::I()[8]); |
REPORTER_ASSERT(reporter, mat.isSimilarity()); |
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
} |
// For test_matrix_decomposition, below. |
@@ -815,7 +845,7 @@ DEF_TEST(Matrix, reporter) { |
REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); |
test_matrix_min_max_scale(reporter); |
- test_matrix_is_similarity(reporter); |
+ test_matrix_preserve_shape(reporter); |
test_matrix_recttorect(reporter); |
test_matrix_decomposition(reporter); |
test_matrix_homogeneous(reporter); |