OLD | NEW |
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 "SkIntersections.h" | 7 #include "SkIntersections.h" |
8 #include "SkOpAngle.h" | 8 #include "SkOpAngle.h" |
9 #include "SkOpSegment.h" | 9 #include "SkOpSegment.h" |
10 #include "SkPathOpsCurve.h" | 10 #include "SkPathOpsCurve.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 314 } |
315 goto recomputeSector; | 315 goto recomputeSector; |
316 } | 316 } |
317 checkEnd += step; | 317 checkEnd += step; |
318 } while (checkEnd != limit); | 318 } while (checkEnd != limit); |
319 recomputeSector: | 319 recomputeSector: |
320 if (checkEnd == fEnd || checkEnd - step == fEnd) { | 320 if (checkEnd == fEnd || checkEnd - step == fEnd) { |
321 fUnorderable = true; | 321 fUnorderable = true; |
322 return false; | 322 return false; |
323 } | 323 } |
| 324 int saveEnd = fEnd; |
324 fEnd = checkEnd - step; | 325 fEnd = checkEnd - step; |
325 setSpans(); | 326 setSpans(); |
326 setSector(); | 327 setSector(); |
| 328 fEnd = saveEnd; |
327 return !fUnorderable; | 329 return !fUnorderable; |
328 } | 330 } |
329 | 331 |
330 // returns -1 if overlaps 0 if no overlap cw 1 if no overlap ccw | 332 // returns -1 if overlaps 0 if no overlap cw 1 if no overlap ccw |
331 int SkOpAngle::convexHullOverlaps(const SkOpAngle& rh) const { | 333 int SkOpAngle::convexHullOverlaps(const SkOpAngle& rh) const { |
332 const SkDVector* sweep = fSweep; | 334 const SkDVector* sweep = fSweep; |
333 const SkDVector* tweep = rh.fSweep; | 335 const SkDVector* tweep = rh.fSweep; |
334 double s0xs1 = sweep[0].crossCheck(sweep[1]); | 336 double s0xs1 = sweep[0].crossCheck(sweep[1]); |
335 double s0xt0 = sweep[0].crossCheck(tweep[0]); | 337 double s0xt0 = sweep[0].crossCheck(tweep[0]); |
336 double s1xt0 = sweep[1].crossCheck(tweep[0]); | 338 double s1xt0 = sweep[1].crossCheck(tweep[0]); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 angle->insert(this); | 653 angle->insert(this); |
652 } | 654 } |
653 return; | 655 return; |
654 } | 656 } |
655 bool singleton = NULL == fNext; | 657 bool singleton = NULL == fNext; |
656 if (singleton) { | 658 if (singleton) { |
657 fNext = this; | 659 fNext = this; |
658 } | 660 } |
659 SkOpAngle* next = fNext; | 661 SkOpAngle* next = fNext; |
660 if (next->fNext == this) { | 662 if (next->fNext == this) { |
| 663 if (angle->overlap(*this)) { |
| 664 return; |
| 665 } |
661 if (singleton || angle->after(this)) { | 666 if (singleton || angle->after(this)) { |
662 this->fNext = angle; | 667 this->fNext = angle; |
663 angle->fNext = next; | 668 angle->fNext = next; |
664 } else { | 669 } else { |
665 next->fNext = angle; | 670 next->fNext = angle; |
666 angle->fNext = this; | 671 angle->fNext = this; |
667 } | 672 } |
668 debugValidateNext(); | 673 debugValidateNext(); |
669 return; | 674 return; |
670 } | 675 } |
671 SkOpAngle* last = this; | 676 SkOpAngle* last = this; |
672 do { | 677 do { |
673 SkASSERT(last->fNext == next); | 678 SkASSERT(last->fNext == next); |
| 679 if (angle->overlap(*last) || angle->overlap(*next)) { |
| 680 return; |
| 681 } |
674 if (angle->after(last)) { | 682 if (angle->after(last)) { |
675 last->fNext = angle; | 683 last->fNext = angle; |
676 angle->fNext = next; | 684 angle->fNext = next; |
677 debugValidateNext(); | 685 debugValidateNext(); |
678 return; | 686 return; |
679 } | 687 } |
680 last = next; | 688 last = next; |
681 next = next->fNext; | 689 next = next->fNext; |
682 if (last == this && next->fUnorderable) { | 690 if (last == this && next->fUnorderable) { |
683 fUnorderable = true; | 691 fUnorderable = true; |
(...skipping 10 matching lines...) Expand all Loading... |
694 SkOpSpan* SkOpAngle::lastMarked() const { | 702 SkOpSpan* SkOpAngle::lastMarked() const { |
695 if (fLastMarked) { | 703 if (fLastMarked) { |
696 if (fLastMarked->fChased) { | 704 if (fLastMarked->fChased) { |
697 return NULL; | 705 return NULL; |
698 } | 706 } |
699 fLastMarked->fChased = true; | 707 fLastMarked->fChased = true; |
700 } | 708 } |
701 return fLastMarked; | 709 return fLastMarked; |
702 } | 710 } |
703 | 711 |
| 712 bool SkOpAngle::loopContains(const SkOpAngle& test) const { |
| 713 if (!fNext) { |
| 714 return false; |
| 715 } |
| 716 const SkOpAngle* first = this; |
| 717 const SkOpAngle* loop = this; |
| 718 const SkOpSegment* tSegment = test.fSegment; |
| 719 double tStart = tSegment->span(test.fStart).fT; |
| 720 double tEnd = tSegment->span(test.fEnd).fT; |
| 721 do { |
| 722 const SkOpSegment* lSegment = loop->fSegment; |
| 723 // FIXME : use precisely_equal ? or compare points exactly ? |
| 724 if (lSegment != tSegment) { |
| 725 continue; |
| 726 } |
| 727 double lStart = lSegment->span(loop->fStart).fT; |
| 728 if (lStart != tEnd) { |
| 729 continue; |
| 730 } |
| 731 double lEnd = lSegment->span(loop->fEnd).fT; |
| 732 if (lEnd == tStart) { |
| 733 return true; |
| 734 } |
| 735 } while ((loop = loop->fNext) != first); |
| 736 return false; |
| 737 } |
| 738 |
704 int SkOpAngle::loopCount() const { | 739 int SkOpAngle::loopCount() const { |
705 int count = 0; | 740 int count = 0; |
706 const SkOpAngle* first = this; | 741 const SkOpAngle* first = this; |
707 const SkOpAngle* next = this; | 742 const SkOpAngle* next = this; |
708 do { | 743 do { |
709 next = next->fNext; | 744 next = next->fNext; |
710 ++count; | 745 ++count; |
711 } while (next && next != first); | 746 } while (next && next != first); |
712 return count; | 747 return count; |
713 } | 748 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 if ((result = convexHullOverlaps(rh)) >= 0) { | 841 if ((result = convexHullOverlaps(rh)) >= 0) { |
807 return result; | 842 return result; |
808 } | 843 } |
809 return endsIntersect(rh); | 844 return endsIntersect(rh); |
810 unorderable: | 845 unorderable: |
811 fUnorderable = true; | 846 fUnorderable = true; |
812 rh.fUnorderable = true; | 847 rh.fUnorderable = true; |
813 return true; | 848 return true; |
814 } | 849 } |
815 | 850 |
| 851 bool SkOpAngle::overlap(const SkOpAngle& other) const { |
| 852 int min = SkTMin(fStart, fEnd); |
| 853 const SkOpSpan& span = fSegment->span(min); |
| 854 const SkOpSegment* oSeg = other.fSegment; |
| 855 int oMin = SkTMin(other.fStart, other.fEnd); |
| 856 const SkOpSpan& oSpan = oSeg->span(oMin); |
| 857 if (!span.fSmall && !oSpan.fSmall) { |
| 858 return false; |
| 859 } |
| 860 if (fSegment->span(fStart).fPt != oSeg->span(other.fStart).fPt) { |
| 861 return false; |
| 862 } |
| 863 // see if small span is contained by opposite span |
| 864 return span.fSmall ? oSeg->containsPt(fSegment->span(fEnd).fPt, other.fEnd,
other.fStart) |
| 865 : fSegment->containsPt(oSeg->span(other.fEnd).fPt, fEnd, fStart); |
| 866 } |
| 867 |
816 // OPTIMIZE: if this shows up in a profile, add a previous pointer | 868 // OPTIMIZE: if this shows up in a profile, add a previous pointer |
817 // as is, this should be rarely called | 869 // as is, this should be rarely called |
818 SkOpAngle* SkOpAngle::previous() const { | 870 SkOpAngle* SkOpAngle::previous() const { |
819 SkOpAngle* last = fNext; | 871 SkOpAngle* last = fNext; |
820 do { | 872 do { |
821 SkOpAngle* next = last->fNext; | 873 SkOpAngle* next = last->fNext; |
822 if (next == this) { | 874 if (next == this) { |
823 return last; | 875 return last; |
824 } | 876 } |
825 last = next; | 877 last = next; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 return true; | 1090 return true; |
1039 } | 1091 } |
1040 SkASSERT(s0dt0 != 0); | 1092 SkASSERT(s0dt0 != 0); |
1041 double m = s0xt0 / s0dt0; | 1093 double m = s0xt0 / s0dt0; |
1042 double sDist = sweep[0].length() * m; | 1094 double sDist = sweep[0].length() * m; |
1043 double tDist = tweep[0].length() * m; | 1095 double tDist = tweep[0].length() * m; |
1044 bool useS = fabs(sDist) < fabs(tDist); | 1096 bool useS = fabs(sDist) < fabs(tDist); |
1045 double mFactor = fabs(useS ? distEndRatio(sDist) : rh.distEndRatio(tDist)); | 1097 double mFactor = fabs(useS ? distEndRatio(sDist) : rh.distEndRatio(tDist)); |
1046 return mFactor < 5000; // empirically found limit | 1098 return mFactor < 5000; // empirically found limit |
1047 } | 1099 } |
OLD | NEW |