}
}
-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));
REPORTER_ASSERT(reporter, mat.isSimilarity());
+ REPORTER_ASSERT(reporter, mat.preservesRightAngles());
}
// see if there are any accumulated precision issues
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.
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);