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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 REPORTER_ASSERT(reporter, check_decompScale(m)); | 792 REPORTER_ASSERT(reporter, check_decompScale(m)); |
793 m.setScale(2, 3); | 793 m.setScale(2, 3); |
794 REPORTER_ASSERT(reporter, check_decompScale(m)); | 794 REPORTER_ASSERT(reporter, check_decompScale(m)); |
795 m.setRotate(35, 0, 0); | 795 m.setRotate(35, 0, 0); |
796 REPORTER_ASSERT(reporter, check_decompScale(m)); | 796 REPORTER_ASSERT(reporter, check_decompScale(m)); |
797 | 797 |
798 m.setScale(1, 0); | 798 m.setScale(1, 0); |
799 REPORTER_ASSERT(reporter, !check_decompScale(m)); | 799 REPORTER_ASSERT(reporter, !check_decompScale(m)); |
800 } | 800 } |
801 | 801 |
| 802 static void test_mappts(skiatest::Reporter* reporter, const SkMatrix& m, const c
har type[], int n) { |
| 803 const int MAX = 100; |
| 804 SkPoint src[MAX]; |
| 805 SkPoint dst0[MAX], dst1[MAX]; |
| 806 SkASSERT(n <= MAX); |
| 807 |
| 808 SkRandom rand; |
| 809 for (int i = 0; i < n; ++i) { |
| 810 src[i].fX = rand.nextSScalar1() * 100; |
| 811 src[i].fY = rand.nextSScalar1() * 100; |
| 812 } |
| 813 |
| 814 m.mapPoints(dst0, src, n); |
| 815 m.mapPts( dst1, src, n); |
| 816 for (int i = 0; i < n; ++i) { |
| 817 bool eq = SkScalarNearlyEqual(dst0[i].fX, dst1[i].fX) && |
| 818 SkScalarNearlyEqual(dst0[i].fY, dst1[i].fY); |
| 819 if (!eq) { |
| 820 SkDebugf("%s [%d] points (%g %g) pts (%g %g)\n", type, i, dst0[i].fX
, dst0[i].fY, dst1[i].fX, dst1[i].fY); |
| 821 REPORTER_ASSERT(reporter, eq); |
| 822 } |
| 823 } |
| 824 } |
| 825 |
| 826 static void test_mappts(skiatest::Reporter* reporter) { |
| 827 const int counts[] = { 0, 1, 2, 3, 4, 100 }; |
| 828 for (size_t i = 0; i < SK_ARRAY_COUNT(counts); ++i) { |
| 829 const int n = counts[i]; |
| 830 SkMatrix m; |
| 831 m.reset(); |
| 832 test_mappts(reporter, m, "ident", n); |
| 833 m.setTranslate(2, 3); |
| 834 test_mappts(reporter, m, "trans", n); |
| 835 m.postScale(2, 0.5f); |
| 836 test_mappts(reporter, m, "scale", n); |
| 837 m.postRotate(35); |
| 838 test_mappts(reporter, m, "affine", n); |
| 839 m.setPerspX(0.1f); |
| 840 test_mappts(reporter, m, "persp", n); |
| 841 } |
| 842 } |
| 843 |
802 DEF_TEST(Matrix, reporter) { | 844 DEF_TEST(Matrix, reporter) { |
803 SkMatrix mat, inverse, iden1, iden2; | 845 SkMatrix mat, inverse, iden1, iden2; |
804 | 846 |
805 mat.reset(); | 847 mat.reset(); |
806 mat.setTranslate(SK_Scalar1, SK_Scalar1); | 848 mat.setTranslate(SK_Scalar1, SK_Scalar1); |
807 REPORTER_ASSERT(reporter, mat.invert(&inverse)); | 849 REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
808 iden1.setConcat(mat, inverse); | 850 iden1.setConcat(mat, inverse); |
809 REPORTER_ASSERT(reporter, is_identity(iden1)); | 851 REPORTER_ASSERT(reporter, is_identity(iden1)); |
810 | 852 |
811 mat.setScale(SkIntToScalar(2), SkIntToScalar(4)); | 853 mat.setScale(SkIntToScalar(2), SkIntToScalar(4)); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); | 954 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); |
913 | 955 |
914 test_matrix_min_max_scale(reporter); | 956 test_matrix_min_max_scale(reporter); |
915 test_matrix_preserve_shape(reporter); | 957 test_matrix_preserve_shape(reporter); |
916 test_matrix_recttorect(reporter); | 958 test_matrix_recttorect(reporter); |
917 test_matrix_decomposition(reporter); | 959 test_matrix_decomposition(reporter); |
918 test_matrix_homogeneous(reporter); | 960 test_matrix_homogeneous(reporter); |
919 test_set9(reporter); | 961 test_set9(reporter); |
920 | 962 |
921 test_decompScale(reporter); | 963 test_decompScale(reporter); |
| 964 |
| 965 test_mappts(reporter); |
922 } | 966 } |
923 | 967 |
924 DEF_TEST(Matrix_Concat, r) { | 968 DEF_TEST(Matrix_Concat, r) { |
925 SkMatrix a; | 969 SkMatrix a; |
926 a.setTranslate(10, 20); | 970 a.setTranslate(10, 20); |
927 | 971 |
928 SkMatrix b; | 972 SkMatrix b; |
929 b.setScale(3, 5); | 973 b.setScale(3, 5); |
930 | 974 |
931 SkMatrix expected; | 975 SkMatrix expected; |
932 expected.setConcat(a,b); | 976 expected.setConcat(a,b); |
933 | 977 |
934 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); | 978 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); |
935 } | 979 } |
OLD | NEW |