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

Side by Side Diff: tests/PathOpsCubicToQuadsTest.cpp

Issue 19374003: harden and speed up path op unit tests (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rename threaded to single Created 7 years, 5 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/PathOpsCubicReduceOrderTest.cpp ('k') | tests/PathOpsDCubicTest.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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 #include "PathOpsCubicIntersectionTestData.h" 7 #include "PathOpsCubicIntersectionTestData.h"
8 #include "PathOpsQuadIntersectionTestData.h" 8 #include "PathOpsQuadIntersectionTestData.h"
9 #include "PathOpsTestCommon.h" 9 #include "PathOpsTestCommon.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
11 #include "SkIntersections.h" 11 #include "SkIntersections.h"
12 #include "SkPathOpsRect.h" 12 #include "SkPathOpsRect.h"
13 #include "SkReduceOrder.h" 13 #include "SkReduceOrder.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static void test(skiatest::Reporter* reporter, const SkDCubic* cubics, const cha r* name, 16 static void test(skiatest::Reporter* reporter, const SkDCubic* cubics, const cha r* name,
17 int firstTest, size_t testCount) { 17 int firstTest, size_t testCount) {
18 for (size_t index = firstTest; index < testCount; ++index) { 18 for (size_t index = firstTest; index < testCount; ++index) {
19 const SkDCubic& cubic = cubics[index]; 19 const SkDCubic& cubic = cubics[index];
20 SkASSERT(ValidCubic(cubic));
20 double precision = cubic.calcPrecision(); 21 double precision = cubic.calcPrecision();
21 SkTArray<SkDQuad, true> quads; 22 SkTArray<SkDQuad, true> quads;
22 CubicToQuads(cubic, precision, quads); 23 CubicToQuads(cubic, precision, quads);
23 if (quads.count() != 1 && quads.count() != 2) { 24 if (quads.count() != 1 && quads.count() != 2) {
24 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index), 25 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index),
25 quads.count()); 26 quads.count());
26 } 27 }
27 REPORTER_ASSERT(reporter, quads.count() == 1); 28 REPORTER_ASSERT(reporter, quads.count() == 1);
28 } 29 }
29 } 30 }
30 31
31 static void test(skiatest::Reporter* reporter, const SkDQuad* quadTests, const c har* name, 32 static void test(skiatest::Reporter* reporter, const SkDQuad* quadTests, const c har* name,
32 int firstTest, size_t testCount) { 33 int firstTest, size_t testCount) {
33 for (size_t index = firstTest; index < testCount; ++index) { 34 for (size_t index = firstTest; index < testCount; ++index) {
34 const SkDQuad& quad = quadTests[index]; 35 const SkDQuad& quad = quadTests[index];
36 SkASSERT(ValidQuad(quad));
35 SkDCubic cubic = quad.toCubic(); 37 SkDCubic cubic = quad.toCubic();
36 double precision = cubic.calcPrecision(); 38 double precision = cubic.calcPrecision();
37 SkTArray<SkDQuad, true> quads; 39 SkTArray<SkDQuad, true> quads;
38 CubicToQuads(cubic, precision, quads); 40 CubicToQuads(cubic, precision, quads);
39 if (quads.count() != 1 && quads.count() != 2) { 41 if (quads.count() != 1 && quads.count() != 2) {
40 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index), 42 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index),
41 quads.count()); 43 quads.count());
42 } 44 }
43 REPORTER_ASSERT(reporter, quads.count() <= 2); 45 REPORTER_ASSERT(reporter, quads.count() <= 2);
44 } 46 }
45 } 47 }
46 48
47 static void testC(skiatest::Reporter* reporter, const SkDCubic* cubics, const ch ar* name, 49 static void testC(skiatest::Reporter* reporter, const SkDCubic* cubics, const ch ar* name,
48 int firstTest, size_t testCount) { 50 int firstTest, size_t testCount) {
49 // test if computed line end points are valid 51 // test if computed line end points are valid
50 for (size_t index = firstTest; index < testCount; ++index) { 52 for (size_t index = firstTest; index < testCount; ++index) {
51 const SkDCubic& cubic = cubics[index]; 53 const SkDCubic& cubic = cubics[index];
54 SkASSERT(ValidCubic(cubic));
52 double precision = cubic.calcPrecision(); 55 double precision = cubic.calcPrecision();
53 SkTArray<SkDQuad, true> quads; 56 SkTArray<SkDQuad, true> quads;
54 CubicToQuads(cubic, precision, quads); 57 CubicToQuads(cubic, precision, quads);
55 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) 58 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX)
56 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { 59 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) {
57 SkDebugf("[%d] unmatched start\n", static_cast<int>(index)); 60 SkDebugf("[%d] unmatched start\n", static_cast<int>(index));
58 REPORTER_ASSERT(reporter, 0); 61 REPORTER_ASSERT(reporter, 0);
59 } 62 }
60 int last = quads.count() - 1; 63 int last = quads.count() - 1;
61 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) 64 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX)
62 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) { 65 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) {
63 SkDebugf("[%d] unmatched end\n", static_cast<int>(index)); 66 SkDebugf("[%d] unmatched end\n", static_cast<int>(index));
64 REPORTER_ASSERT(reporter, 0); 67 REPORTER_ASSERT(reporter, 0);
65 } 68 }
66 } 69 }
67 } 70 }
68 71
69 static void testC(skiatest::Reporter* reporter, const SkDCubic(* cubics)[2], con st char* name, 72 static void testC(skiatest::Reporter* reporter, const SkDCubic(* cubics)[2], con st char* name,
70 int firstTest, size_t testCount) { 73 int firstTest, size_t testCount) {
71 for (size_t index = firstTest; index < testCount; ++index) { 74 for (size_t index = firstTest; index < testCount; ++index) {
72 for (int idx2 = 0; idx2 < 2; ++idx2) { 75 for (int idx2 = 0; idx2 < 2; ++idx2) {
73 const SkDCubic& cubic = cubics[index][idx2]; 76 const SkDCubic& cubic = cubics[index][idx2];
77 SkASSERT(ValidCubic(cubic));
74 double precision = cubic.calcPrecision(); 78 double precision = cubic.calcPrecision();
75 SkTArray<SkDQuad, true> quads; 79 SkTArray<SkDQuad, true> quads;
76 CubicToQuads(cubic, precision, quads); 80 CubicToQuads(cubic, precision, quads);
77 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) 81 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX)
78 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { 82 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) {
79 SkDebugf("[%d][%d] unmatched start\n", static_cast<int>(index), idx2); 83 SkDebugf("[%d][%d] unmatched start\n", static_cast<int>(index), idx2);
80 REPORTER_ASSERT(reporter, 0); 84 REPORTER_ASSERT(reporter, 0);
81 } 85 }
82 int last = quads.count() - 1; 86 int last = quads.count() - 1;
83 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) 87 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 }; 165 };
162 166
163 static size_t localsCount = SK_ARRAY_COUNT(locals); 167 static size_t localsCount = SK_ARRAY_COUNT(locals);
164 168
165 #define DEBUG_CRASH 0 169 #define DEBUG_CRASH 0
166 #define TEST_AVERAGE_END_POINTS 0 // must take const off to test 170 #define TEST_AVERAGE_END_POINTS 0 // must take const off to test
167 extern const bool AVERAGE_END_POINTS; 171 extern const bool AVERAGE_END_POINTS;
168 172
169 static void oneOff(skiatest::Reporter* reporter, size_t x) { 173 static void oneOff(skiatest::Reporter* reporter, size_t x) {
170 const SkDCubic& cubic = locals[x]; 174 const SkDCubic& cubic = locals[x];
175 SkASSERT(ValidCubic(cubic));
171 const SkPoint skcubic[4] = { 176 const SkPoint skcubic[4] = {
172 {static_cast<float>(cubic[0].fX), static_cast<float>(cubic[0].fY)}, 177 {static_cast<float>(cubic[0].fX), static_cast<float>(cubic[0].fY)},
173 {static_cast<float>(cubic[1].fX), static_cast<float>(cubic[1].fY)}, 178 {static_cast<float>(cubic[1].fX), static_cast<float>(cubic[1].fY)},
174 {static_cast<float>(cubic[2].fX), static_cast<float>(cubic[2].fY)}, 179 {static_cast<float>(cubic[2].fX), static_cast<float>(cubic[2].fY)},
175 {static_cast<float>(cubic[3].fX), static_cast<float>(cubic[3].fY)}}; 180 {static_cast<float>(cubic[3].fX), static_cast<float>(cubic[3].fY)}};
176 SkScalar skinflect[2]; 181 SkScalar skinflect[2];
177 int skin = SkFindCubicInflections(skcubic, skinflect); 182 int skin = SkFindCubicInflections(skcubic, skinflect);
178 if (false) SkDebugf("%s %d %1.9g\n", __FUNCTION__, skin, skinflect[0]); 183 if (false) SkDebugf("%s %d %1.9g\n", __FUNCTION__, skin, skinflect[0]);
179 SkTArray<SkDQuad, true> quads; 184 SkTArray<SkDQuad, true> quads;
180 double precision = cubic.calcPrecision(); 185 double precision = cubic.calcPrecision();
(...skipping 12 matching lines...) Expand all
193 } 198 }
194 199
195 static void PathOpsCubicToQuadsTest(skiatest::Reporter* reporter) { 200 static void PathOpsCubicToQuadsTest(skiatest::Reporter* reporter) {
196 CubicToQuads_Test(reporter); 201 CubicToQuads_Test(reporter);
197 CubicsToQuadratics_OneOffTest(reporter); 202 CubicsToQuadratics_OneOffTest(reporter);
198 CubicsToQuadratics_OneOffTests(reporter); 203 CubicsToQuadratics_OneOffTests(reporter);
199 } 204 }
200 205
201 #include "TestClassDef.h" 206 #include "TestClassDef.h"
202 DEFINE_TESTCLASS_SHORT(PathOpsCubicToQuadsTest) 207 DEFINE_TESTCLASS_SHORT(PathOpsCubicToQuadsTest)
OLDNEW
« no previous file with comments | « tests/PathOpsCubicReduceOrderTest.cpp ('k') | tests/PathOpsDCubicTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698