Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: tests/MatrixTest.cpp

Issue 298473002: Add function to get both min and max scale factors from matrix (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Address comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MatrixTest.cpp
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 1897554bc8bd1c8fbfbc63d4dc9c77a5d205244c..9c7a5203695e239dc1c9dc6d971405d3ce29dad0 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -120,43 +120,67 @@ static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
}
static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
+ SkScalar scales[2];
+ bool success;
+
SkMatrix identity;
identity.reset();
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxScale());
+ success = identity.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix scale;
scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxScale());
+ success = scale.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success && SK_Scalar1 * 2 == scales[0] && SK_Scalar1 * 4 == scales[1]);
SkMatrix rot90Scale;
rot90Scale.setRotate(90 * SK_Scalar1);
rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale());
+ success = rot90Scale.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4 == scales[0] && SK_Scalar1 / 2 == scales[1]);
SkMatrix rotate;
rotate.setRotate(128 * SK_Scalar1);
- REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale() ,SK_ScalarNearlyZero));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale(), SK_ScalarNearlyZero));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxScale(), SK_ScalarNearlyZero));
+ success = rotate.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success);
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[0], SK_ScalarNearlyZero));
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[1], SK_ScalarNearlyZero));
SkMatrix translate;
translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale());
+ success = translate.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix perspX;
perspX.reset();
perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale());
+ // Verify that getMinMaxScales() doesn't update the scales array on failure.
+ scales[0] = -5;
+ scales[1] = -5;
+ success = perspX.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix perspY;
perspY.reset();
perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale());
+ scales[0] = -5;
+ scales[1] = -5;
+ success = perspY.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix baseMats[] = {scale, rot90Scale, rotate,
translate, perspX, perspY};
@@ -180,6 +204,11 @@ static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
+ SkScalar scales[2];
+ bool success = mat.getMinMaxScales(scales);
+ REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
+ REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
+
if (mat.hasPerspective()) {
m -= 1; // try another non-persp matrix
continue;
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698