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

Side by Side Diff: src/pathops/SkOpContour.cpp

Issue 585913002: fail early if coincidence can't be resolved (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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/SkOpContour.h ('k') | src/pathops/SkOpSegment.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 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 "SkIntersections.h" 7 #include "SkIntersections.h"
8 #include "SkOpContour.h" 8 #include "SkOpContour.h"
9 #include "SkPathWriter.h" 9 #include "SkPathWriter.h"
10 #include "SkTSort.h" 10 #include "SkTSort.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 bool SkOpContour::calcAngles() { 260 bool SkOpContour::calcAngles() {
261 int segmentCount = fSegments.count(); 261 int segmentCount = fSegments.count();
262 for (int test = 0; test < segmentCount; ++test) { 262 for (int test = 0; test < segmentCount; ++test) {
263 if (!fSegments[test].calcAngles()) { 263 if (!fSegments[test].calcAngles()) {
264 return false; 264 return false;
265 } 265 }
266 } 266 }
267 return true; 267 return true;
268 } 268 }
269 269
270 void SkOpContour::calcCoincidentWinding() { 270 bool SkOpContour::calcCoincidentWinding() {
271 int count = fCoincidences.count(); 271 int count = fCoincidences.count();
272 #if DEBUG_CONCIDENT 272 #if DEBUG_CONCIDENT
273 if (count > 0) { 273 if (count > 0) {
274 SkDebugf("%s count=%d\n", __FUNCTION__, count); 274 SkDebugf("%s count=%d\n", __FUNCTION__, count);
275 } 275 }
276 #endif 276 #endif
277 for (int index = 0; index < count; ++index) { 277 for (int index = 0; index < count; ++index) {
278 SkCoincidence& coincidence = fCoincidences[index]; 278 SkCoincidence& coincidence = fCoincidences[index];
279 calcCommonCoincidentWinding(coincidence); 279 if (!calcCommonCoincidentWinding(coincidence)) {
280 return false;
281 }
280 } 282 }
283 return true;
281 } 284 }
282 285
283 void SkOpContour::calcPartialCoincidentWinding() { 286 void SkOpContour::calcPartialCoincidentWinding() {
284 int count = fPartialCoincidences.count(); 287 int count = fPartialCoincidences.count();
285 #if DEBUG_CONCIDENT 288 #if DEBUG_CONCIDENT
286 if (count > 0) { 289 if (count > 0) {
287 SkDebugf("%s count=%d\n", __FUNCTION__, count); 290 SkDebugf("%s count=%d\n", __FUNCTION__, count);
288 } 291 }
289 #endif 292 #endif
290 for (int index = 0; index < count; ++index) { 293 for (int index = 0; index < count; ++index) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 SkTSwap(missingPt1, missingPt2); 467 SkTSwap(missingPt1, missingPt2);
465 } 468 }
466 addTo1->addTCancel(missingPt1, missingPt2, addOther1); 469 addTo1->addTCancel(missingPt1, missingPt2, addOther1);
467 } else { 470 } else {
468 if (addTo2->reversePoints(missingPt1, missingPt2)) { 471 if (addTo2->reversePoints(missingPt1, missingPt2)) {
469 SkTSwap(missingPt1, missingPt2); 472 SkTSwap(missingPt1, missingPt2);
470 } 473 }
471 addTo2->addTCancel(missingPt1, missingPt2, addOther2); 474 addTo2->addTCancel(missingPt1, missingPt2, addOther2);
472 } 475 }
473 } else if (missingT1 >= 0) { 476 } else if (missingT1 >= 0) {
474 addTo1->addTCoincident(missingPt1, missingPt2, addTo1 == addTo2 ? missin gT2 : otherT2, 477 SkAssertResult(addTo1->addTCoincident(missingPt1, missingPt2,
475 addOther1); 478 addTo1 == addTo2 ? missingT2 : otherT2, addOther1));
476 } else { 479 } else {
477 addTo2->addTCoincident(missingPt2, missingPt1, addTo2 == addTo1 ? missin gT1 : otherT1, 480 SkAssertResult(addTo2->addTCoincident(missingPt2, missingPt1,
478 addOther2); 481 addTo2 == addTo1 ? missingT1 : otherT1, addOther2));
479 } 482 }
480 } 483 }
481 484
482 void SkOpContour::joinCoincidence(const SkTArray<SkCoincidence, true>& coinciden ces, bool partial) { 485 void SkOpContour::joinCoincidence(const SkTArray<SkCoincidence, true>& coinciden ces, bool partial) {
483 int count = coincidences.count(); 486 int count = coincidences.count();
484 #if DEBUG_CONCIDENT 487 #if DEBUG_CONCIDENT
485 if (count > 0) { 488 if (count > 0) {
486 SkDebugf("%s count=%d\n", __FUNCTION__, count); 489 SkDebugf("%s count=%d\n", __FUNCTION__, count);
487 } 490 }
488 #endif 491 #endif
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 double oMatchEnd = cancel ? oStartT : oEndT; 539 double oMatchEnd = cancel ? oStartT : oEndT;
537 if (partial ? endT != 1 || oMatchEnd != 1 : (endT == 1) != (oMatchEnd == 1)) { 540 if (partial ? endT != 1 || oMatchEnd != 1 : (endT == 1) != (oMatchEnd == 1)) {
538 bool added = false; 541 bool added = false;
539 if (cancel && endT != 1 && !added) { 542 if (cancel && endT != 1 && !added) {
540 (void) other.joinCoincidence(&thisOne, endT, *endPt, -step, canc el); 543 (void) other.joinCoincidence(&thisOne, endT, *endPt, -step, canc el);
541 } 544 }
542 } 545 }
543 } 546 }
544 } 547 }
545 548
546 void SkOpContour::calcCommonCoincidentWinding(const SkCoincidence& coincidence) { 549 bool SkOpContour::calcCommonCoincidentWinding(const SkCoincidence& coincidence) {
547 if (coincidence.fNearly[0] && coincidence.fNearly[1]) { 550 if (coincidence.fNearly[0] && coincidence.fNearly[1]) {
548 return; 551 return true;
549 } 552 }
550 int thisIndex = coincidence.fSegments[0]; 553 int thisIndex = coincidence.fSegments[0];
551 SkOpSegment& thisOne = fSegments[thisIndex]; 554 SkOpSegment& thisOne = fSegments[thisIndex];
552 if (thisOne.done()) { 555 if (thisOne.done()) {
553 return; 556 return true;
554 } 557 }
555 SkOpContour* otherContour = coincidence.fOther; 558 SkOpContour* otherContour = coincidence.fOther;
556 int otherIndex = coincidence.fSegments[1]; 559 int otherIndex = coincidence.fSegments[1];
557 SkOpSegment& other = otherContour->fSegments[otherIndex]; 560 SkOpSegment& other = otherContour->fSegments[otherIndex];
558 if (other.done()) { 561 if (other.done()) {
559 return; 562 return true;
560 } 563 }
561 double startT = coincidence.fTs[0][0]; 564 double startT = coincidence.fTs[0][0];
562 double endT = coincidence.fTs[0][1]; 565 double endT = coincidence.fTs[0][1];
563 const SkPoint* startPt = &coincidence.fPts[0][0]; 566 const SkPoint* startPt = &coincidence.fPts[0][0];
564 const SkPoint* endPt = &coincidence.fPts[0][1]; 567 const SkPoint* endPt = &coincidence.fPts[0][1];
565 bool cancelers; 568 bool cancelers;
566 if ((cancelers = startT > endT)) { 569 if ((cancelers = startT > endT)) {
567 SkTSwap<double>(startT, endT); 570 SkTSwap<double>(startT, endT);
568 SkTSwap<const SkPoint*>(startPt, endPt); 571 SkTSwap<const SkPoint*>(startPt, endPt);
569 } 572 }
570 bump_out_close_span(&startT, &endT); 573 bump_out_close_span(&startT, &endT);
571 SkASSERT(!approximately_negative(endT - startT)); 574 SkASSERT(!approximately_negative(endT - startT));
572 double oStartT = coincidence.fTs[1][0]; 575 double oStartT = coincidence.fTs[1][0];
573 double oEndT = coincidence.fTs[1][1]; 576 double oEndT = coincidence.fTs[1][1];
574 if (oStartT > oEndT) { 577 if (oStartT > oEndT) {
575 SkTSwap<double>(oStartT, oEndT); 578 SkTSwap<double>(oStartT, oEndT);
576 cancelers ^= true; 579 cancelers ^= true;
577 } 580 }
578 bump_out_close_span(&oStartT, &oEndT); 581 bump_out_close_span(&oStartT, &oEndT);
579 SkASSERT(!approximately_negative(oEndT - oStartT)); 582 SkASSERT(!approximately_negative(oEndT - oStartT));
583 bool success = true;
580 if (cancelers) { 584 if (cancelers) {
581 thisOne.addTCancel(*startPt, *endPt, &other); 585 thisOne.addTCancel(*startPt, *endPt, &other);
582 } else { 586 } else {
583 thisOne.addTCoincident(*startPt, *endPt, endT, &other); 587 success = thisOne.addTCoincident(*startPt, *endPt, endT, &other);
584 } 588 }
585 #if DEBUG_CONCIDENT 589 #if DEBUG_CONCIDENT
586 thisOne.debugShowTs("p"); 590 thisOne.debugShowTs("p");
587 other.debugShowTs("o"); 591 other.debugShowTs("o");
588 #endif 592 #endif
593 return success;
589 } 594 }
590 595
591 void SkOpContour::resolveNearCoincidence() { 596 void SkOpContour::resolveNearCoincidence() {
592 int count = fCoincidences.count(); 597 int count = fCoincidences.count();
593 for (int index = 0; index < count; ++index) { 598 for (int index = 0; index < count; ++index) {
594 SkCoincidence& coincidence = fCoincidences[index]; 599 SkCoincidence& coincidence = fCoincidences[index];
595 if (!coincidence.fNearly[0] || !coincidence.fNearly[1]) { 600 if (!coincidence.fNearly[0] || !coincidence.fNearly[1]) {
596 continue; 601 continue;
597 } 602 }
598 int thisIndex = coincidence.fSegments[0]; 603 int thisIndex = coincidence.fSegments[0];
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 SkDebugf("%s empty contour\n", __FUNCTION__); 753 SkDebugf("%s empty contour\n", __FUNCTION__);
749 SkASSERT(0); 754 SkASSERT(0);
750 // FIXME: delete empty contour? 755 // FIXME: delete empty contour?
751 return; 756 return;
752 } 757 }
753 fBounds = fSegments.front().bounds(); 758 fBounds = fSegments.front().bounds();
754 for (int index = 1; index < count; ++index) { 759 for (int index = 1; index < count; ++index) {
755 fBounds.add(fSegments[index].bounds()); 760 fBounds.add(fSegments[index].bounds());
756 } 761 }
757 } 762 }
OLDNEW
« no previous file with comments | « src/pathops/SkOpContour.h ('k') | src/pathops/SkOpSegment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698