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

Side by Side Diff: tests/PathOpsCubicLineIntersectionIdeas.cpp

Issue 2426173002: fix fuzzers (Closed)
Patch Set: fix dm Created 4 years, 2 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 | « tests/PathOpsCubicIntersectionTestData.cpp ('k') | tests/PathOpsCubicLineIntersectionTest.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 2014 Google Inc. 2 * Copyright 2014 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 "PathOpsTestCommon.h" 7 #include "PathOpsTestCommon.h"
8 #include "SkIntersections.h" 8 #include "SkIntersections.h"
9 #include "SkPathOpsCubic.h" 9 #include "SkPathOpsCubic.h"
10 #include "SkPathOpsLine.h" 10 #include "SkPathOpsLine.h"
11 #include "SkPathOpsQuad.h" 11 #include "SkPathOpsQuad.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 #include "SkReduceOrder.h" 13 #include "SkReduceOrder.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static bool gPathOpsCubicLineIntersectionIdeasVerbose = false; 16 static bool gPathOpsCubicLineIntersectionIdeasVerbose = false;
17 17
18 static struct CubicLineFailures { 18 static struct CubicLineFailures {
19 SkDCubic c; 19 CubicPts c;
20 double t; 20 double t;
21 SkDPoint p; 21 SkDPoint p;
22 } cubicLineFailures[] = { 22 } cubicLineFailures[] = {
23 {{{{-164.3726806640625, 36.826904296875}, {-189.045166015625, -953.222045898 4375}, 23 {{{{-164.3726806640625, 36.826904296875}, {-189.045166015625, -953.222045898 4375},
24 {926.505859375, -897.36175537109375}, {-139.33489990234375, 204.40771484 375}}}, 24 {926.505859375, -897.36175537109375}, {-139.33489990234375, 204.40771484 375}}},
25 0.37329583, {107.54935269006289, -632.13736293162208}}, 25 0.37329583, {107.54935269006289, -632.13736293162208}},
26 {{{{784.056884765625, -554.8350830078125}, {67.5489501953125, 509.0224609375 }, 26 {{{{784.056884765625, -554.8350830078125}, {67.5489501953125, 509.0224609375 },
27 {-447.713134765625, 751.375}, {415.7784423828125, 172.22265625}}}, 27 {-447.713134765625, 751.375}, {415.7784423828125, 172.22265625}}},
28 0.660005242, {-32.973148967736151, 478.01341797403569}}, 28 0.660005242, {-32.973148967736151, 478.01341797403569}},
29 {{{{-580.6834716796875, -127.044921875}, {-872.8983154296875, -945.543029785 15625}, 29 {{{{-580.6834716796875, -127.044921875}, {-872.8983154296875, -945.543029785 15625},
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return; 138 return;
139 } 139 }
140 SkRandom ran; 140 SkRandom ran;
141 double worstStep[256] = {0}; 141 double worstStep[256] = {0};
142 int errors = 0; 142 int errors = 0;
143 int iters = 0; 143 int iters = 0;
144 double smallestR2 = 0; 144 double smallestR2 = 0;
145 double largestR2 = 0; 145 double largestR2 = 0;
146 for (int index = 0; index < 1000000000; ++index) { 146 for (int index = 0; index < 1000000000; ++index) {
147 SkDPoint origin = {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 10 00)}; 147 SkDPoint origin = {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 10 00)};
148 SkDCubic cubic = {{origin, 148 CubicPts cuPts = {{origin,
149 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}, 149 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)},
150 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}, 150 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)},
151 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)} 151 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}
152 }}; 152 }};
153 // construct a line at a known intersection 153 // construct a line at a known intersection
154 double t = ran.nextRangeF(0, 1); 154 double t = ran.nextRangeF(0, 1);
155 SkDCubic cubic;
156 cubic.debugSet(cuPts.fPts);
155 SkDPoint pt = cubic.ptAtT(t); 157 SkDPoint pt = cubic.ptAtT(t);
156 // skip answers with no intersections (although note the bug!) or two, o r more 158 // skip answers with no intersections (although note the bug!) or two, o r more
157 // see if the line / cubic has a fun range of roots 159 // see if the line / cubic has a fun range of roots
158 double A, B, C, D; 160 double A, B, C, D;
159 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D); 161 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D);
160 D -= pt.fY; 162 D -= pt.fY;
161 double allRoots[3] = {0}, validRoots[3] = {0}; 163 double allRoots[3] = {0}, validRoots[3] = {0};
162 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots); 164 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots);
163 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots); 165 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots);
164 if (valid != 1) { 166 if (valid != 1) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 int worstLimit = SK_ARRAY_COUNT(worstStep); 243 int worstLimit = SK_ARRAY_COUNT(worstStep);
242 while (worstStep[--worstLimit] == 0) ; 244 while (worstStep[--worstLimit] == 0) ;
243 for (int idx2 = 0; idx2 <= worstLimit; ++idx2) { 245 for (int idx2 = 0; idx2 <= worstLimit; ++idx2) {
244 SkDebugf("%1.9g ", worstStep[idx2]); 246 SkDebugf("%1.9g ", worstStep[idx2]);
245 } 247 }
246 SkDebugf("\n"); 248 SkDebugf("\n");
247 SkDebugf("smallestR2=%1.9g largestR2=%1.9g\n", smallestR2, largestR2); 249 SkDebugf("smallestR2=%1.9g largestR2=%1.9g\n", smallestR2, largestR2);
248 } 250 }
249 251
250 static double testOneFailure(const CubicLineFailures& failure) { 252 static double testOneFailure(const CubicLineFailures& failure) {
251 const SkDCubic& cubic = failure.c; 253 const CubicPts& c = failure.c;
254 SkDCubic cubic;
255 cubic.debugSet(c.fPts);
252 const SkDPoint& pt = failure.p; 256 const SkDPoint& pt = failure.p;
253 double A, B, C, D; 257 double A, B, C, D;
254 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D); 258 SkDCubic::Coefficients(&cubic[0].fY, &A, &B, &C, &D);
255 D -= pt.fY; 259 D -= pt.fY;
256 double allRoots[3] = {0}, validRoots[3] = {0}; 260 double allRoots[3] = {0}, validRoots[3] = {0};
257 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots); 261 int realRoots = SkDCubic::RootsReal(A, B, C, D, allRoots);
258 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots); 262 int valid = SkDQuad::AddValidTs(allRoots, realRoots, validRoots);
259 SkASSERT_RELEASE(valid == 1); 263 SkASSERT_RELEASE(valid == 1);
260 SkASSERT_RELEASE(realRoots != 1); 264 SkASSERT_RELEASE(realRoots != 1);
261 double t = validRoots[0]; 265 double t = validRoots[0];
(...skipping 12 matching lines...) Expand all
274 SkASSERT_RELEASE(newT >= 0); 278 SkASSERT_RELEASE(newT >= 0);
275 } 279 }
276 } 280 }
277 281
278 DEF_TEST(PathOpsCubicLineOneFailure, reporter) { 282 DEF_TEST(PathOpsCubicLineOneFailure, reporter) {
279 return; // disable for now 283 return; // disable for now
280 const CubicLineFailures& failure = cubicLineFailures[1]; 284 const CubicLineFailures& failure = cubicLineFailures[1];
281 double newT = testOneFailure(failure); 285 double newT = testOneFailure(failure);
282 SkASSERT_RELEASE(newT >= 0); 286 SkASSERT_RELEASE(newT >= 0);
283 } 287 }
OLDNEW
« no previous file with comments | « tests/PathOpsCubicIntersectionTestData.cpp ('k') | tests/PathOpsCubicLineIntersectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698