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

Side by Side Diff: tests/PathOpsAngleIdeas.cpp

Issue 1002693002: pathops version two (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix arm 64 inspired coincident handling Created 5 years, 9 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 | « src/pathops/SkReduceOrder.cpp ('k') | tests/PathOpsAngleTest.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 2013 Google Inc. 2 * Copyright 2013 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 "SkOpContour.h"
9 #include "SkOpSegment.h" 10 #include "SkOpSegment.h"
10 #include "SkPathOpsTriangle.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkTArray.h" 12 #include "SkTArray.h"
13 #include "SkTSort.h" 13 #include "SkTSort.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static bool gPathOpsAngleIdeasVerbose = false; 16 static bool gPathOpsAngleIdeasVerbose = false;
17 static bool gPathOpsAngleIdeasEnableBruteCheck = false; 17 static bool gPathOpsAngleIdeasEnableBruteCheck = false;
18 18
19 class PathOpsAngleTester { 19 class PathOpsAngleTester {
20 public: 20 public:
21 static int ConvexHullOverlaps(const SkOpAngle& lh, const SkOpAngle& rh) { 21 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) {
22 return lh.convexHullOverlaps(rh); 22 return lh.convexHullOverlaps(&rh);
23 } 23 }
24 24
25 static int EndsIntersect(const SkOpAngle& lh, const SkOpAngle& rh) { 25 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) {
26 return lh.endsIntersect(rh); 26 return lh.endsIntersect(&rh);
27 } 27 }
28 }; 28 };
29 29
30 struct TRange { 30 struct TRange {
31 double tMin1; 31 double tMin1;
32 double tMin2; 32 double tMin2;
33 double t1; 33 double t1;
34 double t2; 34 double t2;
35 double tMin; 35 double tMin;
36 double a1; 36 double a1;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 399 }
400 400
401 static bool bruteForceCheck(skiatest::Reporter* reporter, const SkDQuad& quad1, 401 static bool bruteForceCheck(skiatest::Reporter* reporter, const SkDQuad& quad1,
402 const SkDQuad& quad2, bool ccw) { 402 const SkDQuad& quad2, bool ccw) {
403 TRange lowerRange, upperRange; 403 TRange lowerRange, upperRange;
404 bool result = bruteMinT(reporter, quad1, quad2, &lowerRange, &upperRange); 404 bool result = bruteMinT(reporter, quad1, quad2, &lowerRange, &upperRange);
405 REPORTER_ASSERT(reporter, result); 405 REPORTER_ASSERT(reporter, result);
406 return ccw == upperRange.ccw; 406 return ccw == upperRange.ccw;
407 } 407 }
408 408
409 class PathOpsSegmentTester { 409 static void makeSegment(SkOpContour* contour, const SkDQuad& quad, SkPoint short Quad[3],
410 public: 410 SkChunkAlloc* allocator) {
411 static void ConstructQuad(SkOpSegment* segment, SkPoint shortQuad[3]) {
412 segment->debugConstructQuad(shortQuad);
413 }
414 };
415
416 static void makeSegment(const SkDQuad& quad, SkPoint shortQuad[3], SkOpSegment* result) {
417 shortQuad[0] = quad[0].asSkPoint(); 411 shortQuad[0] = quad[0].asSkPoint();
418 shortQuad[1] = quad[1].asSkPoint(); 412 shortQuad[1] = quad[1].asSkPoint();
419 shortQuad[2] = quad[2].asSkPoint(); 413 shortQuad[2] = quad[2].asSkPoint();
420 PathOpsSegmentTester::ConstructQuad(result, shortQuad); 414 contour->addQuad(shortQuad, allocator);
421 } 415 }
422 416
423 static void testQuadAngles(skiatest::Reporter* reporter, const SkDQuad& quad1, c onst SkDQuad& quad2, 417 static void testQuadAngles(skiatest::Reporter* reporter, const SkDQuad& quad1, c onst SkDQuad& quad2,
424 int testNo) { 418 int testNo, SkChunkAlloc* allocator) {
425 SkPoint shortQuads[2][3]; 419 SkPoint shortQuads[2][3];
426 SkOpSegment seg[2]; 420
427 makeSegment(quad1, shortQuads[0], &seg[0]); 421 SkOpContour contour;
428 makeSegment(quad2, shortQuads[1], &seg[1]); 422 SkOpGlobalState state(NULL PATH_OPS_DEBUG_PARAMS(&contour));
429 int realOverlap = PathOpsAngleTester::ConvexHullOverlaps(*seg[0].debugLastAn gle(), 423 contour.init(&state, false, false);
430 *seg[1].debugLastAngle()); 424 makeSegment(&contour, quad1, shortQuads[0], allocator);
425 makeSegment(&contour, quad1, shortQuads[1], allocator);
426 SkOpSegment* seg1 = contour.first();
427 seg1->debugAddAngle(0, 1, allocator);
428 SkOpSegment* seg2 = seg1->next();
429 seg2->debugAddAngle(0, 1, allocator);
430 int realOverlap = PathOpsAngleTester::ConvexHullOverlaps(*seg1->debugLastAng le(),
431 *seg2->debugLastAngle());
431 const SkDPoint& origin = quad1[0]; 432 const SkDPoint& origin = quad1[0];
432 REPORTER_ASSERT(reporter, origin == quad2[0]); 433 REPORTER_ASSERT(reporter, origin == quad2[0]);
433 double a1s = atan2(origin.fY - quad1[1].fY, quad1[1].fX - origin.fX); 434 double a1s = atan2(origin.fY - quad1[1].fY, quad1[1].fX - origin.fX);
434 double a1e = atan2(origin.fY - quad1[2].fY, quad1[2].fX - origin.fX); 435 double a1e = atan2(origin.fY - quad1[2].fY, quad1[2].fX - origin.fX);
435 double a2s = atan2(origin.fY - quad2[1].fY, quad2[1].fX - origin.fX); 436 double a2s = atan2(origin.fY - quad2[1].fY, quad2[1].fX - origin.fX);
436 double a2e = atan2(origin.fY - quad2[2].fY, quad2[2].fX - origin.fX); 437 double a2e = atan2(origin.fY - quad2[2].fY, quad2[2].fX - origin.fX);
437 bool oldSchoolOverlap = radianBetween(a1s, a2s, a1e) 438 bool oldSchoolOverlap = radianBetween(a1s, a2s, a1e)
438 || radianBetween(a1s, a2e, a1e) || radianBetween(a2s, a1s, a2e) 439 || radianBetween(a1s, a2e, a1e) || radianBetween(a2s, a1s, a2e)
439 || radianBetween(a2s, a1e, a2e); 440 || radianBetween(a2s, a1e, a2e);
440 int overlap = quadHullsOverlap(reporter, quad1, quad2); 441 int overlap = quadHullsOverlap(reporter, quad1, quad2);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 SkASSERT(SkScalarSignAsInt(SkDoubleToScalar(midXray)) 539 SkASSERT(SkScalarSignAsInt(SkDoubleToScalar(midXray))
539 == SkScalarSignAsInt(SkDoubleToScalar(vDir[sIndex]))); 540 == SkScalarSignAsInt(SkDoubleToScalar(vDir[sIndex])));
540 firstInside = (rayDist > endDist) ^ (sIndex == 0) ^ (vDir[sIndex] < 0); 541 firstInside = (rayDist > endDist) ^ (sIndex == 0) ^ (vDir[sIndex] < 0);
541 } else if (overlap >= 0) { 542 } else if (overlap >= 0) {
542 return; // answer has already been determined 543 return; // answer has already been determined
543 } else { 544 } else {
544 firstInside = checkParallel(reporter, quad1, quad2); 545 firstInside = checkParallel(reporter, quad1, quad2);
545 } 546 }
546 if (overlap < 0) { 547 if (overlap < 0) {
547 SkDEBUGCODE(int realEnds =) 548 SkDEBUGCODE(int realEnds =)
548 PathOpsAngleTester::EndsIntersect(*seg[0].debugLastAngle(), 549 PathOpsAngleTester::EndsIntersect(*seg1->debugLastAngle(),
549 *seg[1].debugLastAngle()); 550 *seg2->debugLastAngle());
550 SkASSERT(realEnds == (firstInside ? 1 : 0)); 551 SkASSERT(realEnds == (firstInside ? 1 : 0));
551 } 552 }
552 bruteForce(reporter, quad1, quad2, firstInside); 553 bruteForce(reporter, quad1, quad2, firstInside);
553 } 554 }
554 555
555 DEF_TEST(PathOpsAngleOverlapHullsOne, reporter) { 556 DEF_TEST(PathOpsAngleOverlapHullsOne, reporter) {
557 SkChunkAlloc allocator(4096);
556 // gPathOpsAngleIdeasVerbose = true; 558 // gPathOpsAngleIdeasVerbose = true;
557 const SkDQuad quads[] = { 559 const SkDQuad quads[] = {
558 {{{939.4808349609375, 914.355224609375}, {-357.7921142578125, 590.842529296875}, {736.8936767578125, -350.717529296875}}}, 560 {{{939.4808349609375, 914.355224609375}, {-357.7921142578125, 590.842529296875}, {736.8936767578125, -350.717529296875}}},
559 {{{939.4808349609375, 914.355224609375}, {-182.85418701171875, 634.4552001953125 }, {-509.62615966796875, 576.1182861328125}}} 561 {{{939.4808349609375, 914.355224609375}, {-182.85418701171875, 634.4552001953125 }, {-509.62615966796875, 576.1182861328125}}}
560 }; 562 };
561 for (int index = 0; index < (int) SK_ARRAY_COUNT(quads); index += 2) { 563 for (int index = 0; index < (int) SK_ARRAY_COUNT(quads); index += 2) {
562 testQuadAngles(reporter, quads[index], quads[index + 1], 0); 564 testQuadAngles(reporter, quads[index], quads[index + 1], 0, &allocator);
563 } 565 }
564 } 566 }
565 567
566 DEF_TEST(PathOpsAngleOverlapHulls, reporter) { 568 DEF_TEST(PathOpsAngleOverlapHulls, reporter) {
569 SkChunkAlloc allocator(4096);
567 if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default 570 if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default
568 return; 571 return;
569 } 572 }
570 SkRandom ran; 573 SkRandom ran;
571 for (int index = 0; index < 100000; ++index) { 574 for (int index = 0; index < 100000; ++index) {
572 if (index % 1000 == 999) SkDebugf("."); 575 if (index % 1000 == 999) SkDebugf(".");
573 SkDPoint origin = {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 10 00)}; 576 SkDPoint origin = {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 10 00)};
574 SkDQuad quad1 = {{origin, {ran.nextRangeF(-1000, 1000), ran.nextRangeF(- 1000, 1000)}, 577 SkDQuad quad1 = {{origin, {ran.nextRangeF(-1000, 1000), ran.nextRangeF(- 1000, 1000)},
575 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}}}; 578 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}}};
576 if (quad1[0] == quad1[2]) { 579 if (quad1[0] == quad1[2]) {
577 continue; 580 continue;
578 } 581 }
579 SkDQuad quad2 = {{origin, {ran.nextRangeF(-1000, 1000), ran.nextRangeF(- 1000, 1000)}, 582 SkDQuad quad2 = {{origin, {ran.nextRangeF(-1000, 1000), ran.nextRangeF(- 1000, 1000)},
580 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}}}; 583 {ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}}};
581 if (quad2[0] == quad2[2]) { 584 if (quad2[0] == quad2[2]) {
582 continue; 585 continue;
583 } 586 }
584 SkIntersections i; 587 SkIntersections i;
585 i.intersect(quad1, quad2); 588 i.intersect(quad1, quad2);
586 REPORTER_ASSERT(reporter, i.used() >= 1); 589 REPORTER_ASSERT(reporter, i.used() >= 1);
587 if (i.used() > 1) { 590 if (i.used() > 1) {
588 continue; 591 continue;
589 } 592 }
590 testQuadAngles(reporter, quad1, quad2, index); 593 testQuadAngles(reporter, quad1, quad2, index, &allocator);
591 } 594 }
592 } 595 }
593 596
594 DEF_TEST(PathOpsAngleBruteT, reporter) { 597 DEF_TEST(PathOpsAngleBruteT, reporter) {
595 if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default 598 if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default
596 return; 599 return;
597 } 600 }
598 SkRandom ran; 601 SkRandom ran;
599 double smaller = SK_Scalar1; 602 double smaller = SK_Scalar1;
600 SkDQuad small[2]; 603 SkDQuad small[2];
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 step /= 2; 854 step /= 2;
852 } 855 }
853 #ifdef SK_DEBUG 856 #ifdef SK_DEBUG
854 // DumpQ(q1, q2, 999); 857 // DumpQ(q1, q2, 999);
855 #endif 858 #endif
856 } 859 }
857 if (gPathOpsAngleIdeasVerbose) { 860 if (gPathOpsAngleIdeasVerbose) {
858 SkDebugf("maxR=%1.9g\n", maxR); 861 SkDebugf("maxR=%1.9g\n", maxR);
859 } 862 }
860 } 863 }
OLDNEW
« no previous file with comments | « src/pathops/SkReduceOrder.cpp ('k') | tests/PathOpsAngleTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698