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 "SkOpSegment.h" | 8 #include "SkOpSegment.h" |
9 #include "SkPathWriter.h" | 9 #include "SkPathWriter.h" |
10 #include "SkTSort.h" | 10 #include "SkTSort.h" |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 if (!span->fWindValue && !span->fOppValue) { | 1075 if (!span->fWindValue && !span->fOppValue) { |
1076 span->fDone = true; | 1076 span->fDone = true; |
1077 ++fDoneSpans; | 1077 ++fDoneSpans; |
1078 return true; | 1078 return true; |
1079 } | 1079 } |
1080 return false; | 1080 return false; |
1081 } | 1081 } |
1082 | 1082 |
1083 // look to see if the curve end intersects an intermediary that intersects the o ther | 1083 // look to see if the curve end intersects an intermediary that intersects the o ther |
1084 void SkOpSegment::checkEnds() { | 1084 void SkOpSegment::checkEnds() { |
1085 #if 1 | 1085 #if 0 |
1086 return; // FIXME: suspect we will need the code below to make intersections consistent | 1086 return; // FIXME: suspect we will need the code below to make intersections consistent |
1087 #else | 1087 #else |
1088 debugValidate(); | |
1088 SkTDArray<SkOpSpan> missingSpans; | 1089 SkTDArray<SkOpSpan> missingSpans; |
1089 int count = fTs.count(); | 1090 int count = fTs.count(); |
1090 for (int index = 0; index < count; ++index) { | 1091 for (int index = 0; index < count; ++index) { |
1091 const SkOpSpan& span = fTs[index]; | 1092 const SkOpSpan& span = fTs[index]; |
1092 const SkOpSegment* other = span.fOther; | 1093 const SkOpSegment* other = span.fOther; |
1093 const SkOpSpan* otherSpan = &other->fTs[span.fOtherIndex]; | 1094 const SkOpSpan* otherSpan = &other->fTs[span.fOtherIndex]; |
1094 double otherT = otherSpan->fT; | 1095 double otherT = otherSpan->fT; |
1095 if (otherT != 0 && otherT != 1) { | 1096 if (otherT != 0 && otherT != 1) { |
1096 continue; | 1097 continue; |
1097 } | 1098 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 SkOpSpan* missing = missingSpans.append(); | 1144 SkOpSpan* missing = missingSpans.append(); |
1144 missing->fT = t; | 1145 missing->fT = t; |
1145 missing->fOther = match; | 1146 missing->fOther = match; |
1146 missing->fOtherT = matchT; | 1147 missing->fOtherT = matchT; |
1147 missing->fPt = peekSpan.fPt; | 1148 missing->fPt = peekSpan.fPt; |
1148 } | 1149 } |
1149 nextPeeker: | 1150 nextPeeker: |
1150 ; | 1151 ; |
1151 } | 1152 } |
1152 int missingCount = missingSpans.count(); | 1153 int missingCount = missingSpans.count(); |
1154 if (missingCount == 0) { | |
1155 return; | |
1156 } | |
1157 debugValidate(); | |
1153 for (int index = 0; index < missingCount; ++index) { | 1158 for (int index = 0; index < missingCount; ++index) { |
1154 const SkOpSpan& missing = missingSpans[index]; | 1159 const SkOpSpan& missing = missingSpans[index]; |
1155 addTPair(missing.fT, missing.fOther, missing.fOtherT, false, missing.fPt ); | 1160 addTPair(missing.fT, missing.fOther, missing.fOtherT, false, missing.fPt ); |
1156 } | 1161 } |
1157 if (missingCount > 0) { | 1162 fixOtherTIndex(); |
1158 fixOtherTIndex(); | 1163 for (int index = 0; index < missingCount; ++index) { |
1164 const SkOpSpan& missing = missingSpans[index]; | |
1165 missing.fOther->fixOtherTIndex(); | |
1159 } | 1166 } |
1167 debugValidate(); | |
1160 #endif | 1168 #endif |
1161 } | 1169 } |
1162 | 1170 |
1163 bool SkOpSegment::equalPoints(int greaterTIndex, int lesserTIndex) { | 1171 bool SkOpSegment::equalPoints(int greaterTIndex, int lesserTIndex) { |
1164 SkASSERT(greaterTIndex >= lesserTIndex); | 1172 SkASSERT(greaterTIndex >= lesserTIndex); |
1165 double greaterT = fTs[greaterTIndex].fT; | 1173 double greaterT = fTs[greaterTIndex].fT; |
1166 double lesserT = fTs[lesserTIndex].fT; | 1174 double lesserT = fTs[lesserTIndex].fT; |
1167 if (greaterT == lesserT) { | 1175 if (greaterT == lesserT) { |
1168 return true; | 1176 return true; |
1169 } | 1177 } |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1785 // while the following fixes the indices up again, it isn't smart about | 1793 // while the following fixes the indices up again, it isn't smart about |
1786 // skipping segments whose indices are already correct | 1794 // skipping segments whose indices are already correct |
1787 // assuming we leave the code that wrote the index in the first place | 1795 // assuming we leave the code that wrote the index in the first place |
1788 void SkOpSegment::fixOtherTIndex() { | 1796 void SkOpSegment::fixOtherTIndex() { |
1789 int iCount = fTs.count(); | 1797 int iCount = fTs.count(); |
1790 for (int i = 0; i < iCount; ++i) { | 1798 for (int i = 0; i < iCount; ++i) { |
1791 SkOpSpan& iSpan = fTs[i]; | 1799 SkOpSpan& iSpan = fTs[i]; |
1792 double oT = iSpan.fOtherT; | 1800 double oT = iSpan.fOtherT; |
1793 SkOpSegment* other = iSpan.fOther; | 1801 SkOpSegment* other = iSpan.fOther; |
1794 int oCount = other->fTs.count(); | 1802 int oCount = other->fTs.count(); |
1803 SkDEBUGCODE(iSpan.fOtherIndex = -1); | |
1795 for (int o = 0; o < oCount; ++o) { | 1804 for (int o = 0; o < oCount; ++o) { |
1796 SkOpSpan& oSpan = other->fTs[o]; | 1805 SkOpSpan& oSpan = other->fTs[o]; |
1797 if (oT == oSpan.fT && this == oSpan.fOther && oSpan.fOtherT == iSpan .fT) { | 1806 if (oT == oSpan.fT && this == oSpan.fOther && oSpan.fOtherT == iSpan .fT) { |
1798 iSpan.fOtherIndex = o; | 1807 iSpan.fOtherIndex = o; |
1808 oSpan.fOtherIndex = i; | |
1799 break; | 1809 break; |
1800 } | 1810 } |
1801 } | 1811 } |
1812 SkASSERT(iSpan.fOtherIndex >= 0); | |
1802 } | 1813 } |
1803 } | 1814 } |
1804 | 1815 |
1805 void SkOpSegment::init(const SkPoint pts[], SkPath::Verb verb, bool operand, boo l evenOdd) { | 1816 void SkOpSegment::init(const SkPoint pts[], SkPath::Verb verb, bool operand, boo l evenOdd) { |
1806 fDoneSpans = 0; | 1817 fDoneSpans = 0; |
1807 fOperand = operand; | 1818 fOperand = operand; |
1808 fXor = evenOdd; | 1819 fXor = evenOdd; |
1809 fPts = pts; | 1820 fPts = pts; |
1810 fVerb = verb; | 1821 fVerb = verb; |
1811 } | 1822 } |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2748 } | 2759 } |
2749 if (done()) { | 2760 if (done()) { |
2750 SkDebugf(" done"); | 2761 SkDebugf(" done"); |
2751 } | 2762 } |
2752 SkDebugf("\n"); | 2763 SkDebugf("\n"); |
2753 } | 2764 } |
2754 #endif | 2765 #endif |
2755 | 2766 |
2756 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY | 2767 #if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY |
2757 void SkOpSegment::debugShowActiveSpans() const { | 2768 void SkOpSegment::debugShowActiveSpans() const { |
2769 debugValidate(); | |
2758 if (done()) { | 2770 if (done()) { |
2759 return; | 2771 return; |
2760 } | 2772 } |
2761 #if DEBUG_ACTIVE_SPANS_SHORT_FORM | 2773 #if DEBUG_ACTIVE_SPANS_SHORT_FORM |
2762 int lastId = -1; | 2774 int lastId = -1; |
2763 double lastT = -1; | 2775 double lastT = -1; |
2764 #endif | 2776 #endif |
2765 for (int i = 0; i < fTs.count(); ++i) { | 2777 for (int i = 0; i < fTs.count(); ++i) { |
2766 SkASSERT(&fTs[i] == &fTs[i].fOther->fTs[fTs[i].fOtherIndex].fOther-> | |
2767 fTs[fTs[i].fOther->fTs[fTs[i].fOtherIndex].fOtherIndex]); | |
2768 if (fTs[i].fDone) { | 2778 if (fTs[i].fDone) { |
2769 continue; | 2779 continue; |
2770 } | 2780 } |
2771 SkASSERT(i < fTs.count() - 1); | 2781 SkASSERT(i < fTs.count() - 1); |
2772 #if DEBUG_ACTIVE_SPANS_SHORT_FORM | 2782 #if DEBUG_ACTIVE_SPANS_SHORT_FORM |
2773 if (lastId == fID && lastT == fTs[i].fT) { | 2783 if (lastId == fID && lastT == fTs[i].fT) { |
2774 continue; | 2784 continue; |
2775 } | 2785 } |
2776 lastId = fID; | 2786 lastId = fID; |
2777 lastT = fTs[i].fT; | 2787 lastT = fTs[i].fT; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2988 sum += fTs[i].fWindValue; | 2998 sum += fTs[i].fWindValue; |
2989 slots[fTs[i].fOther->fID - 1] = as_digit(fTs[i].fWindValue); | 2999 slots[fTs[i].fOther->fID - 1] = as_digit(fTs[i].fWindValue); |
2990 sum += fTs[i].fOppValue; | 3000 sum += fTs[i].fOppValue; |
2991 slots[slotCount + fTs[i].fOther->fID - 1] = as_digit(fTs[i].fOppValue); | 3001 slots[slotCount + fTs[i].fOther->fID - 1] = as_digit(fTs[i].fOppValue); |
2992 } | 3002 } |
2993 SkDebugf("%s id=%2d %.*s | %.*s\n", __FUNCTION__, fID, slotCount, slots.begi n(), slotCount, | 3003 SkDebugf("%s id=%2d %.*s | %.*s\n", __FUNCTION__, fID, slotCount, slots.begi n(), slotCount, |
2994 slots.begin() + slotCount); | 3004 slots.begin() + slotCount); |
2995 return sum; | 3005 return sum; |
2996 } | 3006 } |
2997 #endif | 3007 #endif |
3008 | |
3009 void SkOpSegment::debugValidate() const { | |
3010 #if SK_DEBUG | |
fmalita_google_do_not_use
2013/07/18 18:31:28
When building Chrome, I had to change this to #ifd
| |
3011 int count = fTs.count(); | |
3012 SkASSERT(count >= 2); | |
3013 SkASSERT(fTs[0].fT == 0); | |
3014 SkASSERT(fTs[count - 1].fT == 1); | |
3015 int done = 0; | |
3016 double t = -1; | |
3017 for (int i = 0; i < count; ++i) { | |
3018 const SkOpSpan& span = fTs[i]; | |
3019 SkASSERT(t <= span.fT); | |
3020 t = span.fT; | |
3021 int otherIndex = span.fOtherIndex; | |
3022 const SkOpSegment* other = span.fOther; | |
3023 const SkOpSpan& otherSpan = other->fTs[otherIndex]; | |
3024 SkASSERT(otherSpan.fPt == span.fPt); | |
3025 SkASSERT(otherSpan.fOtherT == t); | |
3026 SkASSERT(&fTs[i] == &otherSpan.fOther->fTs[otherSpan.fOtherIndex]); | |
3027 done += span.fDone; | |
3028 } | |
3029 SkASSERT(done == fDoneSpans); | |
3030 #endif | |
3031 } | |
OLD | NEW |