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

Side by Side Diff: tests/MatrixTest.cpp

Issue 23576015: Change old PRG to be SkLCGRandom; change new one to SkRandom (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix some spurious SkMWCRandoms Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « tests/MathTest.cpp ('k') | tests/MipMapTest.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkMath.h" 9 #include "SkMath.h"
10 #include "SkMatrix.h" 10 #include "SkMatrix.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch()); 162 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch());
163 163
164 SkMatrix baseMats[] = {scale, rot90Scale, rotate, 164 SkMatrix baseMats[] = {scale, rot90Scale, rotate,
165 translate, perspX, perspY}; 165 translate, perspX, perspY};
166 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)]; 166 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
167 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) { 167 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
168 mats[i] = baseMats[i]; 168 mats[i] = baseMats[i];
169 bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]); 169 bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
170 REPORTER_ASSERT(reporter, invertable); 170 REPORTER_ASSERT(reporter, invertable);
171 } 171 }
172 SkMWCRandom rand; 172 SkRandom rand;
173 for (int m = 0; m < 1000; ++m) { 173 for (int m = 0; m < 1000; ++m) {
174 SkMatrix mat; 174 SkMatrix mat;
175 mat.reset(); 175 mat.reset();
176 for (int i = 0; i < 4; ++i) { 176 for (int i = 0; i < 4; ++i) {
177 int x = rand.nextU() % SK_ARRAY_COUNT(mats); 177 int x = rand.nextU() % SK_ARRAY_COUNT(mats);
178 mat.postConcat(mats[x]); 178 mat.postConcat(mats[x]);
179 } 179 }
180 SkScalar stretch = mat.getMaxStretch(); 180 SkScalar stretch = mat.getMaxStretch();
181 181
182 if ((stretch < 0) != mat.hasPerspective()) { 182 if ((stretch < 0) != mat.hasPerspective()) {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); 485 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
486 486
487 // rotation, anisotropic scale + reflection, then different rotation 487 // rotation, anisotropic scale + reflection, then different rotation
488 mat.setRotate(kRotation0); 488 mat.setRotate(kRotation0);
489 mat.postScale(-kScale1, kScale0); 489 mat.postScale(-kScale1, kScale0);
490 mat.postRotate(kRotation1); 490 mat.postRotate(kRotation1);
491 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota tion2)); 491 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rota tion2));
492 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); 492 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
493 493
494 // try some random matrices 494 // try some random matrices
495 SkMWCRandom rand; 495 SkRandom rand;
496 for (int m = 0; m < 1000; ++m) { 496 for (int m = 0; m < 1000; ++m) {
497 SkScalar rot0 = rand.nextRangeF(-180, 180); 497 SkScalar rot0 = rand.nextRangeF(-180, 180);
498 SkScalar sx = rand.nextRangeF(-3000.f, 3000.f); 498 SkScalar sx = rand.nextRangeF(-3000.f, 3000.f);
499 SkScalar sy = rand.nextRangeF(-3000.f, 3000.f); 499 SkScalar sy = rand.nextRangeF(-3000.f, 3000.f);
500 SkScalar rot1 = rand.nextRangeF(-180, 180); 500 SkScalar rot1 = rand.nextRangeF(-180, 180);
501 mat.setRotate(rot0); 501 mat.setRotate(rot0);
502 mat.postScale(sx, sy); 502 mat.postScale(sx, sy);
503 mat.postRotate(rot1); 503 mat.postRotate(rot1);
504 504
505 if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) { 505 if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 567
568 static void test_matrix_homogeneous(skiatest::Reporter* reporter) { 568 static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
569 SkMatrix mat; 569 SkMatrix mat;
570 570
571 const float kRotation0 = 15.5f; 571 const float kRotation0 = 15.5f;
572 const float kRotation1 = -50.f; 572 const float kRotation1 = -50.f;
573 const float kScale0 = 5000.f; 573 const float kScale0 = 5000.f;
574 574
575 const int kTripleCount = 1000; 575 const int kTripleCount = 1000;
576 const int kMatrixCount = 1000; 576 const int kMatrixCount = 1000;
577 SkMWCRandom rand; 577 SkRandom rand;
578 578
579 SkScalar randTriples[3*kTripleCount]; 579 SkScalar randTriples[3*kTripleCount];
580 for (int i = 0; i < 3*kTripleCount; ++i) { 580 for (int i = 0; i < 3*kTripleCount; ++i) {
581 randTriples[i] = rand.nextRangeF(-3000.f, 3000.f); 581 randTriples[i] = rand.nextRangeF(-3000.f, 3000.f);
582 } 582 }
583 583
584 SkMatrix mats[kMatrixCount]; 584 SkMatrix mats[kMatrixCount];
585 for (int i = 0; i < kMatrixCount; ++i) { 585 for (int i = 0; i < kMatrixCount; ++i) {
586 for (int j = 0; j < 9; ++j) { 586 for (int j = 0; j < 9; ++j) {
587 mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f)); 587 mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 798
799 test_matrix_max_stretch(reporter); 799 test_matrix_max_stretch(reporter);
800 test_matrix_is_similarity(reporter); 800 test_matrix_is_similarity(reporter);
801 test_matrix_recttorect(reporter); 801 test_matrix_recttorect(reporter);
802 test_matrix_decomposition(reporter); 802 test_matrix_decomposition(reporter);
803 test_matrix_homogeneous(reporter); 803 test_matrix_homogeneous(reporter);
804 } 804 }
805 805
806 #include "TestClassDef.h" 806 #include "TestClassDef.h"
807 DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix) 807 DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix)
OLDNEW
« no previous file with comments | « tests/MathTest.cpp ('k') | tests/MipMapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698