| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 dst.fRight = src.fRight * 2; | 135 dst.fRight = src.fRight * 2; |
| 136 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); | 136 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 137 REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType()); | 137 REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType()); |
| 138 REPORTER_ASSERT(reporter, matrix.rectStaysRect()); | 138 REPORTER_ASSERT(reporter, matrix.rectStaysRect()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) { | 141 static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) { |
| 142 // add 100 in case we have a bug, I don't want to kill my stack in the test | 142 // add 100 in case we have a bug, I don't want to kill my stack in the test |
| 143 static const size_t kBufferSize = SkMatrix::kMaxFlattenSize + 100; | 143 static const size_t kBufferSize = SkMatrix::kMaxFlattenSize + 100; |
| 144 char buffer[kBufferSize]; | 144 char buffer[kBufferSize]; |
| 145 size_t size1 = m.writeToMemory(NULL); | 145 size_t size1 = m.writeToMemory(nullptr); |
| 146 size_t size2 = m.writeToMemory(buffer); | 146 size_t size2 = m.writeToMemory(buffer); |
| 147 REPORTER_ASSERT(reporter, size1 == size2); | 147 REPORTER_ASSERT(reporter, size1 == size2); |
| 148 REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize); | 148 REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize); |
| 149 | 149 |
| 150 SkMatrix m2; | 150 SkMatrix m2; |
| 151 size_t size3 = m2.readFromMemory(buffer, kBufferSize); | 151 size_t size3 = m2.readFromMemory(buffer, kBufferSize); |
| 152 REPORTER_ASSERT(reporter, size1 == size3); | 152 REPORTER_ASSERT(reporter, size1 == size3); |
| 153 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2)); | 153 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2)); |
| 154 | 154 |
| 155 char buffer2[kBufferSize]; | 155 char buffer2[kBufferSize]; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 const float kRotation0 = 15.5f; | 490 const float kRotation0 = 15.5f; |
| 491 const float kRotation1 = -50.f; | 491 const float kRotation1 = -50.f; |
| 492 const float kScale0 = 5000.f; | 492 const float kScale0 = 5000.f; |
| 493 const float kScale1 = 0.001f; | 493 const float kScale1 = 0.001f; |
| 494 | 494 |
| 495 // identity | 495 // identity |
| 496 mat.reset(); | 496 mat.reset(); |
| 497 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); | 497 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); |
| 498 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); | 498 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); |
| 499 // make sure it doesn't crash if we pass in NULLs | 499 // make sure it doesn't crash if we pass in NULLs |
| 500 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, NULL, NULL, NULL)); | 500 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, nullptr, nullptr, nullptr
)); |
| 501 | 501 |
| 502 // rotation only | 502 // rotation only |
| 503 mat.setRotate(kRotation0); | 503 mat.setRotate(kRotation0); |
| 504 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); | 504 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); |
| 505 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); | 505 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); |
| 506 | 506 |
| 507 // uniform scale only | 507 // uniform scale only |
| 508 mat.setScale(kScale0, kScale0); | 508 mat.setScale(kScale0, kScale0); |
| 509 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); | 509 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota
tion2)); |
| 510 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); | 510 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale,
rotation2)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 SkScalar zeros[3] = {0.f, 0.f, 0.f}; | 704 SkScalar zeros[3] = {0.f, 0.f, 0.f}; |
| 705 for (int i = 0; i < kMatrixCount; ++i) { | 705 for (int i = 0; i < kMatrixCount; ++i) { |
| 706 SkScalar dst[3]; | 706 SkScalar dst[3]; |
| 707 mats[i].mapHomogeneousPoints(dst, zeros, 1); | 707 mats[i].mapHomogeneousPoints(dst, zeros, 1); |
| 708 REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros,
3)); | 708 REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros,
3)); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 // doesn't crash with null dst, src, count == 0 | 712 // doesn't crash with null dst, src, count == 0 |
| 713 { | 713 { |
| 714 mats[0].mapHomogeneousPoints(NULL, NULL, 0); | 714 mats[0].mapHomogeneousPoints(nullptr, nullptr, 0); |
| 715 } | 715 } |
| 716 | 716 |
| 717 // uniform scale of point | 717 // uniform scale of point |
| 718 { | 718 { |
| 719 mat.setScale(kScale0, kScale0); | 719 mat.setScale(kScale0, kScale0); |
| 720 SkScalar dst[3]; | 720 SkScalar dst[3]; |
| 721 SkScalar src[3] = {randTriples[0], randTriples[1], 1.f}; | 721 SkScalar src[3] = {randTriples[0], randTriples[1], 1.f}; |
| 722 SkPoint pnt; | 722 SkPoint pnt; |
| 723 pnt.set(src[0], src[1]); | 723 pnt.set(src[0], src[1]); |
| 724 mat.mapHomogeneousPoints(dst, src, 1); | 724 mat.mapHomogeneousPoints(dst, src, 1); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 test_flatten(reporter, mat); | 815 test_flatten(reporter, mat); |
| 816 | 816 |
| 817 mat.setScale(SK_Scalar1/2, SkIntToScalar(2)); | 817 mat.setScale(SK_Scalar1/2, SkIntToScalar(2)); |
| 818 REPORTER_ASSERT(reporter, mat.invert(&inverse)); | 818 REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 819 iden1.setConcat(mat, inverse); | 819 iden1.setConcat(mat, inverse); |
| 820 REPORTER_ASSERT(reporter, is_identity(iden1)); | 820 REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 821 test_flatten(reporter, mat); | 821 test_flatten(reporter, mat); |
| 822 | 822 |
| 823 mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0); | 823 mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0); |
| 824 mat.postRotate(SkIntToScalar(25)); | 824 mat.postRotate(SkIntToScalar(25)); |
| 825 REPORTER_ASSERT(reporter, mat.invert(NULL)); | 825 REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
| 826 REPORTER_ASSERT(reporter, mat.invert(&inverse)); | 826 REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 827 iden1.setConcat(mat, inverse); | 827 iden1.setConcat(mat, inverse); |
| 828 REPORTER_ASSERT(reporter, is_identity(iden1)); | 828 REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 829 iden2.setConcat(inverse, mat); | 829 iden2.setConcat(inverse, mat); |
| 830 REPORTER_ASSERT(reporter, is_identity(iden2)); | 830 REPORTER_ASSERT(reporter, is_identity(iden2)); |
| 831 test_flatten(reporter, mat); | 831 test_flatten(reporter, mat); |
| 832 test_flatten(reporter, iden2); | 832 test_flatten(reporter, iden2); |
| 833 | 833 |
| 834 mat.setScale(0, SK_Scalar1); | 834 mat.setScale(0, SK_Scalar1); |
| 835 REPORTER_ASSERT(reporter, !mat.invert(NULL)); | 835 REPORTER_ASSERT(reporter, !mat.invert(nullptr)); |
| 836 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); | 836 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); |
| 837 mat.setScale(SK_Scalar1, 0); | 837 mat.setScale(SK_Scalar1, 0); |
| 838 REPORTER_ASSERT(reporter, !mat.invert(NULL)); | 838 REPORTER_ASSERT(reporter, !mat.invert(nullptr)); |
| 839 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); | 839 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); |
| 840 | 840 |
| 841 // Inverting this matrix results in a non-finite matrix | 841 // Inverting this matrix results in a non-finite matrix |
| 842 mat.setAll(0.0f, 1.0f, 2.0f, | 842 mat.setAll(0.0f, 1.0f, 2.0f, |
| 843 0.0f, 1.0f, -3.40277175e+38f, | 843 0.0f, 1.0f, -3.40277175e+38f, |
| 844 1.00003040f, 1.0f, 0.0f); | 844 1.00003040f, 1.0f, 0.0f); |
| 845 REPORTER_ASSERT(reporter, !mat.invert(NULL)); | 845 REPORTER_ASSERT(reporter, !mat.invert(nullptr)); |
| 846 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); | 846 REPORTER_ASSERT(reporter, !mat.invert(&inverse)); |
| 847 | 847 |
| 848 // rectStaysRect test | 848 // rectStaysRect test |
| 849 { | 849 { |
| 850 static const struct { | 850 static const struct { |
| 851 SkScalar m00, m01, m10, m11; | 851 SkScalar m00, m01, m10, m11; |
| 852 bool mStaysRect; | 852 bool mStaysRect; |
| 853 } | 853 } |
| 854 gRectStaysRectSamples[] = { | 854 gRectStaysRectSamples[] = { |
| 855 { 0, 0, 0, 0, false }, | 855 { 0, 0, 0, 0, false }, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 a.setTranslate(10, 20); | 933 a.setTranslate(10, 20); |
| 934 | 934 |
| 935 SkMatrix b; | 935 SkMatrix b; |
| 936 b.setScale(3, 5); | 936 b.setScale(3, 5); |
| 937 | 937 |
| 938 SkMatrix expected; | 938 SkMatrix expected; |
| 939 expected.setConcat(a,b); | 939 expected.setConcat(a,b); |
| 940 | 940 |
| 941 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); | 941 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); |
| 942 } | 942 } |
| OLD | NEW |