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

Side by Side Diff: tests/MatrixTest.cpp

Issue 1045493002: use Sk4f for matrix math (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
844 DEF_TEST(Matrix, reporter) { 802 DEF_TEST(Matrix, reporter) {
845 SkMatrix mat, inverse, iden1, iden2; 803 SkMatrix mat, inverse, iden1, iden2;
846 804
847 mat.reset(); 805 mat.reset();
848 mat.setTranslate(SK_Scalar1, SK_Scalar1); 806 mat.setTranslate(SK_Scalar1, SK_Scalar1);
849 REPORTER_ASSERT(reporter, mat.invert(&inverse)); 807 REPORTER_ASSERT(reporter, mat.invert(&inverse));
850 iden1.setConcat(mat, inverse); 808 iden1.setConcat(mat, inverse);
851 REPORTER_ASSERT(reporter, is_identity(iden1)); 809 REPORTER_ASSERT(reporter, is_identity(iden1));
852 810
853 mat.setScale(SkIntToScalar(2), SkIntToScalar(4)); 811 mat.setScale(SkIntToScalar(2), SkIntToScalar(4));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); 912 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
955 913
956 test_matrix_min_max_scale(reporter); 914 test_matrix_min_max_scale(reporter);
957 test_matrix_preserve_shape(reporter); 915 test_matrix_preserve_shape(reporter);
958 test_matrix_recttorect(reporter); 916 test_matrix_recttorect(reporter);
959 test_matrix_decomposition(reporter); 917 test_matrix_decomposition(reporter);
960 test_matrix_homogeneous(reporter); 918 test_matrix_homogeneous(reporter);
961 test_set9(reporter); 919 test_set9(reporter);
962 920
963 test_decompScale(reporter); 921 test_decompScale(reporter);
964
965 test_mappts(reporter);
966 } 922 }
967 923
968 DEF_TEST(Matrix_Concat, r) { 924 DEF_TEST(Matrix_Concat, r) {
969 SkMatrix a; 925 SkMatrix a;
970 a.setTranslate(10, 20); 926 a.setTranslate(10, 20);
971 927
972 SkMatrix b; 928 SkMatrix b;
973 b.setScale(3, 5); 929 b.setScale(3, 5);
974 930
975 SkMatrix expected; 931 SkMatrix expected;
976 expected.setConcat(a,b); 932 expected.setConcat(a,b);
977 933
978 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); 934 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b));
979 } 935 }
OLDNEW
« 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