| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkMath.h" | 8 #include "SkMath.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 SkMatrix translate; | 196 SkMatrix translate; |
| 197 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1); | 197 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1); |
| 198 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale()); | 198 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale()); |
| 199 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale()); | 199 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale()); |
| 200 success = translate.getMinMaxScales(scales); | 200 success = translate.getMinMaxScales(scales); |
| 201 REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 =
= scales[1]); | 201 REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 =
= scales[1]); |
| 202 | 202 |
| 203 SkMatrix perspX; | 203 SkMatrix perspX; |
| 204 perspX.reset(); | 204 perspX.reset(); |
| 205 perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000)); | 205 perspX.setPerspX(SK_Scalar1 / 1000); |
| 206 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale()); | 206 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale()); |
| 207 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale()); | 207 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale()); |
| 208 // Verify that getMinMaxScales() doesn't update the scales array on failure. | 208 // Verify that getMinMaxScales() doesn't update the scales array on failure. |
| 209 scales[0] = -5; | 209 scales[0] = -5; |
| 210 scales[1] = -5; | 210 scales[1] = -5; |
| 211 success = perspX.getMinMaxScales(scales); | 211 success = perspX.getMinMaxScales(scales); |
| 212 REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * S
K_Scalar1 == scales[1]); | 212 REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * S
K_Scalar1 == scales[1]); |
| 213 | 213 |
| 214 SkMatrix perspY; | 214 SkMatrix perspY; |
| 215 perspY.reset(); | 215 perspY.reset(); |
| 216 perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500)); | 216 perspY.setPerspY(-SK_Scalar1 / 500); |
| 217 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale()); | 217 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale()); |
| 218 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale()); | 218 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale()); |
| 219 scales[0] = -5; | 219 scales[0] = -5; |
| 220 scales[1] = -5; | 220 scales[1] = -5; |
| 221 success = perspY.getMinMaxScales(scales); | 221 success = perspY.getMinMaxScales(scales); |
| 222 REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * S
K_Scalar1 == scales[1]); | 222 REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * S
K_Scalar1 == scales[1]); |
| 223 | 223 |
| 224 SkMatrix baseMats[] = {scale, rot90Scale, rotate, | 224 SkMatrix baseMats[] = {scale, rot90Scale, rotate, |
| 225 translate, perspX, perspY}; | 225 translate, perspX, perspY}; |
| 226 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)]; | 226 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)]; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 // skew with different size at a pivot point | 352 // skew with different size at a pivot point |
| 353 mat.reset(); | 353 mat.reset(); |
| 354 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20), | 354 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20), |
| 355 SkIntToScalar(2), SkIntToScalar(2)); | 355 SkIntToScalar(2), SkIntToScalar(2)); |
| 356 REPORTER_ASSERT(reporter, !mat.isSimilarity()); | 356 REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
| 357 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); | 357 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
| 358 | 358 |
| 359 // perspective x | 359 // perspective x |
| 360 mat.reset(); | 360 mat.reset(); |
| 361 mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2)); | 361 mat.setPerspX(SK_Scalar1 / 2); |
| 362 REPORTER_ASSERT(reporter, !mat.isSimilarity()); | 362 REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
| 363 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); | 363 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
| 364 | 364 |
| 365 // perspective y | 365 // perspective y |
| 366 mat.reset(); | 366 mat.reset(); |
| 367 mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2)); | 367 mat.setPerspY(SK_Scalar1 / 2); |
| 368 REPORTER_ASSERT(reporter, !mat.isSimilarity()); | 368 REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
| 369 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); | 369 REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); |
| 370 | 370 |
| 371 // rotate | 371 // rotate |
| 372 for (int angle = 0; angle < 360; ++angle) { | 372 for (int angle = 0; angle < 360; ++angle) { |
| 373 mat.reset(); | 373 mat.reset(); |
| 374 mat.setRotate(SkIntToScalar(angle)); | 374 mat.setRotate(SkIntToScalar(angle)); |
| 375 REPORTER_ASSERT(reporter, mat.isSimilarity()); | 375 REPORTER_ASSERT(reporter, mat.isSimilarity()); |
| 376 REPORTER_ASSERT(reporter, mat.preservesRightAngles()); | 376 REPORTER_ASSERT(reporter, mat.preservesRightAngles()); |
| 377 } | 377 } |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 | 860 |
| 861 #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e) | 861 #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e) |
| 862 REPORTER_ASSERT(reporter, affineEqual(ScaleX)); | 862 REPORTER_ASSERT(reporter, affineEqual(ScaleX)); |
| 863 REPORTER_ASSERT(reporter, affineEqual(SkewY)); | 863 REPORTER_ASSERT(reporter, affineEqual(SkewY)); |
| 864 REPORTER_ASSERT(reporter, affineEqual(SkewX)); | 864 REPORTER_ASSERT(reporter, affineEqual(SkewX)); |
| 865 REPORTER_ASSERT(reporter, affineEqual(ScaleY)); | 865 REPORTER_ASSERT(reporter, affineEqual(ScaleY)); |
| 866 REPORTER_ASSERT(reporter, affineEqual(TransX)); | 866 REPORTER_ASSERT(reporter, affineEqual(TransX)); |
| 867 REPORTER_ASSERT(reporter, affineEqual(TransY)); | 867 REPORTER_ASSERT(reporter, affineEqual(TransY)); |
| 868 #undef affineEqual | 868 #undef affineEqual |
| 869 | 869 |
| 870 mat.set(SkMatrix::kMPersp1, SkScalarToPersp(SK_Scalar1 / 2)); | 870 mat.set(SkMatrix::kMPersp1, SK_Scalar1 / 2); |
| 871 REPORTER_ASSERT(reporter, !mat.asAffine(affine)); | 871 REPORTER_ASSERT(reporter, !mat.asAffine(affine)); |
| 872 | 872 |
| 873 SkMatrix mat2; | 873 SkMatrix mat2; |
| 874 mat2.reset(); | 874 mat2.reset(); |
| 875 mat.reset(); | 875 mat.reset(); |
| 876 SkScalar zero = 0; | 876 SkScalar zero = 0; |
| 877 mat.set(SkMatrix::kMSkewX, -zero); | 877 mat.set(SkMatrix::kMSkewX, -zero); |
| 878 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2)); | 878 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2)); |
| 879 | 879 |
| 880 mat2.reset(); | 880 mat2.reset(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 896 a.setTranslate(10, 20); | 896 a.setTranslate(10, 20); |
| 897 | 897 |
| 898 SkMatrix b; | 898 SkMatrix b; |
| 899 b.setScale(3, 5); | 899 b.setScale(3, 5); |
| 900 | 900 |
| 901 SkMatrix expected; | 901 SkMatrix expected; |
| 902 expected.setConcat(a,b); | 902 expected.setConcat(a,b); |
| 903 | 903 |
| 904 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); | 904 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); |
| 905 } | 905 } |
| OLD | NEW |