caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef SkOpSpan_DEFINED |
| 8 | #define SkOpSpan_DEFINED |
| 9 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 10 | #include "SkPathOpsDebug.h" |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 11 | #include "SkPathOpsTypes.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | #include "SkPoint.h" |
| 13 | |
Herb Derby | c3cc5fa | 2017-03-07 11:11:47 -0500 | [diff] [blame] | 14 | class SkArenaAlloc; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 15 | class SkOpAngle; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 16 | class SkOpContour; |
| 17 | class SkOpGlobalState; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 18 | class SkOpSegment; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 19 | class SkOpSpanBase; |
| 20 | class SkOpSpan; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 21 | struct SkPathOpsBounds; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 23 | // subset of op span used by terminal span (when t is equal to one) |
| 24 | class SkOpPtT { |
| 25 | public: |
| 26 | enum { |
| 27 | kIsAlias = 1, |
| 28 | kIsDuplicate = 1 |
| 29 | }; |
| 30 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 31 | const SkOpPtT* active() const; |
| 32 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 33 | // please keep in sync with debugAddOpp() |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 34 | void addOpp(SkOpPtT* opp, SkOpPtT* oppPrev) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 35 | SkOpPtT* oldNext = this->fNext; |
| 36 | SkASSERT(this != opp); |
| 37 | this->fNext = opp; |
| 38 | SkASSERT(oppPrev != oldNext); |
| 39 | oppPrev->fNext = oldNext; |
| 40 | } |
| 41 | |
| 42 | bool alias() const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 43 | bool coincident() const { return fCoincident; } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 44 | bool contains(const SkOpPtT* ) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 45 | bool contains(const SkOpSegment*, const SkPoint& ) const; |
| 46 | bool contains(const SkOpSegment*, double t) const; |
| 47 | const SkOpPtT* contains(const SkOpSegment* ) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 48 | SkOpContour* contour() const; |
| 49 | |
| 50 | int debugID() const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 51 | return SkDEBUGRELEASE(fID, -1); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 52 | } |
| 53 | |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 54 | void debugAddOpp(const SkOpPtT* opp, const SkOpPtT* oppPrev) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 55 | const SkOpAngle* debugAngle(int id) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 56 | const SkOpCoincidence* debugCoincidence() const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 57 | bool debugContains(const SkOpPtT* ) const; |
| 58 | const SkOpPtT* debugContains(const SkOpSegment* check) const; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 59 | SkOpContour* debugContour(int id) const; |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 60 | const SkOpPtT* debugEnder(const SkOpPtT* end) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 61 | int debugLoopLimit(bool report) const; |
| 62 | bool debugMatchID(int id) const; |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 63 | const SkOpPtT* debugOppPrev(const SkOpPtT* opp) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 64 | const SkOpPtT* debugPtT(int id) const; |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 65 | void debugResetCoinT() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 66 | const SkOpSegment* debugSegment(int id) const; |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 67 | void debugSetCoinT(int ) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 68 | const SkOpSpanBase* debugSpan(int id) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 69 | void debugValidate() const; |
| 70 | |
| 71 | bool deleted() const { |
| 72 | return fDeleted; |
| 73 | } |
| 74 | |
| 75 | bool duplicate() const { |
| 76 | return fDuplicatePt; |
| 77 | } |
| 78 | |
| 79 | void dump() const; // available to testing only |
| 80 | void dumpAll() const; |
| 81 | void dumpBase() const; |
| 82 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 83 | const SkOpPtT* find(const SkOpSegment* ) const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 84 | SkOpGlobalState* globalState() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 85 | void init(SkOpSpanBase* , double t, const SkPoint& , bool dup); |
| 86 | |
| 87 | void insert(SkOpPtT* span) { |
| 88 | SkASSERT(span != this); |
| 89 | span->fNext = fNext; |
| 90 | fNext = span; |
| 91 | } |
| 92 | |
| 93 | const SkOpPtT* next() const { |
| 94 | return fNext; |
| 95 | } |
| 96 | |
| 97 | SkOpPtT* next() { |
| 98 | return fNext; |
| 99 | } |
| 100 | |
| 101 | bool onEnd() const; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 102 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 103 | // returns nullptr if this is already in the opp ptT loop |
| 104 | SkOpPtT* oppPrev(const SkOpPtT* opp) const { |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 105 | // find the fOpp ptr to opp |
| 106 | SkOpPtT* oppPrev = opp->fNext; |
| 107 | if (oppPrev == this) { |
| 108 | return nullptr; |
| 109 | } |
| 110 | while (oppPrev->fNext != opp) { |
| 111 | oppPrev = oppPrev->fNext; |
| 112 | if (oppPrev == this) { |
| 113 | return nullptr; |
| 114 | } |
| 115 | } |
| 116 | return oppPrev; |
| 117 | } |
| 118 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 119 | static bool Overlaps(const SkOpPtT* s1, const SkOpPtT* e1, const SkOpPtT* s2, |
| 120 | const SkOpPtT* e2, const SkOpPtT** sOut, const SkOpPtT** eOut) { |
| 121 | const SkOpPtT* start1 = s1->fT < e1->fT ? s1 : e1; |
| 122 | const SkOpPtT* start2 = s2->fT < e2->fT ? s2 : e2; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 123 | *sOut = between(s1->fT, start2->fT, e1->fT) ? start2 |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 124 | : between(s2->fT, start1->fT, e2->fT) ? start1 : nullptr; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 125 | const SkOpPtT* end1 = s1->fT < e1->fT ? e1 : s1; |
| 126 | const SkOpPtT* end2 = s2->fT < e2->fT ? e2 : s2; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 127 | *eOut = between(s1->fT, end2->fT, e1->fT) ? end2 |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 128 | : between(s2->fT, end1->fT, e2->fT) ? end1 : nullptr; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 129 | if (*sOut == *eOut) { |
| 130 | SkASSERT(start1->fT >= end2->fT || start2->fT >= end1->fT); |
| 131 | return false; |
| 132 | } |
| 133 | SkASSERT(!*sOut || *sOut != *eOut); |
| 134 | return *sOut && *eOut; |
| 135 | } |
| 136 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 137 | bool ptAlreadySeen(const SkOpPtT* head) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 138 | SkOpPtT* prev(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 139 | |
| 140 | const SkOpSegment* segment() const; |
| 141 | SkOpSegment* segment(); |
| 142 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 143 | void setCoincident() const { |
caryclark | fc560e0 | 2016-07-27 08:46:10 -0700 | [diff] [blame] | 144 | SkOPASSERT(!fDeleted); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 145 | fCoincident = true; |
| 146 | } |
| 147 | |
| 148 | void setDeleted(); |
| 149 | |
| 150 | void setSpan(const SkOpSpanBase* span) { |
| 151 | fSpan = const_cast<SkOpSpanBase*>(span); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | const SkOpSpanBase* span() const { |
| 155 | return fSpan; |
| 156 | } |
| 157 | |
| 158 | SkOpSpanBase* span() { |
| 159 | return fSpan; |
| 160 | } |
| 161 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 162 | const SkOpPtT* starter(const SkOpPtT* end) const { |
| 163 | return fT < end->fT ? this : end; |
| 164 | } |
| 165 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 166 | double fT; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 167 | SkPoint fPt; // cache of point value at this t |
| 168 | protected: |
| 169 | SkOpSpanBase* fSpan; // contains winding data |
| 170 | SkOpPtT* fNext; // intersection on opposite curve or alias on this curve |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 171 | bool fDeleted; // set if removed from span list |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 172 | bool fDuplicatePt; // set if identical pt is somewhere in the next loop |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 173 | // below mutable since referrer is otherwise always const |
| 174 | mutable bool fCoincident; // set if at some point a coincident span pointed here |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 175 | SkDEBUGCODE(int fID); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | class SkOpSpanBase { |
| 179 | public: |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 180 | SkOpSpanBase* active(); |
| 181 | void addOpp(SkOpSpanBase* opp); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 182 | |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 183 | void bumpSpanAdds() { |
| 184 | ++fSpanAdds; |
| 185 | } |
| 186 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 187 | bool chased() const { |
| 188 | return fChased; |
| 189 | } |
| 190 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 191 | void checkForCollapsedCoincidence(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 192 | |
| 193 | const SkOpSpanBase* coinEnd() const { |
| 194 | return fCoinEnd; |
| 195 | } |
| 196 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 197 | bool collapsed(double s, double e) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 198 | bool contains(const SkOpSpanBase* ) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 199 | const SkOpPtT* contains(const SkOpSegment* ) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 200 | |
| 201 | bool containsCoinEnd(const SkOpSpanBase* coin) const { |
| 202 | SkASSERT(this != coin); |
| 203 | const SkOpSpanBase* next = this; |
| 204 | while ((next = next->fCoinEnd) != this) { |
| 205 | if (next == coin) { |
| 206 | return true; |
| 207 | } |
| 208 | } |
| 209 | return false; |
| 210 | } |
| 211 | |
| 212 | bool containsCoinEnd(const SkOpSegment* ) const; |
| 213 | SkOpContour* contour() const; |
| 214 | |
| 215 | int debugBumpCount() { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 216 | return SkDEBUGRELEASE(++fCount, -1); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | int debugID() const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 220 | return SkDEBUGRELEASE(fID, -1); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 223 | #if DEBUG_COIN |
| 224 | void debugAddOpp(SkPathOpsDebug::GlitchLog* , const SkOpSpanBase* opp) const; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 225 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 226 | bool debugAlignedEnd(double t, const SkPoint& pt) const; |
| 227 | bool debugAlignedInner() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 228 | const SkOpAngle* debugAngle(int id) const; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 229 | #if DEBUG_COIN |
| 230 | void debugCheckForCollapsedCoincidence(SkPathOpsDebug::GlitchLog* ) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 231 | #endif |
| 232 | const SkOpCoincidence* debugCoincidence() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 233 | bool debugCoinEndLoopCheck() const; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 234 | SkOpContour* debugContour(int id) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 235 | #ifdef SK_DEBUG |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 236 | bool debugDeleted() const { return fDebugDeleted; } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 237 | #endif |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 238 | #if DEBUG_COIN |
| 239 | void debugInsertCoinEnd(SkPathOpsDebug::GlitchLog* , |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 240 | const SkOpSpanBase* ) const; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 241 | void debugMergeMatches(SkPathOpsDebug::GlitchLog* log, |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 242 | const SkOpSpanBase* opp) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 243 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 244 | const SkOpPtT* debugPtT(int id) const; |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 245 | void debugResetCoinT() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 246 | const SkOpSegment* debugSegment(int id) const; |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 247 | void debugSetCoinT(int ) const; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 248 | #ifdef SK_DEBUG |
| 249 | void debugSetDeleted() { fDebugDeleted = true; } |
| 250 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 251 | const SkOpSpanBase* debugSpan(int id) const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 252 | const SkOpSpan* debugStarter(SkOpSpanBase const** endPtr) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 253 | SkOpGlobalState* globalState() const; |
| 254 | void debugValidate() const; |
| 255 | |
| 256 | bool deleted() const { |
| 257 | return fPtT.deleted(); |
| 258 | } |
| 259 | |
| 260 | void dump() const; // available to testing only |
| 261 | void dumpCoin() const; |
| 262 | void dumpAll() const; |
| 263 | void dumpBase() const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 264 | void dumpHead() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 265 | |
| 266 | bool final() const { |
| 267 | return fPtT.fT == 1; |
| 268 | } |
| 269 | |
| 270 | SkOpAngle* fromAngle() const { |
| 271 | return fFromAngle; |
| 272 | } |
| 273 | |
| 274 | void initBase(SkOpSegment* parent, SkOpSpan* prev, double t, const SkPoint& pt); |
| 275 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 276 | // Please keep this in sync with debugInsertCoinEnd() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 277 | void insertCoinEnd(SkOpSpanBase* coin) { |
| 278 | if (containsCoinEnd(coin)) { |
| 279 | SkASSERT(coin->containsCoinEnd(this)); |
| 280 | return; |
| 281 | } |
| 282 | debugValidate(); |
| 283 | SkASSERT(this != coin); |
| 284 | SkOpSpanBase* coinNext = coin->fCoinEnd; |
| 285 | coin->fCoinEnd = this->fCoinEnd; |
| 286 | this->fCoinEnd = coinNext; |
| 287 | debugValidate(); |
| 288 | } |
| 289 | |
| 290 | void merge(SkOpSpan* span); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 291 | void mergeMatches(SkOpSpanBase* opp); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 292 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 293 | const SkOpSpan* prev() const { |
| 294 | return fPrev; |
| 295 | } |
| 296 | |
| 297 | SkOpSpan* prev() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 298 | return fPrev; |
| 299 | } |
| 300 | |
| 301 | const SkPoint& pt() const { |
| 302 | return fPtT.fPt; |
| 303 | } |
| 304 | |
| 305 | const SkOpPtT* ptT() const { |
| 306 | return &fPtT; |
| 307 | } |
| 308 | |
| 309 | SkOpPtT* ptT() { |
| 310 | return &fPtT; |
| 311 | } |
| 312 | |
| 313 | SkOpSegment* segment() const { |
| 314 | return fSegment; |
| 315 | } |
| 316 | |
caryclark | d434972 | 2015-07-23 12:40:22 -0700 | [diff] [blame] | 317 | void setAligned() { |
| 318 | fAligned = true; |
| 319 | } |
| 320 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 321 | void setChased(bool chased) { |
| 322 | fChased = chased; |
| 323 | } |
| 324 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 325 | void setFromAngle(SkOpAngle* angle) { |
| 326 | fFromAngle = angle; |
| 327 | } |
| 328 | |
| 329 | void setPrev(SkOpSpan* prev) { |
| 330 | fPrev = prev; |
| 331 | } |
| 332 | |
| 333 | bool simple() const { |
| 334 | fPtT.debugValidate(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 335 | return fPtT.next()->next() == &fPtT; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 336 | } |
| 337 | |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 338 | int spanAddsCount() const { |
| 339 | return fSpanAdds; |
| 340 | } |
| 341 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 342 | const SkOpSpan* starter(const SkOpSpanBase* end) const { |
| 343 | const SkOpSpanBase* result = t() < end->t() ? this : end; |
| 344 | return result->upCast(); |
| 345 | } |
| 346 | |
| 347 | SkOpSpan* starter(SkOpSpanBase* end) { |
| 348 | SkASSERT(this->segment() == end->segment()); |
| 349 | SkOpSpanBase* result = t() < end->t() ? this : end; |
| 350 | return result->upCast(); |
| 351 | } |
| 352 | |
| 353 | SkOpSpan* starter(SkOpSpanBase** endPtr) { |
| 354 | SkOpSpanBase* end = *endPtr; |
| 355 | SkASSERT(this->segment() == end->segment()); |
| 356 | SkOpSpanBase* result; |
| 357 | if (t() < end->t()) { |
| 358 | result = this; |
| 359 | } else { |
| 360 | result = end; |
| 361 | *endPtr = this; |
| 362 | } |
| 363 | return result->upCast(); |
| 364 | } |
| 365 | |
| 366 | int step(const SkOpSpanBase* end) const { |
| 367 | return t() < end->t() ? 1 : -1; |
| 368 | } |
| 369 | |
| 370 | double t() const { |
| 371 | return fPtT.fT; |
| 372 | } |
| 373 | |
| 374 | void unaligned() { |
| 375 | fAligned = false; |
| 376 | } |
| 377 | |
| 378 | SkOpSpan* upCast() { |
| 379 | SkASSERT(!final()); |
| 380 | return (SkOpSpan*) this; |
| 381 | } |
| 382 | |
| 383 | const SkOpSpan* upCast() const { |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 384 | SkOPASSERT(!final()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 385 | return (const SkOpSpan*) this; |
| 386 | } |
| 387 | |
| 388 | SkOpSpan* upCastable() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 389 | return final() ? nullptr : upCast(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | const SkOpSpan* upCastable() const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 393 | return final() ? nullptr : upCast(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | private: |
| 397 | void alignInner(); |
| 398 | |
| 399 | protected: // no direct access to internals to avoid treating a span base as a span |
| 400 | SkOpPtT fPtT; // list of points and t values associated with the start of this span |
| 401 | SkOpSegment* fSegment; // segment that contains this span |
| 402 | SkOpSpanBase* fCoinEnd; // linked list of coincident spans that end here (may point to itself) |
| 403 | SkOpAngle* fFromAngle; // points to next angle from span start to end |
| 404 | SkOpSpan* fPrev; // previous intersection point |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 405 | int fSpanAdds; // number of times intersections have been added to span |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 406 | bool fAligned; |
| 407 | bool fChased; // set after span has been added to chase array |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 408 | SkDEBUGCODE(int fCount); // number of pt/t pairs added |
| 409 | SkDEBUGCODE(int fID); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 410 | SkDEBUGCODE(bool fDebugDeleted); // set when span was merged with another span |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | class SkOpSpan : public SkOpSpanBase { |
| 414 | public: |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 415 | bool alreadyAdded() const { |
| 416 | if (fAlreadyAdded) { |
| 417 | return true; |
| 418 | } |
| 419 | fAlreadyAdded = true; |
| 420 | return false; |
| 421 | } |
| 422 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 423 | bool clearCoincident() { |
| 424 | SkASSERT(!final()); |
| 425 | if (fCoincident == this) { |
| 426 | return false; |
| 427 | } |
| 428 | fCoincident = this; |
| 429 | return true; |
| 430 | } |
| 431 | |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 432 | int computeWindSum(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 433 | bool containsCoincidence(const SkOpSegment* ) const; |
| 434 | |
| 435 | bool containsCoincidence(const SkOpSpan* coin) const { |
| 436 | SkASSERT(this != coin); |
| 437 | const SkOpSpan* next = this; |
| 438 | while ((next = next->fCoincident) != this) { |
| 439 | if (next == coin) { |
| 440 | return true; |
| 441 | } |
| 442 | } |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | bool debugCoinLoopCheck() const; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 447 | #if DEBUG_COIN |
| 448 | void debugInsertCoincidence(SkPathOpsDebug::GlitchLog* , const SkOpSpan* ) const; |
| 449 | void debugInsertCoincidence(SkPathOpsDebug::GlitchLog* , |
| 450 | const SkOpSegment* , bool flipped, bool ordered) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 451 | #endif |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 452 | void dumpCoin() const; |
| 453 | bool dumpSpan() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 454 | |
| 455 | bool done() const { |
| 456 | SkASSERT(!final()); |
| 457 | return fDone; |
| 458 | } |
| 459 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 460 | void init(SkOpSegment* parent, SkOpSpan* prev, double t, const SkPoint& pt); |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 461 | bool insertCoincidence(const SkOpSegment* , bool flipped, bool ordered); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 462 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 463 | // Please keep this in sync with debugInsertCoincidence() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 464 | void insertCoincidence(SkOpSpan* coin) { |
| 465 | if (containsCoincidence(coin)) { |
| 466 | SkASSERT(coin->containsCoincidence(this)); |
| 467 | return; |
| 468 | } |
| 469 | debugValidate(); |
| 470 | SkASSERT(this != coin); |
| 471 | SkOpSpan* coinNext = coin->fCoincident; |
| 472 | coin->fCoincident = this->fCoincident; |
| 473 | this->fCoincident = coinNext; |
| 474 | debugValidate(); |
| 475 | } |
| 476 | |
| 477 | bool isCanceled() const { |
| 478 | SkASSERT(!final()); |
| 479 | return fWindValue == 0 && fOppValue == 0; |
| 480 | } |
| 481 | |
| 482 | bool isCoincident() const { |
| 483 | SkASSERT(!final()); |
| 484 | return fCoincident != this; |
| 485 | } |
| 486 | |
| 487 | SkOpSpanBase* next() const { |
| 488 | SkASSERT(!final()); |
| 489 | return fNext; |
| 490 | } |
| 491 | |
| 492 | int oppSum() const { |
| 493 | SkASSERT(!final()); |
| 494 | return fOppSum; |
| 495 | } |
| 496 | |
| 497 | int oppValue() const { |
| 498 | SkASSERT(!final()); |
| 499 | return fOppValue; |
| 500 | } |
| 501 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 502 | void release(const SkOpPtT* ); |
| 503 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 504 | SkOpPtT* setCoinStart(SkOpSpan* oldCoinStart, SkOpSegment* oppSegment); |
| 505 | |
| 506 | void setDone(bool done) { |
| 507 | SkASSERT(!final()); |
| 508 | fDone = done; |
| 509 | } |
| 510 | |
| 511 | void setNext(SkOpSpanBase* nextT) { |
| 512 | SkASSERT(!final()); |
| 513 | fNext = nextT; |
| 514 | } |
| 515 | |
| 516 | void setOppSum(int oppSum); |
| 517 | |
| 518 | void setOppValue(int oppValue) { |
| 519 | SkASSERT(!final()); |
| 520 | SkASSERT(fOppSum == SK_MinS32); |
caryclark | 595ac28 | 2016-10-24 08:41:45 -0700 | [diff] [blame] | 521 | SkOPASSERT(!oppValue || !fDone); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 522 | fOppValue = oppValue; |
| 523 | } |
| 524 | |
| 525 | void setToAngle(SkOpAngle* angle) { |
| 526 | SkASSERT(!final()); |
| 527 | fToAngle = angle; |
| 528 | } |
| 529 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 530 | void setWindSum(int windSum); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 531 | |
| 532 | void setWindValue(int windValue) { |
| 533 | SkASSERT(!final()); |
| 534 | SkASSERT(windValue >= 0); |
| 535 | SkASSERT(fWindSum == SK_MinS32); |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 536 | SkOPASSERT(!windValue || !fDone); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 537 | fWindValue = windValue; |
| 538 | } |
| 539 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 540 | bool sortableTop(SkOpContour* ); |
| 541 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 542 | SkOpAngle* toAngle() const { |
| 543 | SkASSERT(!final()); |
| 544 | return fToAngle; |
| 545 | } |
| 546 | |
| 547 | int windSum() const { |
| 548 | SkASSERT(!final()); |
| 549 | return fWindSum; |
| 550 | } |
| 551 | |
| 552 | int windValue() const { |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 553 | SkOPASSERT(!final()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 554 | return fWindValue; |
| 555 | } |
| 556 | |
| 557 | private: // no direct access to internals to avoid treating a span base as a span |
| 558 | SkOpSpan* fCoincident; // linked list of spans coincident with this one (may point to itself) |
| 559 | SkOpAngle* fToAngle; // points to next angle from span start to end |
| 560 | SkOpSpanBase* fNext; // next intersection point |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 561 | int fWindSum; // accumulated from contours surrounding this one. |
| 562 | int fOppSum; // for binary operators: the opposite winding sum |
| 563 | int fWindValue; // 0 == canceled; 1 == normal; >1 == coincident |
| 564 | int fOppValue; // normally 0 -- when binary coincident edges combine, opp value goes here |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 565 | int fTopTTry; // specifies direction and t value to try next |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 566 | bool fDone; // if set, this span to next higher T has been processed |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 567 | mutable bool fAlreadyAdded; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 568 | }; |
| 569 | |
| 570 | #endif |