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

Side by Side Diff: tests/PathOpsCubicReduceOrderTest.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/PathOpsCubicQuadIntersectionTest.cpp ('k') | tests/PathOpsCubicToQuadsTest.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 "SkIntersections.h" 10 #include "SkIntersections.h"
10 #include "SkPathOpsRect.h" 11 #include "SkPathOpsRect.h"
11 #include "SkReduceOrder.h" 12 #include "SkReduceOrder.h"
12 #include "Test.h" 13 #include "Test.h"
13 14
14 static bool controls_inside(const SkDCubic& cubic) { 15 static bool controls_inside(const SkDCubic& cubic) {
15 return between(cubic[0].fX, cubic[1].fX, cubic[3].fX) 16 return between(cubic[0].fX, cubic[1].fX, cubic[3].fX)
16 && between(cubic[0].fX, cubic[2].fX, cubic[3].fX) 17 && between(cubic[0].fX, cubic[2].fX, cubic[3].fX)
17 && between(cubic[0].fY, cubic[1].fY, cubic[3].fY) 18 && between(cubic[0].fY, cubic[1].fY, cubic[3].fY)
18 && between(cubic[0].fY, cubic[2].fY, cubic[3].fY); 19 && between(cubic[0].fY, cubic[2].fY, cubic[3].fY);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ? firstTestIndex : SK_MaxS32; 96 ? firstTestIndex : SK_MaxS32;
96 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines 97 int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines
97 ? firstTestIndex : SK_MaxS32; 98 ? firstTestIndex : SK_MaxS32;
98 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLi nes 99 int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLi nes
99 ? firstTestIndex : SK_MaxS32; 100 ? firstTestIndex : SK_MaxS32;
100 int firstComputedLinesTest = run == RunAll ? 0 : run == RunComputedLines 101 int firstComputedLinesTest = run == RunAll ? 0 : run == RunComputedLines
101 ? firstTestIndex : SK_MaxS32; 102 ? firstTestIndex : SK_MaxS32;
102 103
103 for (index = firstPointDegeneratesTest; index < pointDegenerates_count; ++in dex) { 104 for (index = firstPointDegeneratesTest; index < pointDegenerates_count; ++in dex) {
104 const SkDCubic& cubic = pointDegenerates[index]; 105 const SkDCubic& cubic = pointDegenerates[index];
106 SkASSERT(ValidCubic(cubic));
105 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 107 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
106 if (order != 1) { 108 if (order != 1) {
107 SkDebugf("[%d] pointDegenerates order=%d\n", static_cast<int>(index) , order); 109 SkDebugf("[%d] pointDegenerates order=%d\n", static_cast<int>(index) , order);
108 REPORTER_ASSERT(reporter, 0); 110 REPORTER_ASSERT(reporter, 0);
109 } 111 }
110 } 112 }
111 for (index = firstNotPointDegeneratesTest; index < notPointDegenerates_count ; ++index) { 113 for (index = firstNotPointDegeneratesTest; index < notPointDegenerates_count ; ++index) {
112 const SkDCubic& cubic = notPointDegenerates[index]; 114 const SkDCubic& cubic = notPointDegenerates[index];
115 SkASSERT(ValidCubic(cubic));
113 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 116 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
114 if (order == 1) { 117 if (order == 1) {
115 SkDebugf("[%d] notPointDegenerates order=%d\n", static_cast<int>(ind ex), order); 118 SkDebugf("[%d] notPointDegenerates order=%d\n", static_cast<int>(ind ex), order);
116 REPORTER_ASSERT(reporter, 0); 119 REPORTER_ASSERT(reporter, 0);
117 } 120 }
118 } 121 }
119 for (index = firstLinesTest; index < lines_count; ++index) { 122 for (index = firstLinesTest; index < lines_count; ++index) {
120 const SkDCubic& cubic = lines[index]; 123 const SkDCubic& cubic = lines[index];
124 SkASSERT(ValidCubic(cubic));
121 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 125 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
122 if (order != 2) { 126 if (order != 2) {
123 SkDebugf("[%d] lines order=%d\n", static_cast<int>(index), order); 127 SkDebugf("[%d] lines order=%d\n", static_cast<int>(index), order);
124 REPORTER_ASSERT(reporter, 0); 128 REPORTER_ASSERT(reporter, 0);
125 } 129 }
126 } 130 }
127 for (index = firstNotLinesTest; index < notLines_count; ++index) { 131 for (index = firstNotLinesTest; index < notLines_count; ++index) {
128 const SkDCubic& cubic = notLines[index]; 132 const SkDCubic& cubic = notLines[index];
133 SkASSERT(ValidCubic(cubic));
129 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 134 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
130 if (order == 2) { 135 if (order == 2) {
131 SkDebugf("[%d] notLines order=%d\n", static_cast<int>(index), order) ; 136 SkDebugf("[%d] notLines order=%d\n", static_cast<int>(index), order) ;
132 REPORTER_ASSERT(reporter, 0); 137 REPORTER_ASSERT(reporter, 0);
133 } 138 }
134 } 139 }
135 for (index = firstModEpsilonTest; index < modEpsilonLines_count; ++index) { 140 for (index = firstModEpsilonTest; index < modEpsilonLines_count; ++index) {
136 const SkDCubic& cubic = modEpsilonLines[index]; 141 const SkDCubic& cubic = modEpsilonLines[index];
142 SkASSERT(ValidCubic(cubic));
137 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 143 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
138 if (order == 2) { 144 if (order == 2) {
139 SkDebugf("[%d] line mod by epsilon order=%d\n", static_cast<int>(ind ex), order); 145 SkDebugf("[%d] line mod by epsilon order=%d\n", static_cast<int>(ind ex), order);
140 REPORTER_ASSERT(reporter, 0); 146 REPORTER_ASSERT(reporter, 0);
141 } 147 }
142 } 148 }
143 for (index = firstLessEpsilonTest; index < lessEpsilonLines_count; ++index) { 149 for (index = firstLessEpsilonTest; index < lessEpsilonLines_count; ++index) {
144 const SkDCubic& cubic = lessEpsilonLines[index]; 150 const SkDCubic& cubic = lessEpsilonLines[index];
151 SkASSERT(ValidCubic(cubic));
145 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 152 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
146 if (order != 2) { 153 if (order != 2) {
147 SkDebugf("[%d] line less by epsilon/2 order=%d\n", static_cast<int>( index), order); 154 SkDebugf("[%d] line less by epsilon/2 order=%d\n", static_cast<int>( index), order);
148 REPORTER_ASSERT(reporter, 0); 155 REPORTER_ASSERT(reporter, 0);
149 } 156 }
150 } 157 }
151 for (index = firstNegEpsilonTest; index < negEpsilonLines_count; ++index) { 158 for (index = firstNegEpsilonTest; index < negEpsilonLines_count; ++index) {
152 const SkDCubic& cubic = negEpsilonLines[index]; 159 const SkDCubic& cubic = negEpsilonLines[index];
160 SkASSERT(ValidCubic(cubic));
153 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 161 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
154 if (order != 2) { 162 if (order != 2) {
155 SkDebugf("[%d] line neg by epsilon/2 order=%d\n", static_cast<int>(i ndex), order); 163 SkDebugf("[%d] line neg by epsilon/2 order=%d\n", static_cast<int>(i ndex), order);
156 REPORTER_ASSERT(reporter, 0); 164 REPORTER_ASSERT(reporter, 0);
157 } 165 }
158 } 166 }
159 for (index = firstQuadraticPointTest; index < quadraticPoints_count; ++index ) { 167 for (index = firstQuadraticPointTest; index < quadraticPoints_count; ++index ) {
160 const SkDQuad& quad = quadraticPoints[index]; 168 const SkDQuad& quad = quadraticPoints[index];
169 SkASSERT(ValidQuad(quad));
161 SkDCubic cubic = quad.toCubic(); 170 SkDCubic cubic = quad.toCubic();
162 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 171 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
163 if (order != 1) { 172 if (order != 1) {
164 SkDebugf("[%d] point quad order=%d\n", static_cast<int>(index), orde r); 173 SkDebugf("[%d] point quad order=%d\n", static_cast<int>(index), orde r);
165 REPORTER_ASSERT(reporter, 0); 174 REPORTER_ASSERT(reporter, 0);
166 } 175 }
167 } 176 }
168 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) { 177 for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
169 const SkDQuad& quad = quadraticLines[index]; 178 const SkDQuad& quad = quadraticLines[index];
179 SkASSERT(ValidQuad(quad));
170 SkDCubic cubic = quad.toCubic(); 180 SkDCubic cubic = quad.toCubic();
171 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 181 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
172 if (order != 2) { 182 if (order != 2) {
173 SkDebugf("[%d] line quad order=%d\n", static_cast<int>(index), order ); 183 SkDebugf("[%d] line quad order=%d\n", static_cast<int>(index), order );
174 REPORTER_ASSERT(reporter, 0); 184 REPORTER_ASSERT(reporter, 0);
175 } 185 }
176 } 186 }
177 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_cou nt; ++index) { 187 for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_cou nt; ++index) {
178 const SkDQuad& quad = quadraticModEpsilonLines[index]; 188 const SkDQuad& quad = quadraticModEpsilonLines[index];
189 SkASSERT(ValidQuad(quad));
179 SkDCubic cubic = quad.toCubic(); 190 SkDCubic cubic = quad.toCubic();
180 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 191 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
181 if (order != 3) { 192 if (order != 3) {
182 SkDebugf("[%d] line mod quad order=%d\n", static_cast<int>(index), o rder); 193 SkDebugf("[%d] line mod quad order=%d\n", static_cast<int>(index), o rder);
183 REPORTER_ASSERT(reporter, 0); 194 REPORTER_ASSERT(reporter, 0);
184 } 195 }
185 } 196 }
186 197
187 // test if computed line end points are valid 198 // test if computed line end points are valid
188 for (index = firstComputedLinesTest; index < lines_count; ++index) { 199 for (index = firstComputedLinesTest; index < lines_count; ++index) {
189 const SkDCubic& cubic = lines[index]; 200 const SkDCubic& cubic = lines[index];
201 SkASSERT(ValidCubic(cubic));
190 bool controlsInside = controls_inside(cubic); 202 bool controlsInside = controls_inside(cubic);
191 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics, 203 order = reducer.reduce(cubic, SkReduceOrder::kAllow_Quadratics,
192 SkReduceOrder::kStroke_Style); 204 SkReduceOrder::kStroke_Style);
193 if (order == 2 && reducer.fLine[0] == reducer.fLine[1]) { 205 if (order == 2 && reducer.fLine[0] == reducer.fLine[1]) {
194 SkDebugf("[%d] line computed ends match order=%d\n", static_cast<int >(index), order); 206 SkDebugf("[%d] line computed ends match order=%d\n", static_cast<int >(index), order);
195 REPORTER_ASSERT(reporter, 0); 207 REPORTER_ASSERT(reporter, 0);
196 } 208 }
197 if (controlsInside) { 209 if (controlsInside) {
198 if ( (reducer.fLine[0].fX != cubic[0].fX && reducer.fLine[0].f X != cubic[3].fX) 210 if ( (reducer.fLine[0].fX != cubic[0].fX && reducer.fLine[0].f X != cubic[3].fX)
199 || (reducer.fLine[0].fY != cubic[0].fY && reducer.fLine[0].f Y != cubic[3].fY) 211 || (reducer.fLine[0].fY != cubic[0].fY && reducer.fLine[0].f Y != cubic[3].fY)
(...skipping 17 matching lines...) Expand all
217 && !AlmostEqualUlps(reducer.fLine[1].fY, bounds.fBottom))) { 229 && !AlmostEqualUlps(reducer.fLine[1].fY, bounds.fBottom))) {
218 SkDebugf("[%d] line computed tight bounds order=%d\n", static_ca st<int>(index), order); 230 SkDebugf("[%d] line computed tight bounds order=%d\n", static_ca st<int>(index), order);
219 REPORTER_ASSERT(reporter, 0); 231 REPORTER_ASSERT(reporter, 0);
220 } 232 }
221 } 233 }
222 } 234 }
223 } 235 }
224 236
225 #include "TestClassDef.h" 237 #include "TestClassDef.h"
226 DEFINE_TESTCLASS_SHORT(PathOpsReduceOrderCubicTest) 238 DEFINE_TESTCLASS_SHORT(PathOpsReduceOrderCubicTest)
OLDNEW
« no previous file with comments | « tests/PathOpsCubicQuadIntersectionTest.cpp ('k') | tests/PathOpsCubicToQuadsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698