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

Side by Side Diff: tests/PathOpsQuadIntersectionTest.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/PathOpsOpTest.cpp ('k') | tests/PathOpsQuadIntersectionTestData.h » ('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 "PathOpsQuadIntersectionTestData.h" 7 #include "PathOpsQuadIntersectionTestData.h"
8 #include "PathOpsTestCommon.h" 8 #include "PathOpsTestCommon.h"
9 #include "SkIntersections.h" 9 #include "SkIntersections.h"
10 #include "SkPathOpsRect.h" 10 #include "SkPathOpsRect.h"
11 #include "SkReduceOrder.h" 11 #include "SkReduceOrder.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 static void standardTestCases(skiatest::Reporter* reporter) { 14 static void standardTestCases(skiatest::Reporter* reporter) {
15 bool showSkipped = false; 15 bool showSkipped = false;
16 for (size_t index = 0; index < quadraticTests_count; ++index) { 16 for (size_t index = 0; index < quadraticTests_count; ++index) {
17 const SkDQuad& quad1 = quadraticTests[index][0]; 17 const QuadPts& q1 = quadraticTests[index][0];
18 SkDQuad quad1;
19 quad1.debugSet(q1.fPts);
18 SkASSERT(ValidQuad(quad1)); 20 SkASSERT(ValidQuad(quad1));
19 const SkDQuad& quad2 = quadraticTests[index][1]; 21 const QuadPts& q2 = quadraticTests[index][1];
22 SkDQuad quad2;
23 quad2.debugSet(q2.fPts);
20 SkASSERT(ValidQuad(quad2)); 24 SkASSERT(ValidQuad(quad2));
21 SkReduceOrder reduce1, reduce2; 25 SkReduceOrder reduce1, reduce2;
22 int order1 = reduce1.reduce(quad1); 26 int order1 = reduce1.reduce(quad1);
23 int order2 = reduce2.reduce(quad2); 27 int order2 = reduce2.reduce(quad2);
24 if (order1 < 3) { 28 if (order1 < 3) {
25 if (showSkipped) { 29 if (showSkipped) {
26 SkDebugf("[%d] quad1 order=%d\n", static_cast<int>(index), order 1); 30 SkDebugf("[%d] quad1 order=%d\n", static_cast<int>(index), order 1);
27 } 31 }
28 } 32 }
29 if (order2 < 3) { 33 if (order2 < 3) {
(...skipping 15 matching lines...) Expand all
45 __FUNCTION__, static_cast<int>(index), pt, tt1, xy1.fX, xy1.fY, 49 __FUNCTION__, static_cast<int>(index), pt, tt1, xy1.fX, xy1.fY,
46 tt2, xy2.fX, xy2.fY); 50 tt2, xy2.fX, xy2.fY);
47 REPORTER_ASSERT(reporter, 0); 51 REPORTER_ASSERT(reporter, 0);
48 } 52 }
49 } 53 }
50 } 54 }
51 } 55 }
52 } 56 }
53 } 57 }
54 58
55 static const SkDQuad testSet[] = { 59 static const QuadPts testSet[] = {
56 {{{-0.001019871095195412636, -0.008523519150912761688}, {-0.00539640802890062332 2, -0.005396373569965362549}, {-0.02855382487177848816, -0.02855364233255386353} }}, 60 {{{-0.001019871095195412636, -0.008523519150912761688}, {-0.00539640802890062332 2, -0.005396373569965362549}, {-0.02855382487177848816, -0.02855364233255386353} }},
57 {{{-0.004567248281091451645, -0.01482933573424816132}, {-0.01142475008964538574, -0.01140109263360500336}, {-0.02852955088019371033, -0.02847047336399555206}}}, 61 {{{-0.004567248281091451645, -0.01482933573424816132}, {-0.01142475008964538574, -0.01140109263360500336}, {-0.02852955088019371033, -0.02847047336399555206}}},
58 62
59 {{{1, 1}, {0, 2}, {3, 3}}}, 63 {{{1, 1}, {0, 2}, {3, 3}}},
60 {{{3, 0}, {0, 1}, {1, 2}}}, 64 {{{3, 0}, {0, 1}, {1, 2}}},
61 65
62 {{{0.33333333333333326, 0.81481481481481488}, {0.63395173631977997, 0.6874413672 6313931}, {1.205684411948591, 0.81344322326274499}}}, 66 {{{0.33333333333333326, 0.81481481481481488}, {0.63395173631977997, 0.6874413672 6313931}, {1.205684411948591, 0.81344322326274499}}},
63 {{{0.33333333333333326, 0.81481481481481488}, {0.63396444791444551, 0.6874336836 2444768}, {1.205732763658403, 0.81345617746834109}}}, 67 {{{0.33333333333333326, 0.81481481481481488}, {0.63396444791444551, 0.6874336836 2444768}, {1.205732763658403, 0.81345617746834109}}},
64 68
65 {{{4981.9990234375, 1590}, {4981.9990234375, 1617.7523193359375}, {4962.375, 163 7.3760986328125}}}, 69 {{{4981.9990234375, 1590}, {4981.9990234375, 1617.7523193359375}, {4962.375, 163 7.3760986328125}}},
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 {{{360.048828125, 229.2578125}, {360.048828125, 224.4140625}, {362.607421875 , 221.3671875}}}, 323 {{{360.048828125, 229.2578125}, {360.048828125, 224.4140625}, {362.607421875 , 221.3671875}}},
320 {{{362.607421875, 221.3671875}, {365.166015625, 218.3203125}, {369.228515625 , 218.3203125}}}, 324 {{{362.607421875, 221.3671875}, {365.166015625, 218.3203125}, {369.228515625 , 218.3203125}}},
321 {{{8, 8}, {10, 10}, {8, -10}}}, 325 {{{8, 8}, {10, 10}, {8, -10}}},
322 {{{8, 8}, {12, 12}, {14, 4}}}, 326 {{{8, 8}, {12, 12}, {14, 4}}},
323 {{{8, 8}, {9, 9}, {10, 8}}} 327 {{{8, 8}, {9, 9}, {10, 8}}}
324 }; 328 };
325 329
326 const size_t testSetCount = SK_ARRAY_COUNT(testSet); 330 const size_t testSetCount = SK_ARRAY_COUNT(testSet);
327 331
328 static void oneOffTest1(skiatest::Reporter* reporter, size_t outer, size_t inner ) { 332 static void oneOffTest1(skiatest::Reporter* reporter, size_t outer, size_t inner ) {
329 const SkDQuad& quad1 = testSet[outer]; 333 const QuadPts& q1 = testSet[outer];
334 SkDQuad quad1;
335 quad1.debugSet(q1.fPts);
330 SkASSERT(ValidQuad(quad1)); 336 SkASSERT(ValidQuad(quad1));
331 const SkDQuad& quad2 = testSet[inner]; 337 const QuadPts& q2 = testSet[inner];
338 SkDQuad quad2;
339 quad2.debugSet(q2.fPts);
332 SkASSERT(ValidQuad(quad2)); 340 SkASSERT(ValidQuad(quad2));
333 SkIntersections intersections; 341 SkIntersections intersections;
334 intersections.intersect(quad1, quad2); 342 intersections.intersect(quad1, quad2);
335 for (int pt = 0; pt < intersections.used(); ++pt) { 343 for (int pt = 0; pt < intersections.used(); ++pt) {
336 double tt1 = intersections[0][pt]; 344 double tt1 = intersections[0][pt];
337 SkDPoint xy1 = quad1.ptAtT(tt1); 345 SkDPoint xy1 = quad1.ptAtT(tt1);
338 double tt2 = intersections[1][pt]; 346 double tt2 = intersections[1][pt];
339 SkDPoint xy2 = quad2.ptAtT(tt2); 347 SkDPoint xy2 = quad2.ptAtT(tt2);
340 if (!xy1.approximatelyEqual(xy2)) { 348 if (!xy1.approximatelyEqual(xy2)) {
341 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", 349 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
342 __FUNCTION__, static_cast<int>(outer), static_cast<int>(inne r), 350 __FUNCTION__, static_cast<int>(outer), static_cast<int>(inne r),
343 tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); 351 tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
344 REPORTER_ASSERT(reporter, 0); 352 REPORTER_ASSERT(reporter, 0);
345 } 353 }
346 #if ONE_OFF_DEBUG 354 #if ONE_OFF_DEBUG
347 SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__, 355 SkDebugf("%s [%d][%d] t1=%1.9g (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__,
348 outer, inner, tt1, xy1.fX, xy1.fY, tt2); 356 outer, inner, tt1, xy1.fX, xy1.fY, tt2);
349 #endif 357 #endif
350 } 358 }
351 } 359 }
352 360
353 static void oneOffTests(skiatest::Reporter* reporter) { 361 static void oneOffTests(skiatest::Reporter* reporter) {
354 for (size_t outer = 0; outer < testSetCount - 1; ++outer) { 362 for (size_t outer = 0; outer < testSetCount - 1; ++outer) {
355 for (size_t inner = outer + 1; inner < testSetCount; ++inner) { 363 for (size_t inner = outer + 1; inner < testSetCount; ++inner) {
356 oneOffTest1(reporter, outer, inner); 364 oneOffTest1(reporter, outer, inner);
357 } 365 }
358 } 366 }
359 } 367 }
360 368
361 static const SkDQuad coincidentTestSet[] = { 369 static const QuadPts coincidentTestSet[] = {
362 {{{4914.9990234375, 1523}, {4942.75146484375, 1523}, {4962.375, 1542.6239013 671875}}}, 370 {{{4914.9990234375, 1523}, {4942.75146484375, 1523}, {4962.375, 1542.6239013 671875}}},
363 {{{4962.3759765625, 1542.6239013671875}, {4942.75244140625, 1523}, {4915, 15 23}}}, 371 {{{4962.3759765625, 1542.6239013671875}, {4942.75244140625, 1523}, {4915, 15 23}}},
364 #if 0 372 #if 0
365 {{{97.9337615966796875,100}, {88,112.94264984130859375}, {88,130}}}, 373 {{{97.9337615966796875,100}, {88,112.94264984130859375}, {88,130}}},
366 {{{88,130}, {88,124.80951690673828125}, {88.91983795166015625,120}}}, 374 {{{88,130}, {88,124.80951690673828125}, {88.91983795166015625,120}}},
367 #endif 375 #endif
368 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }}, 376 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }},
369 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }}, 377 {{{369.850525, 145.675964}, {382.362915, 121.29287}, {406.211273, 121.29287} }},
370 {{{8, 8}, {10, 10}, {8, -10}}}, 378 {{{8, 8}, {10, 10}, {8, -10}}},
371 {{{8, -10}, {10, 10}, {8, 8}}}, 379 {{{8, -10}, {10, 10}, {8, 8}}},
372 }; 380 };
373 381
374 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet ); 382 static const int coincidentTestSetCount = (int) SK_ARRAY_COUNT(coincidentTestSet );
375 383
376 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) { 384 static void coincidentTestOne(skiatest::Reporter* reporter, int test1, int test2 ) {
377 const SkDQuad& quad1 = coincidentTestSet[test1]; 385 const QuadPts& q1 = coincidentTestSet[test1];
386 SkDQuad quad1;
387 quad1.debugSet(q1.fPts);
378 SkASSERT(ValidQuad(quad1)); 388 SkASSERT(ValidQuad(quad1));
379 const SkDQuad& quad2 = coincidentTestSet[test2]; 389 const QuadPts& q2 = coincidentTestSet[test2];
390 SkDQuad quad2;
391 quad2.debugSet(q2.fPts);
380 SkASSERT(ValidQuad(quad2)); 392 SkASSERT(ValidQuad(quad2));
381 SkIntersections intersections2; 393 SkIntersections intersections2;
382 intersections2.intersect(quad1, quad2); 394 intersections2.intersect(quad1, quad2);
383 REPORTER_ASSERT(reporter, intersections2.debugCoincidentUsed() >= 2); 395 REPORTER_ASSERT(reporter, intersections2.debugCoincidentUsed() >= 2);
384 REPORTER_ASSERT(reporter, intersections2.used() >= 2); 396 REPORTER_ASSERT(reporter, intersections2.used() >= 2);
385 for (int pt = 0; pt < intersections2.debugCoincidentUsed(); pt += 2) { 397 for (int pt = 0; pt < intersections2.debugCoincidentUsed(); pt += 2) {
386 double tt1 = intersections2[0][pt]; 398 double tt1 = intersections2[0][pt];
387 double tt2 = intersections2[1][pt]; 399 double tt2 = intersections2[1][pt];
388 SkDPoint pt1 = quad1.ptAtT(tt1); 400 SkDPoint pt1 = quad1.ptAtT(tt1);
389 SkDPoint pt2 = quad2.ptAtT(tt2); 401 SkDPoint pt2 = quad2.ptAtT(tt2);
390 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2)); 402 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2));
391 } 403 }
392 } 404 }
393 405
394 static void coincidentTest(skiatest::Reporter* reporter) { 406 static void coincidentTest(skiatest::Reporter* reporter) {
395 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) { 407 for (int testIndex = 0; testIndex < coincidentTestSetCount - 1; testIndex += 2) {
396 coincidentTestOne(reporter, testIndex, testIndex + 1); 408 coincidentTestOne(reporter, testIndex, testIndex + 1);
397 } 409 }
398 } 410 }
399 411
400 static void intersectionFinder(int test1, int test2) { 412 static void intersectionFinder(int test1, int test2) {
401 const SkDQuad& quad1 = testSet[test1]; 413 const QuadPts& q1 = testSet[test1];
402 const SkDQuad& quad2 = testSet[test2]; 414 const QuadPts& q2 = testSet[test2];
403 415 SkDQuad quad1, quad2;
416 quad1.debugSet(q1.fPts);
417 quad2.debugSet(q2.fPts);
404 double t1Seed = 0.5; 418 double t1Seed = 0.5;
405 double t2Seed = 0.8; 419 double t2Seed = 0.8;
406 double t1Step = 0.1; 420 double t1Step = 0.1;
407 double t2Step = 0.1; 421 double t2Step = 0.1;
408 SkDPoint t1[3], t2[3]; 422 SkDPoint t1[3], t2[3];
409 bool toggle = true; 423 bool toggle = true;
410 do { 424 do {
411 t1[0] = quad1.ptAtT(t1Seed - t1Step); 425 t1[0] = quad1.ptAtT(t1Seed - t1Step);
412 t1[1] = quad1.ptAtT(t1Seed); 426 t1[1] = quad1.ptAtT(t1Seed);
413 t1[2] = quad1.ptAtT(t1Seed + t1Step); 427 t1[2] = quad1.ptAtT(t1Seed + t1Step);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 528
515 DEF_TEST(PathOpsQuadBinaryProfile, reporter) { 529 DEF_TEST(PathOpsQuadBinaryProfile, reporter) {
516 if (!FLAGS_veryVerbose) { 530 if (!FLAGS_veryVerbose) {
517 return; 531 return;
518 } 532 }
519 SkIntersections intersections; 533 SkIntersections intersections;
520 for (int x = 0; x < 100; ++x) { 534 for (int x = 0; x < 100; ++x) {
521 int outer = 0; 535 int outer = 0;
522 int inner = outer + 1; 536 int inner = outer + 1;
523 do { 537 do {
524 const SkDQuad& quad1 = testSet[outer]; 538 const QuadPts& q1 = testSet[outer];
525 const SkDQuad& quad2 = testSet[inner]; 539 SkDQuad quad1;
540 quad1.debugSet(q1.fPts);
541 const QuadPts& q2 = testSet[inner];
542 SkDQuad quad2;
543 quad2.debugSet(q2.fPts);
526 (void) intersections.intersect(quad1, quad2); 544 (void) intersections.intersect(quad1, quad2);
527 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed 545 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed
528 inner += 2; 546 inner += 2;
529 outer += 2; 547 outer += 2;
530 } while (outer < (int) testSetCount); 548 } while (outer < (int) testSetCount);
531 } 549 }
532 for (int x = 0; x < 100; ++x) { 550 for (int x = 0; x < 100; ++x) {
533 for (size_t test = 0; test < quadraticTests_count; ++test) { 551 for (size_t test = 0; test < quadraticTests_count; ++test) {
534 const SkDQuad& quad1 = quadraticTests[test][0]; 552 const QuadPts& q1 = quadraticTests[test][0];
535 const SkDQuad& quad2 = quadraticTests[test][1]; 553 const QuadPts& q2 = quadraticTests[test][1];
554 SkDQuad quad1, quad2;
555 quad1.debugSet(q1.fPts);
556 quad2.debugSet(q2.fPts);
536 (void) intersections.intersect(quad1, quad2); 557 (void) intersections.intersect(quad1, quad2);
537 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed 558 REPORTER_ASSERT(reporter, intersections.used() >= 0); // make sure code isn't tossed
538 } 559 }
539 } 560 }
540 } 561 }
OLDNEW
« no previous file with comments | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsQuadIntersectionTestData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698