caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 8 | #include "SkMutex.h" |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 9 | #include "SkOpCoincidence.h" |
| 10 | #include "SkOpContour.h" |
jvanverth | 02802f6 | 2015-07-02 06:42:49 -0700 | [diff] [blame] | 11 | #include "SkPath.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 12 | #include "SkPathOpsDebug.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 13 | #include "SkString.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 14 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 15 | class SkCoincidentSpans; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 16 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 17 | #if DEBUG_VALIDATE |
| 18 | extern bool FLAGS_runFail; |
| 19 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 20 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 21 | #if DEBUG_SORT |
| 22 | int SkPathOpsDebug::gSortCountDefault = SK_MaxS32; |
| 23 | int SkPathOpsDebug::gSortCount; |
| 24 | #endif |
| 25 | |
| 26 | #if DEBUG_ACTIVE_OP |
| 27 | const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor"}; |
| 28 | #endif |
| 29 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | #if defined SK_DEBUG || !FORCE_RELEASE |
| 31 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 32 | const char* SkPathOpsDebug::kLVerbStr[] = {"", "line", "quad", "cubic"}; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 33 | |
commit-bot@chromium.org | fe41b8f | 2014-04-25 14:03:52 +0000 | [diff] [blame] | 34 | int SkPathOpsDebug::gContourID = 0; |
| 35 | int SkPathOpsDebug::gSegmentID = 0; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 36 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 37 | bool SkPathOpsDebug::ChaseContains(const SkTDArray<SkOpSpanBase* >& chaseArray, |
| 38 | const SkOpSpanBase* span) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 39 | for (int index = 0; index < chaseArray.count(); ++index) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 40 | const SkOpSpanBase* entry = chaseArray[index]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 41 | if (entry == span) { |
| 42 | return true; |
| 43 | } |
| 44 | } |
| 45 | return false; |
| 46 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 47 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 48 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 49 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 50 | enum GlitchType { |
| 51 | kAddCorruptCoin_Glitch, |
| 52 | kAddExpandedCoin_Glitch, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 53 | kAddExpandedFail_Glitch, |
| 54 | kAddIfMissingCoin_Glitch, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 55 | kAddMissingCoin_Glitch, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 56 | kAddMissingExtend_Glitch, |
| 57 | kAddOrOverlap_Glitch, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 58 | kCollapsedCoin_Glitch, |
| 59 | kCollapsedDone_Glitch, |
| 60 | kCollapsedOppValue_Glitch, |
| 61 | kCollapsedSpan_Glitch, |
| 62 | kCollapsedWindValue_Glitch, |
| 63 | kDeletedCoin_Glitch, |
| 64 | kExpandCoin_Glitch, |
| 65 | kMarkCoinEnd_Glitch, |
| 66 | kMarkCoinInsert_Glitch, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 67 | kMarkCoinMissing_Glitch, |
| 68 | kMarkCoinStart_Glitch, |
| 69 | kMergeContained_Glitch, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 70 | kMissingCoin_Glitch, |
| 71 | kMissingDone_Glitch, |
| 72 | kMissingIntersection_Glitch, |
| 73 | kMoveMultiple_Glitch, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 74 | kMoveNearbyClearAll_Glitch, |
| 75 | kMoveNearbyClearAll2_Glitch, |
| 76 | kMoveNearbyMerge_Glitch, |
| 77 | kMoveNearbyMergeFinal_Glitch, |
| 78 | kMoveNearbyRelease_Glitch, |
| 79 | kMoveNearbyReleaseFinal_Glitch, |
| 80 | kReleasedSpan_Glitch, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 81 | kUnaligned_Glitch, |
| 82 | kUnalignedHead_Glitch, |
| 83 | kUnalignedTail_Glitch, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 86 | static const int kGlitchType_Count = kUnalignedTail_Glitch + 1; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 87 | |
| 88 | struct SpanGlitch { |
| 89 | const char* fStage; |
| 90 | const SkOpSpanBase* fBase; |
| 91 | const SkOpSpanBase* fSuspect; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 92 | const SkOpSegment* fSegment; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 93 | const SkOpSegment* fOppSegment; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 94 | const SkOpPtT* fCoinSpan; |
| 95 | const SkOpPtT* fEndSpan; |
| 96 | const SkOpPtT* fOppSpan; |
| 97 | const SkOpPtT* fOppEndSpan; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 98 | double fStartT; |
| 99 | double fEndT; |
| 100 | double fOppStartT; |
| 101 | double fOppEndT; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 102 | SkPoint fPt; |
| 103 | GlitchType fType; |
| 104 | }; |
| 105 | |
| 106 | struct SkPathOpsDebug::GlitchLog { |
| 107 | SpanGlitch* recordCommon(GlitchType type, const char* stage) { |
| 108 | SpanGlitch* glitch = fGlitches.push(); |
| 109 | glitch->fStage = stage; |
| 110 | glitch->fBase = nullptr; |
| 111 | glitch->fSuspect = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 112 | glitch->fSegment = nullptr; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 113 | glitch->fOppSegment = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 114 | glitch->fCoinSpan = nullptr; |
| 115 | glitch->fEndSpan = nullptr; |
| 116 | glitch->fOppSpan = nullptr; |
| 117 | glitch->fOppEndSpan = nullptr; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 118 | glitch->fStartT = SK_ScalarNaN; |
| 119 | glitch->fEndT = SK_ScalarNaN; |
| 120 | glitch->fOppStartT = SK_ScalarNaN; |
| 121 | glitch->fOppEndT = SK_ScalarNaN; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 122 | glitch->fPt = { SK_ScalarNaN, SK_ScalarNaN }; |
| 123 | glitch->fType = type; |
| 124 | return glitch; |
| 125 | } |
| 126 | |
| 127 | void record(GlitchType type, const char* stage, const SkOpSpanBase* base, |
| 128 | const SkOpSpanBase* suspect = NULL) { |
| 129 | SpanGlitch* glitch = recordCommon(type, stage); |
| 130 | glitch->fBase = base; |
| 131 | glitch->fSuspect = suspect; |
| 132 | } |
| 133 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 134 | void record(GlitchType type, const char* stage, const SkOpSpanBase* base, |
| 135 | const SkOpPtT* ptT) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 136 | SpanGlitch* glitch = recordCommon(type, stage); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 137 | glitch->fBase = base; |
| 138 | glitch->fCoinSpan = ptT; |
| 139 | } |
| 140 | |
| 141 | void record(GlitchType type, const char* stage, const SkCoincidentSpans* coin, |
| 142 | const SkCoincidentSpans* opp = NULL) { |
| 143 | SpanGlitch* glitch = recordCommon(type, stage); |
| 144 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 145 | glitch->fEndSpan = coin->coinPtTEnd(); |
| 146 | if (opp) { |
| 147 | glitch->fOppSpan = opp->coinPtTStart(); |
| 148 | glitch->fOppEndSpan = opp->coinPtTEnd(); |
| 149 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void record(GlitchType type, const char* stage, const SkOpSpanBase* base, |
| 153 | const SkOpSegment* seg, double t, SkPoint pt) { |
| 154 | SpanGlitch* glitch = recordCommon(type, stage); |
| 155 | glitch->fBase = base; |
| 156 | glitch->fSegment = seg; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 157 | glitch->fStartT = t; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 158 | glitch->fPt = pt; |
| 159 | } |
| 160 | |
| 161 | void record(GlitchType type, const char* stage, const SkOpSpanBase* base, double t, |
| 162 | SkPoint pt) { |
| 163 | SpanGlitch* glitch = recordCommon(type, stage); |
| 164 | glitch->fBase = base; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 165 | glitch->fStartT = t; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 166 | glitch->fPt = pt; |
| 167 | } |
| 168 | |
| 169 | void record(GlitchType type, const char* stage, const SkCoincidentSpans* coin, |
| 170 | const SkOpPtT* coinSpan, const SkOpPtT* endSpan) { |
| 171 | SpanGlitch* glitch = recordCommon(type, stage); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 172 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 173 | glitch->fEndSpan = coin->coinPtTEnd(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 174 | glitch->fEndSpan = endSpan; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 175 | glitch->fOppSpan = coinSpan; |
| 176 | glitch->fOppEndSpan = endSpan; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | void record(GlitchType type, const char* stage, const SkCoincidentSpans* coin, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 180 | const SkOpSpanBase* base) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 181 | SpanGlitch* glitch = recordCommon(type, stage); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 182 | glitch->fBase = base; |
| 183 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 184 | glitch->fEndSpan = coin->coinPtTEnd(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void record(GlitchType type, const char* stage, const SkOpPtT* ptTS, const SkOpPtT* ptTE, |
| 188 | const SkOpPtT* oPtTS, const SkOpPtT* oPtTE) { |
| 189 | SpanGlitch* glitch = recordCommon(type, stage); |
| 190 | glitch->fCoinSpan = ptTS; |
| 191 | glitch->fEndSpan = ptTE; |
| 192 | glitch->fOppSpan = oPtTS; |
| 193 | glitch->fOppEndSpan = oPtTE; |
| 194 | } |
| 195 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 196 | void record(GlitchType type, const char* stage, const SkOpSegment* seg, double startT, |
| 197 | double endT, const SkOpSegment* oppSeg, double oppStartT, double oppEndT) { |
| 198 | SpanGlitch* glitch = recordCommon(type, stage); |
| 199 | glitch->fSegment = seg; |
| 200 | glitch->fStartT = startT; |
| 201 | glitch->fEndT = endT; |
| 202 | glitch->fOppSegment = oppSeg; |
| 203 | glitch->fOppStartT = oppStartT; |
| 204 | glitch->fOppEndT = oppEndT; |
| 205 | } |
| 206 | |
| 207 | void record(GlitchType type, const char* stage, const SkOpSegment* seg, |
| 208 | const SkOpSpan* span) { |
| 209 | SpanGlitch* glitch = recordCommon(type, stage); |
| 210 | glitch->fSegment = seg; |
| 211 | glitch->fBase = span; |
| 212 | } |
| 213 | |
| 214 | void record(GlitchType type, const char* stage, double t, const SkOpSpanBase* span) { |
| 215 | SpanGlitch* glitch = recordCommon(type, stage); |
| 216 | glitch->fStartT = t; |
| 217 | glitch->fBase = span; |
| 218 | } |
| 219 | |
| 220 | void record(GlitchType type, const char* stage, const SkOpSegment* seg) { |
| 221 | SpanGlitch* glitch = recordCommon(type, stage); |
| 222 | glitch->fSegment = seg; |
| 223 | } |
| 224 | |
| 225 | void record(GlitchType type, const char* stage, const SkCoincidentSpans* coin, |
| 226 | const SkOpPtT* ptT) { |
| 227 | SpanGlitch* glitch = recordCommon(type, stage); |
| 228 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 229 | glitch->fEndSpan = ptT; |
| 230 | } |
| 231 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 232 | SkTDArray<SpanGlitch> fGlitches; |
| 233 | }; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 234 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 235 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 236 | void SkPathOpsDebug::ShowActiveSpans(SkOpContourHead* contourList) { |
| 237 | #if DEBUG_ACTIVE_SPANS |
| 238 | SkOpContour* contour = contourList; |
| 239 | do { |
| 240 | contour->debugShowActiveSpans(); |
| 241 | } while ((contour = contour->next())); |
| 242 | #endif |
| 243 | } |
| 244 | |
| 245 | #if DEBUG_COINCIDENCE |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 246 | void SkPathOpsDebug::CheckHealth(SkOpContourHead* contourList, const char* id) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 247 | contourList->globalState()->debugSetCheckHealth(true); |
| 248 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 249 | GlitchLog glitches; |
| 250 | const SkOpContour* contour = contourList; |
| 251 | const SkOpCoincidence* coincidence = contour->globalState()->coincidence(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 252 | coincidence->debugCheckValid(id, &glitches); // don't call validate; spans may be inconsistent |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 253 | do { |
| 254 | contour->debugCheckHealth(id, &glitches); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 255 | contour->debugMissingCoincidence(id, &glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 256 | } while ((contour = contour->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 257 | coincidence->debugRemoveCollapsed(id, &glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 258 | coincidence->debugAddMissing(id, &glitches); |
| 259 | coincidence->debugExpand(id, &glitches); |
| 260 | coincidence->debugAddExpanded(id, &glitches); |
| 261 | coincidence->debugMark(id, &glitches); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 262 | coincidence->debugReorder(id, &glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 263 | unsigned mask = 0; |
| 264 | for (int index = 0; index < glitches.fGlitches.count(); ++index) { |
| 265 | const SpanGlitch& glitch = glitches.fGlitches[index]; |
| 266 | mask |= 1 << glitch.fType; |
| 267 | } |
| 268 | for (int index = 0; index < kGlitchType_Count; ++index) { |
| 269 | SkDebugf(mask & (1 << index) ? "x" : "-"); |
| 270 | } |
| 271 | SkDebugf(" %s\n", id); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 272 | for (int index = 0; index < glitches.fGlitches.count(); ++index) { |
| 273 | const SpanGlitch& glitch = glitches.fGlitches[index]; |
| 274 | SkDebugf("%02d: ", index); |
| 275 | if (glitch.fBase) { |
| 276 | SkDebugf(" base=%d", glitch.fBase->debugID()); |
| 277 | } |
| 278 | if (glitch.fSuspect) { |
| 279 | SkDebugf(" base=%d", glitch.fSuspect->debugID()); |
| 280 | } |
| 281 | if (glitch.fSegment) { |
| 282 | SkDebugf(" segment=%d", glitch.fSegment->debugID()); |
| 283 | } |
| 284 | if (glitch.fCoinSpan) { |
| 285 | SkDebugf(" coinSpan=%d", glitch.fCoinSpan->debugID()); |
| 286 | } |
| 287 | if (glitch.fEndSpan) { |
| 288 | SkDebugf(" endSpan=%d", glitch.fEndSpan->debugID()); |
| 289 | } |
| 290 | if (glitch.fOppSpan) { |
| 291 | SkDebugf(" oppSpan=%d", glitch.fOppSpan->debugID()); |
| 292 | } |
| 293 | if (glitch.fOppEndSpan) { |
| 294 | SkDebugf(" oppEndSpan=%d", glitch.fOppEndSpan->debugID()); |
| 295 | } |
| 296 | if (!SkScalarIsNaN(glitch.fStartT)) { |
| 297 | SkDebugf(" startT=%g", glitch.fStartT); |
| 298 | } |
| 299 | if (!SkScalarIsNaN(glitch.fEndT)) { |
| 300 | SkDebugf(" endT=%g", glitch.fEndT); |
| 301 | } |
| 302 | if (glitch.fOppSegment) { |
| 303 | SkDebugf(" segment=%d", glitch.fOppSegment->debugID()); |
| 304 | } |
| 305 | if (!SkScalarIsNaN(glitch.fOppStartT)) { |
| 306 | SkDebugf(" oppStartT=%g", glitch.fOppStartT); |
| 307 | } |
| 308 | if (!SkScalarIsNaN(glitch.fOppEndT)) { |
| 309 | SkDebugf(" oppEndT=%g", glitch.fOppEndT); |
| 310 | } |
| 311 | if (!SkScalarIsNaN(glitch.fPt.fX) || !SkScalarIsNaN(glitch.fPt.fY)) { |
| 312 | SkDebugf(" pt=%g,%g", glitch.fPt.fX, glitch.fPt.fY); |
| 313 | } |
| 314 | switch (glitch.fType) { |
| 315 | case kAddCorruptCoin_Glitch: SkDebugf(" AddCorruptCoin"); break; |
| 316 | case kAddExpandedCoin_Glitch: SkDebugf(" AddExpandedCoin"); break; |
| 317 | case kAddExpandedFail_Glitch: SkDebugf(" AddExpandedFail"); break; |
| 318 | case kAddIfMissingCoin_Glitch: SkDebugf(" AddIfMissingCoin"); break; |
| 319 | case kAddMissingCoin_Glitch: SkDebugf(" AddMissingCoin"); break; |
| 320 | case kAddMissingExtend_Glitch: SkDebugf(" AddMissingExtend"); break; |
| 321 | case kAddOrOverlap_Glitch: SkDebugf(" AAddOrOverlap"); break; |
| 322 | case kCollapsedCoin_Glitch: SkDebugf(" CollapsedCoin"); break; |
| 323 | case kCollapsedDone_Glitch: SkDebugf(" CollapsedDone"); break; |
| 324 | case kCollapsedOppValue_Glitch: SkDebugf(" CollapsedOppValue"); break; |
| 325 | case kCollapsedSpan_Glitch: SkDebugf(" CollapsedSpan"); break; |
| 326 | case kCollapsedWindValue_Glitch: SkDebugf(" CollapsedWindValue"); break; |
| 327 | case kDeletedCoin_Glitch: SkDebugf(" DeletedCoin"); break; |
| 328 | case kExpandCoin_Glitch: SkDebugf(" ExpandCoin"); break; |
| 329 | case kMarkCoinEnd_Glitch: SkDebugf(" MarkCoinEnd"); break; |
| 330 | case kMarkCoinInsert_Glitch: SkDebugf(" MarkCoinInsert"); break; |
| 331 | case kMarkCoinMissing_Glitch: SkDebugf(" MarkCoinMissing"); break; |
| 332 | case kMarkCoinStart_Glitch: SkDebugf(" MarkCoinStart"); break; |
| 333 | case kMergeContained_Glitch: SkDebugf(" MergeContained"); break; |
| 334 | case kMissingCoin_Glitch: SkDebugf(" MissingCoin"); break; |
| 335 | case kMissingDone_Glitch: SkDebugf(" MissingDone"); break; |
| 336 | case kMissingIntersection_Glitch: SkDebugf(" MissingIntersection"); break; |
| 337 | case kMoveMultiple_Glitch: SkDebugf(" MoveMultiple"); break; |
| 338 | case kMoveNearbyClearAll_Glitch: SkDebugf(" MoveNearbyClearAll"); break; |
| 339 | case kMoveNearbyClearAll2_Glitch: SkDebugf(" MoveNearbyClearAll2"); break; |
| 340 | case kMoveNearbyMerge_Glitch: SkDebugf(" MoveNearbyMerge"); break; |
| 341 | case kMoveNearbyMergeFinal_Glitch: SkDebugf(" MoveNearbyMergeFinal"); break; |
| 342 | case kMoveNearbyRelease_Glitch: SkDebugf(" MoveNearbyRelease"); break; |
| 343 | case kMoveNearbyReleaseFinal_Glitch: SkDebugf(" MoveNearbyReleaseFinal"); break; |
| 344 | case kReleasedSpan_Glitch: SkDebugf(" ReleasedSpan"); break; |
| 345 | case kUnaligned_Glitch: SkDebugf(" Unaligned"); break; |
| 346 | case kUnalignedHead_Glitch: SkDebugf(" UnalignedHead"); break; |
| 347 | case kUnalignedTail_Glitch: SkDebugf(" UnalignedTail"); break; |
| 348 | default: SkASSERT(0); |
| 349 | } |
| 350 | SkDebugf("\n"); |
| 351 | } |
| 352 | contourList->globalState()->debugSetCheckHealth(false); |
| 353 | #if DEBUG_ACTIVE_SPANS |
| 354 | SkDebugf("active after %s:\n", id); |
| 355 | ShowActiveSpans(contourList); |
| 356 | #endif |
| 357 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 358 | } |
| 359 | #endif |
| 360 | |
| 361 | #if defined SK_DEBUG || !FORCE_RELEASE |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 362 | void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 363 | size_t len = strlen(str); |
| 364 | bool num = false; |
| 365 | for (size_t idx = 0; idx < len; ++idx) { |
| 366 | if (num && str[idx] == 'e') { |
| 367 | if (len + 2 >= bufferLen) { |
| 368 | return; |
| 369 | } |
| 370 | memmove(&str[idx + 2], &str[idx + 1], len - idx); |
| 371 | str[idx] = '*'; |
| 372 | str[idx + 1] = '^'; |
| 373 | ++len; |
| 374 | } |
| 375 | num = str[idx] >= '0' && str[idx] <= '9'; |
| 376 | } |
| 377 | } |
| 378 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 379 | bool SkPathOpsDebug::ValidWind(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 380 | return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; |
| 381 | } |
| 382 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 383 | void SkPathOpsDebug::WindingPrintf(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 384 | if (wind == SK_MinS32) { |
| 385 | SkDebugf("?"); |
| 386 | } else { |
| 387 | SkDebugf("%d", wind); |
| 388 | } |
| 389 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 390 | #endif // defined SK_DEBUG || !FORCE_RELEASE |
| 391 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 392 | |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 393 | #if DEBUG_SHOW_TEST_NAME |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 394 | void* SkPathOpsDebug::CreateNameStr() { return new char[DEBUG_FILENAME_STRING_LENGTH]; } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 395 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 396 | void SkPathOpsDebug::DeleteNameStr(void* v) { delete[] reinterpret_cast<char*>(v); } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 397 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 398 | void SkPathOpsDebug::BumpTestName(char* test) { |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 399 | char* num = test + strlen(test); |
| 400 | while (num[-1] >= '0' && num[-1] <= '9') { |
| 401 | --num; |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 402 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 403 | if (num[0] == '\0') { |
| 404 | return; |
| 405 | } |
| 406 | int dec = atoi(num); |
| 407 | if (dec == 0) { |
| 408 | return; |
| 409 | } |
| 410 | ++dec; |
| 411 | SK_SNPRINTF(num, DEBUG_FILENAME_STRING_LENGTH - (num - test), "%d", dec); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 412 | } |
| 413 | #endif |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 414 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 415 | static void show_function_header(const char* functionName) { |
| 416 | SkDebugf("\nstatic void %s(skiatest::Reporter* reporter, const char* filename) {\n", functionName); |
| 417 | if (strcmp("skphealth_com76", functionName) == 0) { |
| 418 | SkDebugf("found it\n"); |
| 419 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 420 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 421 | |
| 422 | static const char* gOpStrs[] = { |
| 423 | "kDifference_SkPathOp", |
| 424 | "kIntersect_SkPathOp", |
| 425 | "kUnion_SkPathOp", |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 426 | "kXOR_PathOp", |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 427 | "kReverseDifference_SkPathOp", |
| 428 | }; |
| 429 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 430 | const char* SkPathOpsDebug::OpStr(SkPathOp op) { |
| 431 | return gOpStrs[op]; |
| 432 | } |
| 433 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 434 | static void show_op(SkPathOp op, const char* pathOne, const char* pathTwo) { |
| 435 | SkDebugf(" testPathOp(reporter, %s, %s, %s, filename);\n", pathOne, pathTwo, gOpStrs[op]); |
| 436 | SkDebugf("}\n"); |
| 437 | } |
| 438 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 439 | SK_DECLARE_STATIC_MUTEX(gTestMutex); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 440 | |
| 441 | void SkPathOpsDebug::ShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp, |
| 442 | const char* testName) { |
| 443 | SkAutoMutexAcquire ac(gTestMutex); |
| 444 | show_function_header(testName); |
| 445 | ShowOnePath(a, "path", true); |
| 446 | ShowOnePath(b, "pathB", true); |
| 447 | show_op(shapeOp, "path", "pathB"); |
| 448 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 449 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 450 | #include "SkPathOpsTypes.h" |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 451 | #include "SkIntersectionHelper.h" |
| 452 | #include "SkIntersections.h" |
| 453 | |
| 454 | #if DEBUG_T_SECT_LOOP_COUNT |
| 455 | void SkOpGlobalState::debugAddLoopCount(SkIntersections* i, const SkIntersectionHelper& wt, |
| 456 | const SkIntersectionHelper& wn) { |
| 457 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 458 | SkIntersections::DebugLoop looper = (SkIntersections::DebugLoop) index; |
| 459 | if (fDebugLoopCount[index] >= i->debugLoopCount(looper)) { |
| 460 | continue; |
| 461 | } |
| 462 | fDebugLoopCount[index] = i->debugLoopCount(looper); |
| 463 | fDebugWorstVerb[index * 2] = wt.segment()->verb(); |
| 464 | fDebugWorstVerb[index * 2 + 1] = wn.segment()->verb(); |
| 465 | sk_bzero(&fDebugWorstPts[index * 8], sizeof(SkPoint) * 8); |
| 466 | memcpy(&fDebugWorstPts[index * 2 * 4], wt.pts(), |
| 467 | (SkPathOpsVerbToPoints(wt.segment()->verb()) + 1) * sizeof(SkPoint)); |
| 468 | memcpy(&fDebugWorstPts[(index * 2 + 1) * 4], wn.pts(), |
| 469 | (SkPathOpsVerbToPoints(wn.segment()->verb()) + 1) * sizeof(SkPoint)); |
| 470 | fDebugWorstWeight[index * 2] = wt.weight(); |
| 471 | fDebugWorstWeight[index * 2 + 1] = wn.weight(); |
| 472 | } |
| 473 | i->debugResetLoopCount(); |
| 474 | } |
| 475 | |
| 476 | void SkOpGlobalState::debugDoYourWorst(SkOpGlobalState* local) { |
| 477 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 478 | if (fDebugLoopCount[index] >= local->fDebugLoopCount[index]) { |
| 479 | continue; |
| 480 | } |
| 481 | fDebugLoopCount[index] = local->fDebugLoopCount[index]; |
| 482 | fDebugWorstVerb[index * 2] = local->fDebugWorstVerb[index * 2]; |
| 483 | fDebugWorstVerb[index * 2 + 1] = local->fDebugWorstVerb[index * 2 + 1]; |
| 484 | memcpy(&fDebugWorstPts[index * 2 * 4], &local->fDebugWorstPts[index * 2 * 4], |
| 485 | sizeof(SkPoint) * 8); |
| 486 | fDebugWorstWeight[index * 2] = local->fDebugWorstWeight[index * 2]; |
| 487 | fDebugWorstWeight[index * 2 + 1] = local->fDebugWorstWeight[index * 2 + 1]; |
| 488 | } |
| 489 | local->debugResetLoopCounts(); |
| 490 | } |
| 491 | |
| 492 | static void dump_curve(SkPath::Verb verb, const SkPoint& pts, float weight) { |
| 493 | if (!verb) { |
| 494 | return; |
| 495 | } |
| 496 | const char* verbs[] = { "", "line", "quad", "conic", "cubic" }; |
| 497 | SkDebugf("%s: {{", verbs[verb]); |
| 498 | int ptCount = SkPathOpsVerbToPoints(verb); |
| 499 | for (int index = 0; index <= ptCount; ++index) { |
| 500 | SkDPoint::Dump((&pts)[index]); |
| 501 | if (index < ptCount - 1) { |
| 502 | SkDebugf(", "); |
| 503 | } |
| 504 | } |
| 505 | SkDebugf("}"); |
| 506 | if (weight != 1) { |
| 507 | SkDebugf(", "); |
| 508 | if (weight == floorf(weight)) { |
| 509 | SkDebugf("%.0f", weight); |
| 510 | } else { |
| 511 | SkDebugf("%1.9gf", weight); |
| 512 | } |
| 513 | } |
| 514 | SkDebugf("}\n"); |
| 515 | } |
| 516 | |
| 517 | void SkOpGlobalState::debugLoopReport() { |
| 518 | const char* loops[] = { "iterations", "coinChecks", "perpCalcs" }; |
| 519 | SkDebugf("\n"); |
| 520 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 521 | SkDebugf("%s: %d\n", loops[index], fDebugLoopCount[index]); |
| 522 | dump_curve(fDebugWorstVerb[index * 2], fDebugWorstPts[index * 2 * 4], |
| 523 | fDebugWorstWeight[index * 2]); |
| 524 | dump_curve(fDebugWorstVerb[index * 2 + 1], fDebugWorstPts[(index * 2 + 1) * 4], |
| 525 | fDebugWorstWeight[index * 2 + 1]); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | void SkOpGlobalState::debugResetLoopCounts() { |
| 530 | sk_bzero(fDebugLoopCount, sizeof(fDebugLoopCount)); |
| 531 | sk_bzero(fDebugWorstVerb, sizeof(fDebugWorstVerb)); |
| 532 | sk_bzero(fDebugWorstPts, sizeof(fDebugWorstPts)); |
| 533 | sk_bzero(fDebugWorstWeight, sizeof(fDebugWorstWeight)); |
| 534 | } |
| 535 | #endif |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 536 | |
| 537 | #ifdef SK_DEBUG |
| 538 | bool SkOpGlobalState::debugRunFail() const { |
| 539 | #if DEBUG_VALIDATE |
| 540 | return FLAGS_runFail; |
| 541 | #else |
| 542 | return false; |
| 543 | #endif |
| 544 | } |
| 545 | #endif |
| 546 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 547 | #if DEBUG_T_SECT_LOOP_COUNT |
| 548 | void SkIntersections::debugBumpLoopCount(DebugLoop index) { |
| 549 | fDebugLoopCount[index]++; |
| 550 | } |
| 551 | |
| 552 | int SkIntersections::debugLoopCount(DebugLoop index) const { |
| 553 | return fDebugLoopCount[index]; |
| 554 | } |
| 555 | |
| 556 | void SkIntersections::debugResetLoopCount() { |
| 557 | sk_bzero(fDebugLoopCount, sizeof(fDebugLoopCount)); |
| 558 | } |
| 559 | #endif |
| 560 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 561 | #include "SkPathOpsCubic.h" |
| 562 | #include "SkPathOpsQuad.h" |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 563 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 564 | SkDCubic SkDQuad::debugToCubic() const { |
| 565 | SkDCubic cubic; |
| 566 | cubic[0] = fPts[0]; |
| 567 | cubic[2] = fPts[1]; |
| 568 | cubic[3] = fPts[2]; |
| 569 | cubic[1].fX = (cubic[0].fX + cubic[2].fX * 2) / 3; |
| 570 | cubic[1].fY = (cubic[0].fY + cubic[2].fY * 2) / 3; |
| 571 | cubic[2].fX = (cubic[3].fX + cubic[2].fX * 2) / 3; |
| 572 | cubic[2].fY = (cubic[3].fY + cubic[2].fY * 2) / 3; |
| 573 | return cubic; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 574 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 575 | |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 576 | void SkDRect::debugInit() { |
| 577 | fLeft = fTop = fRight = fBottom = SK_ScalarNaN; |
| 578 | } |
| 579 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 580 | #include "SkOpAngle.h" |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 581 | #include "SkOpSegment.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 582 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 583 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 584 | // commented-out lines keep this in sync with addT() |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 585 | const SkOpPtT* SkOpSegment::debugAddT(double t) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 586 | debugValidate(); |
| 587 | SkPoint pt = this->ptAtT(t); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 588 | const SkOpSpanBase* span = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 589 | do { |
| 590 | const SkOpPtT* result = span->ptT(); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 591 | if (t == result->fT || this->match(result, this, t, pt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 592 | // span->bumpSpanAdds(); |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 593 | return result; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 594 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 595 | if (t < result->fT) { |
| 596 | const SkOpSpan* prev = result->span()->prev(); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 597 | FAIL_WITH_NULL_IF(!prev); |
| 598 | // marks in global state that new op span has been allocated |
| 599 | this->globalState()->setAllocatedOpSpan(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 600 | // span->init(this, prev, t, pt); |
| 601 | this->debugValidate(); |
| 602 | // #if DEBUG_ADD_T |
| 603 | // SkDebugf("%s insert t=%1.9g segID=%d spanID=%d\n", __FUNCTION__, t, |
| 604 | // span->segment()->debugID(), span->debugID()); |
| 605 | // #endif |
| 606 | // span->bumpSpanAdds(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 607 | return nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 608 | } |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 609 | FAIL_WITH_NULL_IF(span != &fTail); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 610 | } while ((span = span->upCast()->next())); |
| 611 | SkASSERT(0); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 612 | return nullptr; // we never get here, but need this to satisfy compiler |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 613 | } |
| 614 | #endif |
| 615 | |
| 616 | #if DEBUG_ANGLE |
| 617 | void SkOpSegment::debugCheckAngleCoin() const { |
| 618 | const SkOpSpanBase* base = &fHead; |
| 619 | const SkOpSpan* span; |
| 620 | do { |
| 621 | const SkOpAngle* angle = base->fromAngle(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 622 | if (angle && angle->debugCheckCoincidence()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 623 | angle->debugCheckNearCoincidence(); |
| 624 | } |
| 625 | if (base->final()) { |
| 626 | break; |
| 627 | } |
| 628 | span = base->upCast(); |
| 629 | angle = span->toAngle(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 630 | if (angle && angle->debugCheckCoincidence()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 631 | angle->debugCheckNearCoincidence(); |
| 632 | } |
| 633 | } while ((base = span->next())); |
| 634 | } |
| 635 | #endif |
| 636 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 637 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 638 | // this mimics the order of the checks in handle coincidence |
| 639 | void SkOpSegment::debugCheckHealth(const char* id, SkPathOpsDebug::GlitchLog* glitches) const { |
| 640 | debugMoveMultiples(id, glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 641 | debugMoveNearby(id, glitches); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 642 | debugMissingCoincidence(id, glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 643 | } |
| 644 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 645 | // commented-out lines keep this in sync with clearAll() |
| 646 | void SkOpSegment::debugClearAll(const char* id, SkPathOpsDebug::GlitchLog* glitches) const { |
| 647 | const SkOpSpan* span = &fHead; |
| 648 | do { |
| 649 | this->debugClearOne(span, id, glitches); |
| 650 | } while ((span = span->next()->upCastable())); |
| 651 | this->globalState()->coincidence()->debugRelease(id, glitches, this); |
| 652 | } |
| 653 | |
| 654 | // commented-out lines keep this in sync with clearOne() |
| 655 | void SkOpSegment::debugClearOne(const SkOpSpan* span, const char* id, SkPathOpsDebug::GlitchLog* glitches) const { |
| 656 | if (span->windValue()) glitches->record(kCollapsedWindValue_Glitch, id, span); |
| 657 | if (span->oppValue()) glitches->record(kCollapsedOppValue_Glitch, id, span); |
| 658 | if (!span->done()) glitches->record(kCollapsedDone_Glitch, id, span); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 659 | } |
| 660 | #endif |
| 661 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 662 | SkOpAngle* SkOpSegment::debugLastAngle() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 663 | SkOpAngle* result = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 664 | SkOpSpan* span = this->head(); |
| 665 | do { |
| 666 | if (span->toAngle()) { |
| 667 | SkASSERT(!result); |
| 668 | result = span->toAngle(); |
| 669 | } |
| 670 | } while ((span = span->next()->upCastable())); |
| 671 | SkASSERT(result); |
| 672 | return result; |
| 673 | } |
| 674 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 675 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 676 | // commented-out lines keep this in sync with ClearVisited |
| 677 | void SkOpSegment::DebugClearVisited(const SkOpSpanBase* span) { |
| 678 | // reset visited flag back to false |
| 679 | do { |
| 680 | const SkOpPtT* ptT = span->ptT(), * stopPtT = ptT; |
| 681 | while ((ptT = ptT->next()) != stopPtT) { |
| 682 | const SkOpSegment* opp = ptT->segment(); |
| 683 | opp->resetDebugVisited(); |
| 684 | } |
| 685 | } while (!span->final() && (span = span->upCast()->next())); |
| 686 | } |
| 687 | #endif |
| 688 | |
| 689 | #if DEBUG_COINCIDENCE_VERBOSE |
| 690 | // commented-out lines keep this in sync with missingCoincidence() |
| 691 | // look for pairs of undetected coincident curves |
| 692 | // assumes that segments going in have visited flag clear |
| 693 | // Even though pairs of curves correct detect coincident runs, a run may be missed |
| 694 | // if the coincidence is a product of multiple intersections. For instance, given |
| 695 | // curves A, B, and C: |
| 696 | // A-B intersect at a point 1; A-C and B-C intersect at point 2, so near |
| 697 | // the end of C that the intersection is replaced with the end of C. |
| 698 | // Even though A-B correctly do not detect an intersection at point 2, |
| 699 | // the resulting run from point 1 to point 2 is coincident on A and B. |
| 700 | void SkOpSegment::debugMissingCoincidence(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 701 | if (this->done()) { |
| 702 | return; |
| 703 | } |
| 704 | const SkOpSpan* prior = nullptr; |
| 705 | const SkOpSpanBase* spanBase = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 706 | // bool result = false; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 707 | do { |
| 708 | const SkOpPtT* ptT = spanBase->ptT(), * spanStopPtT = ptT; |
| 709 | SkASSERT(ptT->span() == spanBase); |
| 710 | while ((ptT = ptT->next()) != spanStopPtT) { |
| 711 | if (ptT->deleted()) { |
| 712 | continue; |
| 713 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 714 | const SkOpSegment* opp = ptT->span()->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 715 | if (opp->done()) { |
| 716 | continue; |
| 717 | } |
| 718 | // when opp is encounted the 1st time, continue; on 2nd encounter, look for coincidence |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 719 | if (!opp->debugVisited()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 720 | continue; |
| 721 | } |
| 722 | if (spanBase == &fHead) { |
| 723 | continue; |
| 724 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 725 | if (ptT->segment() == this) { |
| 726 | continue; |
| 727 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 728 | const SkOpSpan* span = spanBase->upCastable(); |
| 729 | // FIXME?: this assumes that if the opposite segment is coincident then no more |
| 730 | // coincidence needs to be detected. This may not be true. |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 731 | if (span && span->segment() != opp && span->containsCoincidence(opp)) { // debug has additional condition since it may be called before inner duplicate points have been deleted |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 732 | continue; |
| 733 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 734 | if (spanBase->segment() != opp && spanBase->containsCoinEnd(opp)) { // debug has additional condition since it may be called before inner duplicate points have been deleted |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 735 | continue; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 736 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 737 | const SkOpPtT* priorPtT = nullptr, * priorStopPtT; |
| 738 | // find prior span containing opp segment |
| 739 | const SkOpSegment* priorOpp = nullptr; |
| 740 | const SkOpSpan* priorTest = spanBase->prev(); |
| 741 | while (!priorOpp && priorTest) { |
| 742 | priorStopPtT = priorPtT = priorTest->ptT(); |
| 743 | while ((priorPtT = priorPtT->next()) != priorStopPtT) { |
| 744 | if (priorPtT->deleted()) { |
| 745 | continue; |
| 746 | } |
| 747 | SkOpSegment* segment = priorPtT->span()->segment(); |
| 748 | if (segment == opp) { |
| 749 | prior = priorTest; |
| 750 | priorOpp = opp; |
| 751 | break; |
| 752 | } |
| 753 | } |
| 754 | priorTest = priorTest->prev(); |
| 755 | } |
| 756 | if (!priorOpp) { |
| 757 | continue; |
| 758 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 759 | if (priorPtT == ptT) { |
| 760 | continue; |
| 761 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 762 | const SkOpPtT* oppStart = prior->ptT(); |
| 763 | const SkOpPtT* oppEnd = spanBase->ptT(); |
| 764 | bool swapped = priorPtT->fT > ptT->fT; |
| 765 | if (swapped) { |
| 766 | SkTSwap(priorPtT, ptT); |
| 767 | SkTSwap(oppStart, oppEnd); |
| 768 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 769 | const SkOpCoincidence* coincidence = this->globalState()->coincidence(); |
| 770 | const SkOpPtT* rootPriorPtT = priorPtT->span()->ptT(); |
| 771 | const SkOpPtT* rootPtT = ptT->span()->ptT(); |
| 772 | const SkOpPtT* rootOppStart = oppStart->span()->ptT(); |
| 773 | const SkOpPtT* rootOppEnd = oppEnd->span()->ptT(); |
| 774 | if (coincidence->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd)) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 775 | goto swapBack; |
| 776 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 777 | if (testForCoincidence(rootPriorPtT, rootPtT, prior, spanBase, opp)) { |
| 778 | // mark coincidence |
| 779 | #if DEBUG_COINCIDENCE |
| 780 | // SkDebugf("%s coinSpan=%d endSpan=%d oppSpan=%d oppEndSpan=%d\n", __FUNCTION__, |
| 781 | // rootPriorPtT->debugID(), rootPtT->debugID(), rootOppStart->debugID(), |
| 782 | // rootOppEnd->debugID()); |
| 783 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 784 | log->record(kMissingCoin_Glitch, id, priorPtT, ptT, oppStart, oppEnd); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 785 | // coincidences->add(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd); |
| 786 | // } |
| 787 | #if DEBUG_COINCIDENCE |
caryclark | d656200 | 2016-07-27 12:02:07 -0700 | [diff] [blame] | 788 | // SkASSERT(coincidences->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 789 | #endif |
| 790 | // result = true; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 791 | } |
| 792 | swapBack: |
| 793 | if (swapped) { |
| 794 | SkTSwap(priorPtT, ptT); |
| 795 | } |
| 796 | } |
| 797 | } while ((spanBase = spanBase->final() ? nullptr : spanBase->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 798 | DebugClearVisited(&fHead); |
| 799 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 800 | } |
| 801 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 802 | // commented-out lines keep this in sync with moveMultiples() |
| 803 | // if a span has more than one intersection, merge the other segments' span as needed |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 804 | void SkOpSegment::debugMoveMultiples(const char* id, SkPathOpsDebug::GlitchLog* glitches) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 805 | debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 806 | const SkOpSpanBase* test = &fHead; |
| 807 | do { |
| 808 | int addCount = test->spanAddsCount(); |
| 809 | SkASSERT(addCount >= 1); |
| 810 | if (addCount == 1) { |
| 811 | continue; |
| 812 | } |
| 813 | const SkOpPtT* startPtT = test->ptT(); |
| 814 | const SkOpPtT* testPtT = startPtT; |
| 815 | do { // iterate through all spans associated with start |
| 816 | const SkOpSpanBase* oppSpan = testPtT->span(); |
| 817 | if (oppSpan->spanAddsCount() == addCount) { |
| 818 | continue; |
| 819 | } |
| 820 | if (oppSpan->deleted()) { |
| 821 | continue; |
| 822 | } |
| 823 | const SkOpSegment* oppSegment = oppSpan->segment(); |
| 824 | if (oppSegment == this) { |
| 825 | continue; |
| 826 | } |
| 827 | // find range of spans to consider merging |
| 828 | const SkOpSpanBase* oppPrev = oppSpan; |
| 829 | const SkOpSpanBase* oppFirst = oppSpan; |
| 830 | while ((oppPrev = oppPrev->prev())) { |
| 831 | if (!roughly_equal(oppPrev->t(), oppSpan->t())) { |
| 832 | break; |
| 833 | } |
| 834 | if (oppPrev->spanAddsCount() == addCount) { |
| 835 | continue; |
| 836 | } |
| 837 | if (oppPrev->deleted()) { |
| 838 | continue; |
| 839 | } |
| 840 | oppFirst = oppPrev; |
| 841 | } |
| 842 | const SkOpSpanBase* oppNext = oppSpan; |
| 843 | const SkOpSpanBase* oppLast = oppSpan; |
| 844 | while ((oppNext = oppNext->final() ? nullptr : oppNext->upCast()->next())) { |
| 845 | if (!roughly_equal(oppNext->t(), oppSpan->t())) { |
| 846 | break; |
| 847 | } |
| 848 | if (oppNext->spanAddsCount() == addCount) { |
| 849 | continue; |
| 850 | } |
| 851 | if (oppNext->deleted()) { |
| 852 | continue; |
| 853 | } |
| 854 | oppLast = oppNext; |
| 855 | } |
| 856 | if (oppFirst == oppLast) { |
| 857 | continue; |
| 858 | } |
| 859 | const SkOpSpanBase* oppTest = oppFirst; |
| 860 | do { |
| 861 | if (oppTest == oppSpan) { |
| 862 | continue; |
| 863 | } |
| 864 | // check to see if the candidate meets specific criteria: |
| 865 | // it contains spans of segments in test's loop but not including 'this' |
| 866 | const SkOpPtT* oppStartPtT = oppTest->ptT(); |
| 867 | const SkOpPtT* oppPtT = oppStartPtT; |
| 868 | while ((oppPtT = oppPtT->next()) != oppStartPtT) { |
| 869 | const SkOpSegment* oppPtTSegment = oppPtT->segment(); |
| 870 | if (oppPtTSegment == this) { |
| 871 | goto tryNextSpan; |
| 872 | } |
| 873 | const SkOpPtT* matchPtT = startPtT; |
| 874 | do { |
| 875 | if (matchPtT->segment() == oppPtTSegment) { |
| 876 | goto foundMatch; |
| 877 | } |
| 878 | } while ((matchPtT = matchPtT->next()) != startPtT); |
| 879 | goto tryNextSpan; |
| 880 | foundMatch: // merge oppTest and oppSpan |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 881 | oppSegment->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 882 | if (oppTest == &oppSegment->fTail || oppTest == &oppSegment->fHead) { |
| 883 | SkASSERT(oppSpan != &oppSegment->fHead); // don't expect collapse |
| 884 | SkASSERT(oppSpan != &oppSegment->fTail); |
| 885 | glitches->record(kMoveMultiple_Glitch, id, oppTest, oppSpan); |
| 886 | } else { |
| 887 | glitches->record(kMoveMultiple_Glitch, id, oppSpan, oppTest); |
| 888 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 889 | oppSegment->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 890 | goto checkNextSpan; |
| 891 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 892 | tryNextSpan: |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 893 | ; |
| 894 | } while (oppTest != oppLast && (oppTest = oppTest->upCast()->next())); |
| 895 | } while ((testPtT = testPtT->next()) != startPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 896 | checkNextSpan: |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 897 | ; |
| 898 | } while ((test = test->final() ? nullptr : test->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 899 | debugValidate(); |
| 900 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 901 | } |
| 902 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 903 | // commented-out lines keep this in sync with moveNearby() |
| 904 | // Move nearby t values and pts so they all hang off the same span. Alignment happens later. |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 905 | void SkOpSegment::debugMoveNearby(const char* id, SkPathOpsDebug::GlitchLog* glitches) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 906 | debugValidate(); |
| 907 | // release undeleted spans pointing to this seg that are linked to the primary span |
| 908 | const SkOpSpanBase* spanBase = &fHead; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 909 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 910 | const SkOpPtT* ptT = spanBase->ptT(); |
| 911 | const SkOpPtT* headPtT = ptT; |
| 912 | while ((ptT = ptT->next()) != headPtT) { |
| 913 | const SkOpSpanBase* test = ptT->span(); |
| 914 | if (ptT->segment() == this && !ptT->deleted() && test != spanBase |
| 915 | && test->ptT() == ptT) { |
| 916 | if (test->final()) { |
| 917 | if (spanBase == &fHead) { |
| 918 | glitches->record(kMoveNearbyClearAll_Glitch, id, this); |
| 919 | // return; |
| 920 | } |
| 921 | glitches->record(kMoveNearbyReleaseFinal_Glitch, id, spanBase, ptT); |
| 922 | } else if (test->prev()) { |
| 923 | glitches->record(kMoveNearbyRelease_Glitch, id, test, headPtT); |
| 924 | } |
| 925 | // break; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 928 | spanBase = spanBase->upCast()->next(); |
| 929 | } while (!spanBase->final()); |
| 930 | |
| 931 | // This loop looks for adjacent spans which are near by |
| 932 | spanBase = &fHead; |
| 933 | do { // iterate through all spans associated with start |
| 934 | const SkOpSpanBase* test = spanBase->upCast()->next(); |
| 935 | if (this->spansNearby(spanBase, test)) { |
| 936 | if (test->final()) { |
| 937 | if (spanBase->prev()) { |
| 938 | glitches->record(kMoveNearbyMergeFinal_Glitch, id, test); |
| 939 | } else { |
| 940 | glitches->record(kMoveNearbyClearAll2_Glitch, id, this); |
| 941 | // return |
| 942 | } |
| 943 | } else { |
| 944 | glitches->record(kMoveNearbyMerge_Glitch, id, spanBase); |
| 945 | } |
| 946 | } |
| 947 | spanBase = test; |
| 948 | } while (!spanBase->final()); |
| 949 | debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 950 | } |
| 951 | #endif |
| 952 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 953 | void SkOpSegment::debugReset() { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 954 | this->init(this->fPts, this->fWeight, this->contour(), this->verb()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 955 | } |
| 956 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 957 | #if DEBUG_COINCIDENCE_ORDER |
| 958 | void SkOpSegment::debugSetCoinT(int index, SkScalar t) const { |
| 959 | if (fDebugBaseMax < 0 || fDebugBaseIndex == index) { |
| 960 | fDebugBaseIndex = index; |
| 961 | fDebugBaseMin = SkTMin(t, fDebugBaseMin); |
| 962 | fDebugBaseMax = SkTMax(t, fDebugBaseMax); |
| 963 | return; |
| 964 | } |
| 965 | SkASSERT(fDebugBaseMin >= t || t >= fDebugBaseMax); |
| 966 | if (fDebugLastMax < 0 || fDebugLastIndex == index) { |
| 967 | fDebugLastIndex = index; |
| 968 | fDebugLastMin = SkTMin(t, fDebugLastMin); |
| 969 | fDebugLastMax = SkTMax(t, fDebugLastMax); |
| 970 | return; |
| 971 | } |
| 972 | SkASSERT(fDebugLastMin >= t || t >= fDebugLastMax); |
| 973 | SkASSERT((t - fDebugBaseMin > 0) == (fDebugLastMin - fDebugBaseMin > 0)); |
| 974 | } |
| 975 | #endif |
| 976 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 977 | #if DEBUG_ACTIVE_SPANS |
| 978 | void SkOpSegment::debugShowActiveSpans() const { |
| 979 | debugValidate(); |
| 980 | if (done()) { |
| 981 | return; |
| 982 | } |
| 983 | int lastId = -1; |
| 984 | double lastT = -1; |
| 985 | const SkOpSpan* span = &fHead; |
| 986 | do { |
| 987 | if (span->done()) { |
| 988 | continue; |
| 989 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 990 | if (lastId == this->debugID() && lastT == span->t()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 991 | continue; |
| 992 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 993 | lastId = this->debugID(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 994 | lastT = span->t(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 995 | SkDebugf("%s id=%d", __FUNCTION__, this->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 996 | // since endpoints may have be adjusted, show actual computed curves |
| 997 | SkDCurve curvePart; |
| 998 | this->subDivide(span, span->next(), &curvePart); |
| 999 | const SkDPoint* pts = curvePart.fCubic.fPts; |
| 1000 | SkDebugf(" (%1.9g,%1.9g", pts[0].fX, pts[0].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1001 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1002 | SkDebugf(" %1.9g,%1.9g", pts[vIndex].fX, pts[vIndex].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1003 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1004 | if (SkPath::kConic_Verb == fVerb) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1005 | SkDebugf(" %1.9gf", curvePart.fConic.fWeight); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1006 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1007 | SkDebugf(") t=%1.9g tEnd=%1.9g", span->t(), span->next()->t()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1008 | if (span->windSum() == SK_MinS32) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1009 | SkDebugf(" windSum=?"); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1010 | } else { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1011 | SkDebugf(" windSum=%d", span->windSum()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1012 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1013 | if (span->oppValue() && span->oppSum() == SK_MinS32) { |
| 1014 | SkDebugf(" oppSum=?"); |
| 1015 | } else if (span->oppValue() || span->oppSum() != SK_MinS32) { |
| 1016 | SkDebugf(" oppSum=%d", span->oppSum()); |
| 1017 | } |
| 1018 | SkDebugf(" windValue=%d", span->windValue()); |
| 1019 | if (span->oppValue() || span->oppSum() != SK_MinS32) { |
| 1020 | SkDebugf(" oppValue=%d", span->oppValue()); |
| 1021 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1022 | SkDebugf("\n"); |
| 1023 | } while ((span = span->next()->upCastable())); |
| 1024 | } |
| 1025 | #endif |
| 1026 | |
| 1027 | #if DEBUG_MARK_DONE |
| 1028 | void SkOpSegment::debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding) { |
| 1029 | const SkPoint& pt = span->ptT()->fPt; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1030 | SkDebugf("%s id=%d", fun, this->debugID()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1031 | SkDebugf(" (%1.9g,%1.9g", fPts[0].fX, fPts[0].fY); |
| 1032 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
| 1033 | SkDebugf(" %1.9g,%1.9g", fPts[vIndex].fX, fPts[vIndex].fY); |
| 1034 | } |
| 1035 | SkDebugf(") t=%1.9g [%d] (%1.9g,%1.9g) tEnd=%1.9g newWindSum=", |
| 1036 | span->t(), span->debugID(), pt.fX, pt.fY, span->next()->t()); |
| 1037 | if (winding == SK_MinS32) { |
| 1038 | SkDebugf("?"); |
| 1039 | } else { |
| 1040 | SkDebugf("%d", winding); |
| 1041 | } |
| 1042 | SkDebugf(" windSum="); |
| 1043 | if (span->windSum() == SK_MinS32) { |
| 1044 | SkDebugf("?"); |
| 1045 | } else { |
| 1046 | SkDebugf("%d", span->windSum()); |
| 1047 | } |
| 1048 | SkDebugf(" windValue=%d\n", span->windValue()); |
| 1049 | } |
| 1050 | |
| 1051 | void SkOpSegment::debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding, |
| 1052 | int oppWinding) { |
| 1053 | const SkPoint& pt = span->ptT()->fPt; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1054 | SkDebugf("%s id=%d", fun, this->debugID()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1055 | SkDebugf(" (%1.9g,%1.9g", fPts[0].fX, fPts[0].fY); |
| 1056 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
| 1057 | SkDebugf(" %1.9g,%1.9g", fPts[vIndex].fX, fPts[vIndex].fY); |
| 1058 | } |
| 1059 | SkDebugf(") t=%1.9g [%d] (%1.9g,%1.9g) tEnd=%1.9g newWindSum=", |
| 1060 | span->t(), span->debugID(), pt.fX, pt.fY, span->next()->t(), winding, oppWinding); |
| 1061 | if (winding == SK_MinS32) { |
| 1062 | SkDebugf("?"); |
| 1063 | } else { |
| 1064 | SkDebugf("%d", winding); |
| 1065 | } |
| 1066 | SkDebugf(" newOppSum="); |
| 1067 | if (oppWinding == SK_MinS32) { |
| 1068 | SkDebugf("?"); |
| 1069 | } else { |
| 1070 | SkDebugf("%d", oppWinding); |
| 1071 | } |
| 1072 | SkDebugf(" oppSum="); |
| 1073 | if (span->oppSum() == SK_MinS32) { |
| 1074 | SkDebugf("?"); |
| 1075 | } else { |
| 1076 | SkDebugf("%d", span->oppSum()); |
| 1077 | } |
| 1078 | SkDebugf(" windSum="); |
| 1079 | if (span->windSum() == SK_MinS32) { |
| 1080 | SkDebugf("?"); |
| 1081 | } else { |
| 1082 | SkDebugf("%d", span->windSum()); |
| 1083 | } |
| 1084 | SkDebugf(" windValue=%d oppValue=%d\n", span->windValue(), span->oppValue()); |
| 1085 | } |
| 1086 | |
| 1087 | #endif |
| 1088 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1089 | // loop looking for a pair of angle parts that are too close to be sorted |
| 1090 | /* This is called after other more simple intersection and angle sorting tests have been exhausted. |
| 1091 | This should be rarely called -- the test below is thorough and time consuming. |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1092 | This checks the distance between start points; the distance between |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1093 | */ |
| 1094 | #if DEBUG_ANGLE |
| 1095 | void SkOpAngle::debugCheckNearCoincidence() const { |
| 1096 | const SkOpAngle* test = this; |
| 1097 | do { |
| 1098 | const SkOpSegment* testSegment = test->segment(); |
| 1099 | double testStartT = test->start()->t(); |
| 1100 | SkDPoint testStartPt = testSegment->dPtAtT(testStartT); |
| 1101 | double testEndT = test->end()->t(); |
| 1102 | SkDPoint testEndPt = testSegment->dPtAtT(testEndT); |
| 1103 | double testLenSq = testStartPt.distanceSquared(testEndPt); |
| 1104 | SkDebugf("%s testLenSq=%1.9g id=%d\n", __FUNCTION__, testLenSq, testSegment->debugID()); |
| 1105 | double testMidT = (testStartT + testEndT) / 2; |
| 1106 | const SkOpAngle* next = test; |
| 1107 | while ((next = next->fNext) != this) { |
| 1108 | SkOpSegment* nextSegment = next->segment(); |
| 1109 | double testMidDistSq = testSegment->distSq(testMidT, next); |
| 1110 | double testEndDistSq = testSegment->distSq(testEndT, next); |
| 1111 | double nextStartT = next->start()->t(); |
| 1112 | SkDPoint nextStartPt = nextSegment->dPtAtT(nextStartT); |
| 1113 | double distSq = testStartPt.distanceSquared(nextStartPt); |
| 1114 | double nextEndT = next->end()->t(); |
| 1115 | double nextMidT = (nextStartT + nextEndT) / 2; |
| 1116 | double nextMidDistSq = nextSegment->distSq(nextMidT, test); |
| 1117 | double nextEndDistSq = nextSegment->distSq(nextEndT, test); |
| 1118 | SkDebugf("%s distSq=%1.9g testId=%d nextId=%d\n", __FUNCTION__, distSq, |
| 1119 | testSegment->debugID(), nextSegment->debugID()); |
| 1120 | SkDebugf("%s testMidDistSq=%1.9g\n", __FUNCTION__, testMidDistSq); |
| 1121 | SkDebugf("%s testEndDistSq=%1.9g\n", __FUNCTION__, testEndDistSq); |
| 1122 | SkDebugf("%s nextMidDistSq=%1.9g\n", __FUNCTION__, nextMidDistSq); |
| 1123 | SkDebugf("%s nextEndDistSq=%1.9g\n", __FUNCTION__, nextEndDistSq); |
| 1124 | SkDPoint nextEndPt = nextSegment->dPtAtT(nextEndT); |
| 1125 | double nextLenSq = nextStartPt.distanceSquared(nextEndPt); |
| 1126 | SkDebugf("%s nextLenSq=%1.9g\n", __FUNCTION__, nextLenSq); |
| 1127 | SkDebugf("\n"); |
| 1128 | } |
| 1129 | test = test->fNext; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1130 | } while (test->fNext != this); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1131 | } |
| 1132 | #endif |
| 1133 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1134 | #if DEBUG_ANGLE |
| 1135 | SkString SkOpAngle::debugPart() const { |
| 1136 | SkString result; |
| 1137 | switch (this->segment()->verb()) { |
| 1138 | case SkPath::kLine_Verb: |
| 1139 | result.printf(LINE_DEBUG_STR " id=%d", LINE_DEBUG_DATA(fCurvePart), |
| 1140 | this->segment()->debugID()); |
| 1141 | break; |
| 1142 | case SkPath::kQuad_Verb: |
| 1143 | result.printf(QUAD_DEBUG_STR " id=%d", QUAD_DEBUG_DATA(fCurvePart), |
| 1144 | this->segment()->debugID()); |
| 1145 | break; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1146 | case SkPath::kConic_Verb: |
| 1147 | result.printf(CONIC_DEBUG_STR " id=%d", |
| 1148 | CONIC_DEBUG_DATA(fCurvePart, fCurvePart.fConic.fWeight), |
| 1149 | this->segment()->debugID()); |
| 1150 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1151 | case SkPath::kCubic_Verb: |
| 1152 | result.printf(CUBIC_DEBUG_STR " id=%d", CUBIC_DEBUG_DATA(fCurvePart), |
| 1153 | this->segment()->debugID()); |
| 1154 | break; |
| 1155 | default: |
| 1156 | SkASSERT(0); |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 1157 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1158 | return result; |
| 1159 | } |
| 1160 | #endif |
| 1161 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1162 | #if DEBUG_SORT |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1163 | void SkOpAngle::debugLoop() const { |
caryclark | e4097e3 | 2014-06-18 07:24:19 -0700 | [diff] [blame] | 1164 | const SkOpAngle* first = this; |
| 1165 | const SkOpAngle* next = this; |
| 1166 | do { |
| 1167 | next->dumpOne(true); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1168 | SkDebugf("\n"); |
caryclark | e4097e3 | 2014-06-18 07:24:19 -0700 | [diff] [blame] | 1169 | next = next->fNext; |
| 1170 | } while (next && next != first); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1171 | next = first; |
| 1172 | do { |
| 1173 | next->debugValidate(); |
| 1174 | next = next->fNext; |
| 1175 | } while (next && next != first); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1176 | } |
| 1177 | #endif |
| 1178 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1179 | void SkOpAngle::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1180 | #if DEBUG_COINCIDENCE |
| 1181 | if (this->globalState()->debugCheckHealth()) { |
| 1182 | return; |
| 1183 | } |
| 1184 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1185 | #if DEBUG_VALIDATE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1186 | const SkOpAngle* first = this; |
| 1187 | const SkOpAngle* next = this; |
| 1188 | int wind = 0; |
| 1189 | int opp = 0; |
| 1190 | int lastXor = -1; |
| 1191 | int lastOppXor = -1; |
| 1192 | do { |
| 1193 | if (next->unorderable()) { |
| 1194 | return; |
| 1195 | } |
| 1196 | const SkOpSpan* minSpan = next->start()->starter(next->end()); |
| 1197 | if (minSpan->windValue() == SK_MinS32) { |
| 1198 | return; |
| 1199 | } |
| 1200 | bool op = next->segment()->operand(); |
| 1201 | bool isXor = next->segment()->isXor(); |
| 1202 | bool oppXor = next->segment()->oppXor(); |
| 1203 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || between(0, minSpan->windValue(), DEBUG_LIMIT_WIND_SUM)); |
| 1204 | SkASSERT(!DEBUG_LIMIT_WIND_SUM |
| 1205 | || between(-DEBUG_LIMIT_WIND_SUM, minSpan->oppValue(), DEBUG_LIMIT_WIND_SUM)); |
| 1206 | bool useXor = op ? oppXor : isXor; |
| 1207 | SkASSERT(lastXor == -1 || lastXor == (int) useXor); |
| 1208 | lastXor = (int) useXor; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1209 | wind += next->debugSign() * (op ? minSpan->oppValue() : minSpan->windValue()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1210 | if (useXor) { |
| 1211 | wind &= 1; |
| 1212 | } |
| 1213 | useXor = op ? isXor : oppXor; |
| 1214 | SkASSERT(lastOppXor == -1 || lastOppXor == (int) useXor); |
| 1215 | lastOppXor = (int) useXor; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1216 | opp += next->debugSign() * (op ? minSpan->windValue() : minSpan->oppValue()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1217 | if (useXor) { |
| 1218 | opp &= 1; |
| 1219 | } |
| 1220 | next = next->fNext; |
| 1221 | } while (next && next != first); |
caryclark | 182b499 | 2015-05-14 05:45:54 -0700 | [diff] [blame] | 1222 | SkASSERT(wind == 0 || !FLAGS_runFail); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1223 | SkASSERT(opp == 0 || !FLAGS_runFail); |
| 1224 | #endif |
| 1225 | } |
| 1226 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1227 | void SkOpAngle::debugValidateNext() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1228 | #if !FORCE_RELEASE |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1229 | const SkOpAngle* first = this; |
| 1230 | const SkOpAngle* next = first; |
| 1231 | SkTDArray<const SkOpAngle*>(angles); |
| 1232 | do { |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1233 | // SkASSERT_RELEASE(next->fSegment->debugContains(next)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1234 | angles.push(next); |
| 1235 | next = next->next(); |
| 1236 | if (next == first) { |
| 1237 | break; |
| 1238 | } |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1239 | SkASSERT_RELEASE(!angles.contains(next)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1240 | if (!next) { |
| 1241 | return; |
| 1242 | } |
| 1243 | } while (true); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1244 | #endif |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1245 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1246 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1247 | #ifdef SK_DEBUG |
| 1248 | void SkCoincidentSpans::debugStartCheck(const SkOpSpanBase* outer, const SkOpSpanBase* over, |
| 1249 | const SkOpGlobalState* debugState) const { |
| 1250 | SkASSERT(coinPtTEnd()->span() == over || !debugState->debugRunFail()); |
| 1251 | SkASSERT(oppPtTEnd()->span() == outer || !debugState->debugRunFail()); |
| 1252 | } |
| 1253 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1254 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1255 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1256 | /* Commented-out lines keep this in sync with expand */ |
| 1257 | bool SkCoincidentSpans::debugExpand(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1258 | bool expanded = false; |
| 1259 | const SkOpSegment* segment = coinPtTStart()->segment(); |
| 1260 | const SkOpSegment* oppSegment = oppPtTStart()->segment(); |
| 1261 | do { |
| 1262 | const SkOpSpan* start = coinPtTStart()->span()->upCast(); |
| 1263 | const SkOpSpan* prev = start->prev(); |
| 1264 | const SkOpPtT* oppPtT; |
| 1265 | if (!prev || !(oppPtT = prev->contains(oppSegment))) { |
| 1266 | break; |
| 1267 | } |
| 1268 | double midT = (prev->t() + start->t()) / 2; |
| 1269 | if (!segment->isClose(midT, oppSegment)) { |
| 1270 | break; |
| 1271 | } |
| 1272 | if (log) log->record(kExpandCoin_Glitch, id, this, prev->ptT(), oppPtT); |
| 1273 | expanded = true; |
| 1274 | } while (false); // actual continues while expansion is possible |
| 1275 | do { |
| 1276 | const SkOpSpanBase* end = coinPtTEnd()->span(); |
| 1277 | SkOpSpanBase* next = end->final() ? nullptr : end->upCast()->next(); |
| 1278 | const SkOpPtT* oppPtT; |
| 1279 | if (!next || !(oppPtT = next->contains(oppSegment))) { |
| 1280 | break; |
| 1281 | } |
| 1282 | double midT = (end->t() + next->t()) / 2; |
| 1283 | if (!segment->isClose(midT, oppSegment)) { |
| 1284 | break; |
| 1285 | } |
| 1286 | if (log) log->record(kExpandCoin_Glitch, id, this, next->ptT(), oppPtT); |
| 1287 | expanded = true; |
| 1288 | } while (false); // actual continues while expansion is possible |
| 1289 | return expanded; |
| 1290 | } |
| 1291 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1292 | #undef FAIL_IF |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1293 | #define FAIL_IF(cond) do { if (cond) log->record(kAddExpandedFail_Glitch, id, coin); } while (false) |
| 1294 | |
| 1295 | /* Commented-out lines keep this in sync with addExpanded */ |
| 1296 | // for each coincident pair, match the spans |
| 1297 | // if the spans don't match, add the mssing pt to the segment and loop it in the opposite span |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1298 | void SkOpCoincidence::debugAddExpanded(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1299 | const SkCoincidentSpans* coin = this->fHead; |
| 1300 | if (!coin) { |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 1301 | return; |
| 1302 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1303 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1304 | const SkOpPtT* startPtT = coin->coinPtTStart(); |
| 1305 | const SkOpPtT* oStartPtT = coin->oppPtTStart(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1306 | SkASSERT(startPtT->contains(oStartPtT)); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1307 | SkASSERT(coin->coinPtTEnd()->contains(coin->oppPtTEnd())); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1308 | const SkOpSpanBase* start = startPtT->span(); |
| 1309 | const SkOpSpanBase* oStart = oStartPtT->span(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1310 | const SkOpSpanBase* end = coin->coinPtTEnd()->span(); |
| 1311 | const SkOpSpanBase* oEnd = coin->oppPtTEnd()->span(); |
| 1312 | FAIL_IF(oEnd->deleted()); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1313 | const SkOpSpanBase* test = start->upCast()->next(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1314 | const SkOpSpanBase* oTest = coin->flipped() ? oStart->prev() : oStart->upCast()->next(); |
| 1315 | if (!oTest) { |
| 1316 | return; |
| 1317 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1318 | while (test != end || oTest != oEnd) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1319 | if (!test->ptT()->contains(oTest->segment()) |
| 1320 | || !oTest->ptT()->contains(start->segment())) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1321 | // use t ranges to guess which one is missing |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1322 | double startRange = coin->coinPtTEnd()->fT - startPtT->fT; |
| 1323 | FAIL_IF(!startRange); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1324 | double startPart = (test->t() - startPtT->fT) / startRange; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1325 | double oStartRange = coin->oppPtTEnd()->fT - oStartPtT->fT; |
| 1326 | FAIL_IF(!oStartRange); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1327 | double oStartPart = (oTest->t() - oStartPtT->fT) / oStartRange; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1328 | FAIL_IF(startPart == oStartPart); |
| 1329 | bool startOver = false; |
| 1330 | if (startPart < oStartPart) |
| 1331 | log->record(kAddExpandedCoin_Glitch, id, // strange debug formatting lines up with original |
| 1332 | oStartPtT->fT + oStartRange * startPart, test); |
| 1333 | else log->record(kAddExpandedCoin_Glitch, id, |
| 1334 | startPtT->fT + startRange * oStartPart, oTest); |
| 1335 | if (false) { |
| 1336 | SkASSERT(0); |
| 1337 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1338 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1339 | if (startOver) { |
| 1340 | test = start; |
| 1341 | oTest = oStart; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1342 | } |
| 1343 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1344 | if (test != end) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1345 | test = test->upCast()->next(); |
| 1346 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1347 | if (oTest != oEnd) { |
| 1348 | oTest = coin->flipped() ? oTest->prev() : oTest->upCast()->next(); |
| 1349 | if (!oTest) { |
| 1350 | return; |
| 1351 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1354 | } while ((coin = coin->next())); |
| 1355 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1358 | /* Commented-out lines keep this in sync with addIfMissing() */ |
| 1359 | void SkOpCoincidence::debugAddIfMissing(const SkCoincidentSpans* outer, const SkOpPtT* over1s, |
| 1360 | const SkOpPtT* over1e, const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1361 | // SkASSERT(fTop); |
| 1362 | if (fTop && alreadyAdded(fTop, outer, over1s, over1e)) { // in debug, fTop may be null |
| 1363 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1364 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1365 | if (fHead && alreadyAdded(fHead, outer, over1s, over1e)) { |
| 1366 | return; |
| 1367 | } |
| 1368 | log->record(kAddIfMissingCoin_Glitch, id, outer->coinPtTStart(), outer->coinPtTEnd(), over1s, over1e); |
| 1369 | this->debugValidate(); |
| 1370 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1373 | /* Commented-out lines keep this in sync addIfMissing() */ |
| 1374 | void SkOpCoincidence::debugAddIfMissing(const SkOpPtT* over1s, const SkOpPtT* over1e, |
| 1375 | const SkOpPtT* over2s, const SkOpPtT* over2e, double tStart, double tEnd, |
| 1376 | const SkOpPtT* coinPtTStart, const SkOpPtT* coinPtTEnd, |
| 1377 | const SkOpPtT* oppPtTStart, const SkOpPtT* oppPtTEnd, const char* id, SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1378 | double coinTs, coinTe, oppTs, oppTe; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1379 | TRange(over1s, over1e, tStart, tEnd, coinPtTStart, coinPtTEnd, &coinTs, &coinTe); |
| 1380 | TRange(over2s, over2e, tStart, tEnd, oppPtTStart, oppPtTEnd, &oppTs, &oppTe); |
| 1381 | bool swap = coinTs > coinTe; |
| 1382 | if (swap) { |
| 1383 | SkTSwap(coinTs, coinTe); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1384 | } |
| 1385 | if ((over1s->fT < over1e->fT) != (over2s->fT < over2e->fT)) { |
| 1386 | SkTSwap(oppTs, oppTe); |
| 1387 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1388 | if (swap) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1389 | SkTSwap(oppTs, oppTe); |
| 1390 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1391 | const SkOpSegment* coinSeg = coinPtTStart->segment(); |
| 1392 | const SkOpSegment* oppSeg = oppPtTStart->segment(); |
| 1393 | if (coinSeg == oppSeg) { |
| 1394 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1395 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1396 | return this->debugAddOrOverlap(coinSeg, oppSeg, coinTs, coinTe, oppTs, oppTe, id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1399 | /* Commented-out lines keep this in sync addOrOverlap() */ |
| 1400 | void SkOpCoincidence::debugAddOrOverlap(const SkOpSegment* coinSeg, const SkOpSegment* oppSeg, |
| 1401 | double coinTs, double coinTe, double oppTs, double oppTe, const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1402 | SkTDArray<SkCoincidentSpans*> overlaps; |
| 1403 | SkASSERT(!fTop); // this is (correctly) reversed in addifMissing() |
| 1404 | if (fTop && !this->checkOverlap(fTop, coinSeg, oppSeg, coinTs, coinTe, oppTs, oppTe, &overlaps)) { |
| 1405 | return; |
| 1406 | } |
| 1407 | if (fHead && !this->checkOverlap(fHead, coinSeg, oppSeg, coinTs, |
| 1408 | coinTe, oppTs, oppTe, &overlaps)) { |
| 1409 | return; |
| 1410 | } |
| 1411 | const SkCoincidentSpans* overlap = overlaps.count() ? overlaps[0] : nullptr; |
| 1412 | for (int index = 1; index < overlaps.count(); ++index) { // combine overlaps before continuing |
| 1413 | const SkCoincidentSpans* test = overlaps[index]; |
| 1414 | if (overlap->coinPtTStart()->fT > test->coinPtTStart()->fT) { |
| 1415 | log->record(kAddOrOverlap_Glitch, id, overlap, test->coinPtTStart()); |
| 1416 | } |
| 1417 | if (overlap->coinPtTEnd()->fT < test->coinPtTEnd()->fT) { |
| 1418 | log->record(kAddOrOverlap_Glitch, id, overlap, test->coinPtTEnd()); |
| 1419 | } |
| 1420 | if (overlap->flipped() |
| 1421 | ? overlap->oppPtTStart()->fT < test->oppPtTStart()->fT |
| 1422 | : overlap->oppPtTStart()->fT > test->oppPtTStart()->fT) { |
| 1423 | log->record(kAddOrOverlap_Glitch, id, overlap, test->oppPtTStart()); |
| 1424 | } |
| 1425 | if (overlap->flipped() |
| 1426 | ? overlap->oppPtTEnd()->fT > test->oppPtTEnd()->fT |
| 1427 | : overlap->oppPtTEnd()->fT < test->oppPtTEnd()->fT) { |
| 1428 | log->record(kAddOrOverlap_Glitch, id, overlap, test->oppPtTEnd()); |
| 1429 | } |
| 1430 | if (!fHead) { |
| 1431 | SkAssertResult(true); |
| 1432 | } |
| 1433 | } |
| 1434 | const SkOpPtT* cs = coinSeg->existing(coinTs, oppSeg); |
| 1435 | const SkOpPtT* ce = coinSeg->existing(coinTe, oppSeg); |
| 1436 | if (overlap && cs && ce && overlap->contains(cs, ce)) { |
| 1437 | return; |
| 1438 | } |
| 1439 | SkASSERT(cs != ce || !cs); |
| 1440 | const SkOpPtT* os = oppSeg->existing(oppTs, coinSeg); |
| 1441 | const SkOpPtT* oe = oppSeg->existing(oppTe, coinSeg); |
| 1442 | if (overlap && os && oe && overlap->contains(os, oe)) { |
| 1443 | return; |
| 1444 | } |
| 1445 | SkASSERT(true || !cs || !cs->deleted()); |
| 1446 | SkASSERT(true || !os || !os->deleted()); |
| 1447 | SkASSERT(true || !ce || !ce->deleted()); |
| 1448 | SkASSERT(true || !oe || !oe->deleted()); |
| 1449 | const SkOpPtT* csExisting = !cs ? coinSeg->existing(coinTs, nullptr) : nullptr; |
| 1450 | const SkOpPtT* ceExisting = !ce ? coinSeg->existing(coinTe, nullptr) : nullptr; |
| 1451 | if (csExisting && csExisting == ceExisting) { |
| 1452 | return; |
| 1453 | } |
| 1454 | if (csExisting && (csExisting == ce || csExisting->contains(ceExisting ? ceExisting : ce))) { |
| 1455 | return; |
| 1456 | } |
| 1457 | if (ceExisting && (ceExisting == cs || ceExisting->contains(csExisting ? csExisting : cs))) { |
| 1458 | return; |
| 1459 | } |
| 1460 | const SkOpPtT* osExisting = !os ? oppSeg->existing(oppTs, nullptr) : nullptr; |
| 1461 | const SkOpPtT* oeExisting = !oe ? oppSeg->existing(oppTe, nullptr) : nullptr; |
| 1462 | if (osExisting && osExisting == oeExisting) { |
| 1463 | return; |
| 1464 | } |
| 1465 | if (osExisting && (osExisting == oe || osExisting->contains(oeExisting ? oeExisting : oe))) { |
| 1466 | return; |
| 1467 | } |
| 1468 | if (oeExisting && (oeExisting == os || oeExisting->contains(osExisting ? osExisting : os))) { |
| 1469 | return; |
| 1470 | } |
| 1471 | bool csDeleted = false, osDeleted = false, ceDeleted = false, oeDeleted = false; |
| 1472 | this->debugValidate(); |
| 1473 | if (!cs || !os) { |
| 1474 | if (!cs) |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 1475 | cs = coinSeg->debugAddT(coinTs); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1476 | if (!os) |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 1477 | os = oppSeg->debugAddT(oppTs); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1478 | if (cs && os) cs->span()->debugAddOppAndMerge(id, log, os->span(), &csDeleted, &osDeleted); |
| 1479 | // cs = csWritable; |
| 1480 | // os = osWritable; |
| 1481 | if ((ce && ce->deleted()) || (oe && oe->deleted())) { |
| 1482 | return; |
| 1483 | } |
| 1484 | } |
| 1485 | if (!ce || !oe) { |
| 1486 | if (!ce) |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 1487 | ce = coinSeg->debugAddT(coinTe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1488 | if (!oe) |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 1489 | oe = oppSeg->debugAddT(oppTe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1490 | if (ce && oe) ce->span()->debugAddOppAndMerge(id, log, oe->span(), &ceDeleted, &oeDeleted); |
| 1491 | // ce = ceWritable; |
| 1492 | // oe = oeWritable; |
| 1493 | } |
| 1494 | this->debugValidate(); |
| 1495 | if (csDeleted || osDeleted || ceDeleted || oeDeleted) { |
| 1496 | return; |
| 1497 | } |
| 1498 | if (!cs || !ce || cs->contains(ce) || !os || !oe || os->contains(oe)) { |
| 1499 | return; |
| 1500 | } |
| 1501 | // bool result = true; |
| 1502 | if (overlap) { |
| 1503 | if (overlap->coinPtTStart()->segment() == coinSeg) { |
| 1504 | log->record(kAddMissingExtend_Glitch, id, coinSeg, coinTs, coinTe, oppSeg, oppTs, oppTe); |
| 1505 | } else { |
| 1506 | if (oppTs > oppTe) { |
| 1507 | SkTSwap(coinTs, coinTe); |
| 1508 | SkTSwap(oppTs, oppTe); |
| 1509 | } |
| 1510 | log->record(kAddMissingExtend_Glitch, id, oppSeg, oppTs, oppTe, coinSeg, coinTs, coinTe); |
| 1511 | } |
| 1512 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1513 | // if (result) { |
| 1514 | // overlap->debugShow(); |
| 1515 | // } |
| 1516 | #endif |
| 1517 | } else { |
| 1518 | log->record(kAddMissingCoin_Glitch, id, coinSeg, coinTs, coinTe, oppSeg, oppTs, oppTe); |
| 1519 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1520 | // fHead->debugShow(); |
| 1521 | #endif |
| 1522 | } |
| 1523 | this->debugValidate(); |
| 1524 | return; |
| 1525 | } |
| 1526 | |
| 1527 | // Extra commented-out lines keep this in sync with addMissing() |
| 1528 | /* detects overlaps of different coincident runs on same segment */ |
| 1529 | /* does not detect overlaps for pairs without any segments in common */ |
| 1530 | // returns true if caller should loop again |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1531 | void SkOpCoincidence::debugAddMissing(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1532 | const SkCoincidentSpans* outer = fHead; |
| 1533 | if (!outer) { |
| 1534 | return; |
| 1535 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1536 | // bool added = false; |
| 1537 | // fTop = outer; |
| 1538 | // fHead = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1539 | do { |
| 1540 | // addifmissing can modify the list that this is walking |
| 1541 | // save head so that walker can iterate over old data unperturbed |
| 1542 | // addifmissing adds to head freely then add saved head in the end |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1543 | const SkOpSegment* outerCoin = outer->coinPtTStart()->segment(); |
| 1544 | const SkOpSegment* outerOpp = outer->oppPtTStart()->segment(); |
| 1545 | if (outerCoin->done() || outerOpp->done()) { |
| 1546 | continue; |
| 1547 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1548 | const SkCoincidentSpans* inner = outer; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1549 | while ((inner = inner->next())) { |
| 1550 | this->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1551 | double overS, overE; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1552 | const SkOpSegment* innerCoin = inner->coinPtTStart()->segment(); |
| 1553 | const SkOpSegment* innerOpp = inner->oppPtTStart()->segment(); |
| 1554 | if (innerCoin->done() || innerOpp->done()) { |
| 1555 | continue; |
| 1556 | } |
| 1557 | if (outerCoin == innerCoin) { |
| 1558 | if (outerOpp != innerOpp |
| 1559 | && this->overlap(outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1560 | inner->coinPtTStart(), inner->coinPtTEnd(), &overS, &overE)) { |
| 1561 | this->debugAddIfMissing(outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1562 | inner->coinPtTStart(), inner->coinPtTEnd(), overS, overE, |
| 1563 | outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1564 | inner->oppPtTStart(), inner->oppPtTEnd(), id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1565 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1566 | } else if (outerCoin == innerOpp) { |
| 1567 | if (outerOpp != innerCoin |
| 1568 | && this->overlap(outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1569 | inner->oppPtTStart(), inner->oppPtTEnd(), &overS, &overE)) { |
| 1570 | this->debugAddIfMissing(outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1571 | inner->oppPtTStart(), inner->oppPtTEnd(), overS, overE, |
| 1572 | outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1573 | inner->coinPtTStart(), inner->coinPtTEnd(), id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1574 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1575 | } else if (outerOpp == innerCoin) { |
| 1576 | SkASSERT(outerCoin != innerOpp); |
| 1577 | if (this->overlap(outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1578 | inner->coinPtTStart(), inner->coinPtTEnd(), &overS, &overE)) { |
| 1579 | this->debugAddIfMissing(outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1580 | inner->coinPtTStart(), inner->coinPtTEnd(), overS, overE, |
| 1581 | outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1582 | inner->oppPtTStart(), inner->oppPtTEnd(), id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1583 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1584 | } else if (outerOpp == innerOpp) { |
| 1585 | SkASSERT(outerCoin != innerCoin); |
| 1586 | if (this->overlap(outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1587 | inner->oppPtTStart(), inner->oppPtTEnd(), &overS, &overE)) { |
| 1588 | this->debugAddIfMissing(outer->oppPtTStart(), outer->oppPtTEnd(), |
| 1589 | inner->oppPtTStart(), inner->oppPtTEnd(), overS, overE, |
| 1590 | outer->coinPtTStart(), outer->coinPtTEnd(), |
| 1591 | inner->coinPtTStart(), inner->coinPtTEnd(), id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1592 | } |
| 1593 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1594 | this->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1595 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1596 | } while ((outer = outer->next())); |
| 1597 | // this->restoreHead(); |
| 1598 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1601 | // Commented-out lines keep this in sync with release() |
| 1602 | void SkOpCoincidence::debugRelease(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpSegment* deleted) const { |
| 1603 | const SkCoincidentSpans* coin = fHead; |
| 1604 | if (!coin) { |
| 1605 | return; |
| 1606 | } |
| 1607 | do { |
| 1608 | if (coin->coinPtTStart()->segment() == deleted |
| 1609 | || coin->coinPtTEnd()->segment() == deleted |
| 1610 | || coin->oppPtTStart()->segment() == deleted |
| 1611 | || coin->oppPtTEnd()->segment() == deleted) { |
| 1612 | log->record(kReleasedSpan_Glitch, id, coin); |
| 1613 | } |
| 1614 | } while ((coin = coin->next())); |
| 1615 | } |
| 1616 | |
| 1617 | // Commented-out lines keep this in sync with reorder() |
| 1618 | // iterate through all coincident pairs, looking for ranges greater than 1 |
| 1619 | // if found, see if the opposite pair can match it -- which may require |
| 1620 | // reordering the ptT pairs |
| 1621 | void SkOpCoincidence::debugReorder(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1622 | const SkCoincidentSpans* coin = fHead; |
| 1623 | if (!coin) { |
| 1624 | return; |
| 1625 | } |
| 1626 | do { |
| 1627 | // most commonly, concidence are one span long; check for that first |
| 1628 | int intervals = coin->spanCount(); |
| 1629 | if (intervals = 1) { |
| 1630 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1631 | // SkASSERT(!coin->debugExpand(nullptr, nullptr)); |
| 1632 | #endif |
| 1633 | continue; |
| 1634 | } |
| 1635 | coin->debugExpand(id, log); |
| 1636 | if (coin->spanCount() <= 0) { |
| 1637 | return; |
| 1638 | } |
| 1639 | // check to see if every span in coin has a mate in opp |
| 1640 | const SkOpSpan* start = coin->coinPtTStart()->span()->upCast(); |
| 1641 | bool flipped = coin->flipped(); |
| 1642 | const SkOpSpanBase* oppStartBase = coin->oppPtTStart()->span(); |
| 1643 | const SkOpSpan* oppStart = flipped ? oppStartBase->prev() : oppStartBase->upCast(); |
| 1644 | SkDebugf("", start, oppStart); |
| 1645 | } while ((coin = coin->next())); |
| 1646 | return; |
| 1647 | } |
| 1648 | |
| 1649 | // Commented-out lines keep this in sync with expand() |
| 1650 | // expand the range by checking adjacent spans for coincidence |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1651 | bool SkOpCoincidence::debugExpand(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1652 | const SkCoincidentSpans* coin = fHead; |
| 1653 | if (!coin) { |
| 1654 | return false; |
| 1655 | } |
| 1656 | bool expanded = false; |
| 1657 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1658 | if (coin->debugExpand(id, log)) { |
| 1659 | // check to see if multiple spans expanded so they are now identical |
| 1660 | const SkCoincidentSpans* test = fHead; |
| 1661 | do { |
| 1662 | if (coin == test) { |
| 1663 | continue; |
| 1664 | } |
| 1665 | if (coin->coinPtTStart() == test->coinPtTStart() |
| 1666 | && coin->oppPtTStart() == test->oppPtTStart()) { |
| 1667 | if (log) log->record(kExpandCoin_Glitch, id, fHead, test->coinPtTStart()); |
| 1668 | break; |
| 1669 | } |
| 1670 | } while ((test = test->next())); |
| 1671 | expanded = true; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1672 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1673 | } while ((coin = coin->next())); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1674 | return expanded; |
| 1675 | } |
| 1676 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1677 | // Commented-out lines keep this in sync with removeCollapsed() |
| 1678 | void SkOpCoincidence::debugRemoveCollapsed(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1679 | const SkCoincidentSpans* coin = fHead; |
| 1680 | if (!coin) { |
| 1681 | return; |
| 1682 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1683 | // SkCoincidentSpans** priorPtr = &fHead; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1684 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1685 | if (coin->coinPtTStart() == coin->coinPtTEnd()) { |
| 1686 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1687 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1688 | if (coin->oppPtTStart() == coin->oppPtTEnd()) { |
| 1689 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1690 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1691 | if (coin->coinPtTStart()->collapsed(coin->coinPtTEnd())) { |
| 1692 | log->record(kCollapsedCoin_Glitch, id, coin); |
| 1693 | // continue; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1694 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1695 | if (coin->oppPtTStart()->collapsed(coin->oppPtTEnd())) { |
| 1696 | log->record(kCollapsedCoin_Glitch, id, coin, coin); |
| 1697 | // continue; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1698 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1699 | // priorPtr = &coin->nextPtr(); |
| 1700 | } while ((coin = coin->next())); |
| 1701 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1704 | // Commented-out lines keep this in sync with mark() |
| 1705 | /* this sets up the coincidence links in the segments when the coincidence crosses multiple spans */ |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1706 | void SkOpCoincidence::debugMark(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1707 | const SkCoincidentSpans* coin = fHead; |
| 1708 | if (!coin) { |
| 1709 | return; |
| 1710 | } |
| 1711 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1712 | const SkOpSpan* start = coin->coinPtTStartWritable()->span()->upCast(); |
| 1713 | // SkASSERT(start->deleted()); |
| 1714 | const SkOpSpanBase* end = coin->coinPtTEndWritable()->span(); |
| 1715 | // SkASSERT(end->deleted()); |
| 1716 | const SkOpSpanBase* oStart = coin->oppPtTStartWritable()->span(); |
| 1717 | // SkASSERT(oStart->deleted()); |
| 1718 | const SkOpSpanBase* oEnd = coin->oppPtTEndWritable()->span(); |
| 1719 | // SkASSERT(oEnd->deleted()); |
| 1720 | bool flipped = coin->flipped(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1721 | if (flipped) { |
| 1722 | SkTSwap(oStart, oEnd); |
| 1723 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1724 | /* coin and opp spans may not match up. Mark the ends, and then let the interior |
| 1725 | get marked as many times as the spans allow */ |
| 1726 | start->debugInsertCoincidence(id, log, oStart->upCast()); |
| 1727 | end->debugInsertCoinEnd(id, log, oEnd); |
| 1728 | const SkOpSegment* segment = start->segment(); |
| 1729 | const SkOpSegment* oSegment = oStart->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1730 | const SkOpSpanBase* next = start; |
| 1731 | const SkOpSpanBase* oNext = oStart; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1732 | while ((next = next->upCast()->next()) != end) { |
| 1733 | if (next->upCast()->debugInsertCoincidence(id, log, oSegment, flipped), false) { |
| 1734 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1735 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | while ((oNext = oNext->upCast()->next()) != oEnd) { |
| 1738 | if (oNext->upCast()->debugInsertCoincidence(id, log, segment, flipped), false) { |
| 1739 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1740 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1741 | } |
| 1742 | } while ((coin = coin->next())); |
| 1743 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1744 | } |
| 1745 | #endif |
| 1746 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1747 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1748 | // Commented-out lines keep this in sync with markCollapsed() |
| 1749 | void SkOpCoincidence::debugMarkCollapsed(const char* id, SkPathOpsDebug::GlitchLog* log, const SkCoincidentSpans* coin, const SkOpPtT* test) const { |
| 1750 | while (coin) { |
| 1751 | if (coin->collapsed(test)) { |
| 1752 | if (zero_or_one(coin->coinPtTStart()->fT) && zero_or_one(coin->coinPtTEnd()->fT)) { |
| 1753 | log->record(kCollapsedCoin_Glitch, id, coin); |
| 1754 | } |
| 1755 | if (zero_or_one(coin->oppPtTStart()->fT) && zero_or_one(coin->oppPtTEnd()->fT)) { |
| 1756 | log->record(kCollapsedCoin_Glitch, id, coin); |
| 1757 | } |
| 1758 | } |
| 1759 | coin = coin->next(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1763 | // Commented-out lines keep this in sync with markCollapsed() |
| 1764 | void SkOpCoincidence::debugMarkCollapsed(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpPtT* test) const { |
| 1765 | this->debugMarkCollapsed(id, log, fHead, test); |
| 1766 | this->debugMarkCollapsed(id, log, fTop, test); |
| 1767 | } |
| 1768 | #endif |
| 1769 | |
| 1770 | void SkCoincidentSpans::debugShow() const { |
| 1771 | SkDebugf("%s - id=%d t=%1.9g tEnd=%1.9g\n", __FUNCTION__, |
| 1772 | coinPtTStart()->segment()->debugID(), |
| 1773 | coinPtTStart()->fT, coinPtTEnd()->fT); |
| 1774 | SkDebugf("%s + id=%d t=%1.9g tEnd=%1.9g\n", __FUNCTION__, |
| 1775 | oppPtTStart()->segment()->debugID(), |
| 1776 | oppPtTStart()->fT, oppPtTEnd()->fT); |
| 1777 | } |
| 1778 | |
| 1779 | void SkOpCoincidence::debugShowCoincidence() const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1780 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1781 | const SkCoincidentSpans* span = fHead; |
| 1782 | while (span) { |
| 1783 | span->debugShow(); |
| 1784 | span = span->next(); |
| 1785 | } |
| 1786 | #endif |
| 1787 | } |
| 1788 | |
| 1789 | #if DEBUG_COINCIDENCE |
| 1790 | static void DebugValidate(const SkOpSpanBase* next, const SkOpSpanBase* end, |
| 1791 | double oStart, double oEnd, const SkOpSegment* oSegment, |
| 1792 | const char* id, SkPathOpsDebug::GlitchLog* log) { |
| 1793 | SkASSERT(next != end); |
| 1794 | SkASSERT(!next->contains(end) || log); |
| 1795 | if (next->t() > end->t()) { |
| 1796 | SkTSwap(next, end); |
| 1797 | } |
| 1798 | do { |
| 1799 | const SkOpPtT* ptT = next->ptT(); |
| 1800 | int index = 0; |
| 1801 | bool somethingBetween; |
| 1802 | do { |
| 1803 | ++index; |
| 1804 | ptT = ptT->next(); |
| 1805 | const SkOpPtT* checkPtT = next->ptT(); |
| 1806 | if (ptT == checkPtT) { |
| 1807 | break; |
| 1808 | } |
| 1809 | bool looped = false; |
| 1810 | for (int check = 0; check < index; ++check) { |
| 1811 | if ((looped = checkPtT == ptT)) { |
| 1812 | break; |
| 1813 | } |
| 1814 | checkPtT = checkPtT->next(); |
| 1815 | } |
| 1816 | if (looped) { |
| 1817 | SkASSERT(0); |
| 1818 | break; |
| 1819 | } |
| 1820 | if (ptT->deleted()) { |
| 1821 | continue; |
| 1822 | } |
| 1823 | if (ptT->segment() != oSegment) { |
| 1824 | continue; |
| 1825 | } |
| 1826 | somethingBetween |= between(oStart, ptT->fT, oEnd); |
| 1827 | } while (true); |
| 1828 | SkASSERT(somethingBetween); |
| 1829 | } while (next != end && (next = next->upCast()->next())); |
| 1830 | } |
| 1831 | |
| 1832 | static void DebugCheckOverlap(const SkCoincidentSpans* test, const SkCoincidentSpans* list, |
| 1833 | const char* id, SkPathOpsDebug::GlitchLog* log) { |
| 1834 | if (!list) { |
| 1835 | return; |
| 1836 | } |
| 1837 | const SkOpSegment* coinSeg = test->coinPtTStart()->segment(); |
| 1838 | SkASSERT(coinSeg == test->coinPtTEnd()->segment()); |
| 1839 | const SkOpSegment* oppSeg = test->oppPtTStart()->segment(); |
| 1840 | SkASSERT(oppSeg == test->oppPtTEnd()->segment()); |
| 1841 | SkASSERT(coinSeg != test->oppPtTStart()->segment()); |
| 1842 | SkDEBUGCODE(double tcs = test->coinPtTStart()->fT); |
| 1843 | SkASSERT(between(0, tcs, 1)); |
| 1844 | SkDEBUGCODE(double tce = test->coinPtTEnd()->fT); |
| 1845 | SkASSERT(between(0, tce, 1)); |
| 1846 | SkASSERT(tcs < tce); |
| 1847 | double tos = test->oppPtTStart()->fT; |
| 1848 | SkASSERT(between(0, tos, 1)); |
| 1849 | double toe = test->oppPtTEnd()->fT; |
| 1850 | SkASSERT(between(0, toe, 1)); |
| 1851 | SkASSERT(tos != toe); |
| 1852 | if (tos > toe) { |
| 1853 | SkTSwap(tos, toe); |
| 1854 | } |
| 1855 | do { |
| 1856 | double lcs, lce, los, loe; |
| 1857 | if (coinSeg == list->coinPtTStart()->segment()) { |
| 1858 | if (oppSeg != list->oppPtTStart()->segment()) { |
| 1859 | continue; |
| 1860 | } |
| 1861 | lcs = list->coinPtTStart()->fT; |
| 1862 | lce = list->coinPtTEnd()->fT; |
| 1863 | los = list->oppPtTStart()->fT; |
| 1864 | loe = list->oppPtTEnd()->fT; |
| 1865 | if (los > loe) { |
| 1866 | SkTSwap(los, loe); |
| 1867 | } |
| 1868 | } else if (coinSeg == list->oppPtTStart()->segment()) { |
| 1869 | if (oppSeg != list->coinPtTStart()->segment()) { |
| 1870 | continue; |
| 1871 | } |
| 1872 | lcs = list->oppPtTStart()->fT; |
| 1873 | lce = list->oppPtTEnd()->fT; |
| 1874 | if (lcs > lce) { |
| 1875 | SkTSwap(lcs, lce); |
| 1876 | } |
| 1877 | los = list->coinPtTStart()->fT; |
| 1878 | loe = list->coinPtTEnd()->fT; |
| 1879 | } else { |
| 1880 | continue; |
| 1881 | } |
| 1882 | SkASSERT(tce < lcs || lce < tcs); |
| 1883 | SkASSERT(toe < los || loe < tos); |
| 1884 | } while ((list = list->next())); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | static void DebugCheckOverlapTop(const SkCoincidentSpans* head, const SkCoincidentSpans* opt, |
| 1889 | const char* id, SkPathOpsDebug::GlitchLog* log) { |
| 1890 | // check for overlapping coincident spans |
| 1891 | const SkCoincidentSpans* test = head; |
| 1892 | while (test) { |
| 1893 | const SkCoincidentSpans* next = test->next(); |
| 1894 | DebugCheckOverlap(test, next, id, log); |
| 1895 | DebugCheckOverlap(test, opt, id, log); |
| 1896 | test = next; |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1901 | void SkOpCoincidence::debugCheckOverlap(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1902 | DebugCheckOverlapTop(fHead, fTop, id, log); |
| 1903 | DebugCheckOverlapTop(fTop, nullptr, id, log); |
| 1904 | } |
| 1905 | #endif |
| 1906 | |
| 1907 | static void DebugValidate(const SkCoincidentSpans* head, const SkCoincidentSpans* opt, |
| 1908 | const char* id, SkPathOpsDebug::GlitchLog* log) { |
| 1909 | // look for pts inside coincident spans that are not inside the opposite spans |
| 1910 | const SkCoincidentSpans* coin = head; |
| 1911 | while (coin) { |
| 1912 | SkASSERT(SkOpCoincidence::Ordered(coin->coinPtTStart()->segment(), |
| 1913 | coin->oppPtTStart()->segment())); |
| 1914 | SkASSERT(coin->coinPtTStart()->span()->ptT() == coin->coinPtTStart()); |
| 1915 | SkASSERT(coin->coinPtTEnd()->span()->ptT() == coin->coinPtTEnd()); |
| 1916 | SkASSERT(coin->oppPtTStart()->span()->ptT() == coin->oppPtTStart()); |
| 1917 | SkASSERT(coin->oppPtTEnd()->span()->ptT() == coin->oppPtTEnd()); |
| 1918 | DebugValidate(coin->coinPtTStart()->span(), coin->coinPtTEnd()->span(), |
| 1919 | coin->oppPtTStart()->fT, coin->oppPtTEnd()->fT, coin->oppPtTStart()->segment(), |
| 1920 | id, log); |
| 1921 | DebugValidate(coin->oppPtTStart()->span(), coin->oppPtTEnd()->span(), |
| 1922 | coin->coinPtTStart()->fT, coin->coinPtTEnd()->fT, coin->coinPtTStart()->segment(), |
| 1923 | id, log); |
| 1924 | coin = coin->next(); |
| 1925 | } |
| 1926 | DebugCheckOverlapTop(head, opt, id, log); |
| 1927 | } |
| 1928 | #endif |
| 1929 | |
| 1930 | void SkOpCoincidence::debugValidate() const { |
| 1931 | #if DEBUG_COINCIDENCE |
| 1932 | // if (fGlobalState->debugCheckHealth()) { |
| 1933 | // return; |
| 1934 | // } |
| 1935 | DebugValidate(fHead, fTop, nullptr, nullptr); |
| 1936 | DebugValidate(fTop, nullptr, nullptr, nullptr); |
| 1937 | #endif |
| 1938 | } |
| 1939 | |
| 1940 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1941 | void SkOpCoincidence::debugCheckValid(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1942 | DebugValidate(fHead, fTop, id, log); |
| 1943 | DebugValidate(fTop, nullptr, id, log); |
| 1944 | } |
| 1945 | #endif |
| 1946 | |
| 1947 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1948 | void SkOpContour::debugCheckHealth(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1949 | const SkOpSegment* segment = &fHead; |
| 1950 | do { |
| 1951 | segment->debugCheckHealth(id, log); |
| 1952 | } while ((segment = segment->next())); |
| 1953 | } |
| 1954 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1955 | // commmented-out lines keep this aligned with missingCoincidence() |
| 1956 | void SkOpContour::debugMissingCoincidence(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 1957 | // SkASSERT(fCount > 0); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1958 | const SkOpSegment* segment = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1959 | // bool result = false; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1960 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1961 | if (fState->angleCoincidence()) { |
| 1962 | // #if DEBUG_ANGLE |
| 1963 | // segment->debugCheckAngleCoin(); |
| 1964 | // #endif |
| 1965 | } else if (segment->debugMissingCoincidence(id, log), false) { |
| 1966 | // result = true; |
| 1967 | // see FIXME in missingCoincidence() |
| 1968 | // |
| 1969 | // |
| 1970 | // |
| 1971 | // continue; |
| 1972 | } |
| 1973 | segment = segment->next(); |
| 1974 | } while (segment); |
| 1975 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1976 | } |
| 1977 | #endif |
| 1978 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1979 | #if DEBUG_COINCIDENCE_ORDER |
| 1980 | void SkOpSegment::debugResetCoinT() const { |
| 1981 | fDebugBaseIndex = -1; |
| 1982 | fDebugBaseMin = 1; |
| 1983 | fDebugBaseMax = -1; |
| 1984 | fDebugLastIndex = -1; |
| 1985 | fDebugLastMin = 1; |
| 1986 | fDebugLastMax = -1; |
| 1987 | } |
| 1988 | #endif |
| 1989 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1990 | void SkOpSegment::debugValidate() const { |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1991 | #if DEBUG_COINCIDENCE_ORDER |
| 1992 | { |
| 1993 | const SkOpSpanBase* span = &fHead; |
| 1994 | do { |
| 1995 | span->debugResetCoinT(); |
| 1996 | } while (!span->final() && (span = span->upCast()->next())); |
| 1997 | span = &fHead; |
| 1998 | int index = 0; |
| 1999 | do { |
| 2000 | span->debugSetCoinT(index++); |
| 2001 | } while (!span->final() && (span = span->upCast()->next())); |
| 2002 | } |
| 2003 | #endif |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2004 | #if DEBUG_COINCIDENCE |
| 2005 | if (this->globalState()->debugCheckHealth()) { |
| 2006 | return; |
| 2007 | } |
| 2008 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2009 | #if DEBUG_VALIDATE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2010 | const SkOpSpanBase* span = &fHead; |
| 2011 | double lastT = -1; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2012 | const SkOpSpanBase* prev = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2013 | int count = 0; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2014 | int done = 0; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2015 | do { |
| 2016 | if (!span->final()) { |
| 2017 | ++count; |
| 2018 | done += span->upCast()->done() ? 1 : 0; |
| 2019 | } |
| 2020 | SkASSERT(span->segment() == this); |
| 2021 | SkASSERT(!prev || prev->upCast()->next() == span); |
| 2022 | SkASSERT(!prev || prev == span->prev()); |
| 2023 | prev = span; |
| 2024 | double t = span->ptT()->fT; |
| 2025 | SkASSERT(lastT < t); |
| 2026 | lastT = t; |
| 2027 | span->debugValidate(); |
| 2028 | } while (!span->final() && (span = span->upCast()->next())); |
| 2029 | SkASSERT(count == fCount); |
| 2030 | SkASSERT(done == fDoneCount); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 2031 | SkASSERT(count >= fDoneCount); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2032 | SkASSERT(span->final()); |
| 2033 | span->debugValidate(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2034 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2037 | #if DEBUG_COINCIDENCE_VERBOSE |
| 2038 | // Commented-out lines keep this in sync with addOppAndMerge() |
| 2039 | // If the added points envelop adjacent spans, merge them in. |
| 2040 | void SkOpSpanBase::debugAddOppAndMerge(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpSpanBase* opp, bool* spanDeleted, bool* oppDeleted) const { |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 2041 | const SkOpPtT* oppPrev = this->ptT()->debugOppPrev(opp->ptT()); |
| 2042 | if (oppPrev) { |
| 2043 | this->ptT()->debugAddOpp(opp->ptT(), oppPrev); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2044 | this->debugCheckForCollapsedCoincidence(id, log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2045 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2046 | // compute bounds of points in span |
| 2047 | SkPathOpsBounds bounds; |
| 2048 | bounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMin, SK_ScalarMin); |
| 2049 | const SkOpPtT* head = this->ptT(); |
| 2050 | const SkOpPtT* nextPt = head; |
| 2051 | do { |
| 2052 | bounds.add(nextPt->fPt); |
| 2053 | } while ((nextPt = nextPt->next()) != head); |
| 2054 | if (!bounds.width() && !bounds.height()) { |
| 2055 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2056 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2057 | this->debugMergeContained(id, log, bounds, spanDeleted); |
| 2058 | opp->debugMergeContained(id, log, bounds, oppDeleted); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2061 | // Commented-out lines keep this in sync with checkForCollapsedCoincidence() |
| 2062 | void SkOpSpanBase::debugCheckForCollapsedCoincidence(const char* id, SkPathOpsDebug::GlitchLog* log) const { |
| 2063 | const SkOpCoincidence* coins = this->globalState()->coincidence(); |
| 2064 | if (coins->isEmpty()) { |
| 2065 | return; |
| 2066 | } |
| 2067 | // the insert above may have put both ends of a coincident run in the same span |
| 2068 | // for each coincident ptT in loop; see if its opposite in is also in the loop |
| 2069 | // this implementation is the motivation for marking that a ptT is referenced by a coincident span |
| 2070 | const SkOpPtT* head = this->ptT(); |
| 2071 | const SkOpPtT* test = head; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2072 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2073 | if (!test->coincident()) { |
| 2074 | continue; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2075 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2076 | coins->debugMarkCollapsed(id, log, test); |
| 2077 | } while ((test = test->next()) != head); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2078 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2079 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2080 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2081 | bool SkOpSpanBase::debugCoinEndLoopCheck() const { |
| 2082 | int loop = 0; |
| 2083 | const SkOpSpanBase* next = this; |
| 2084 | SkOpSpanBase* nextCoin; |
| 2085 | do { |
| 2086 | nextCoin = next->fCoinEnd; |
| 2087 | SkASSERT(nextCoin == this || nextCoin->fCoinEnd != nextCoin); |
| 2088 | for (int check = 1; check < loop - 1; ++check) { |
| 2089 | const SkOpSpanBase* checkCoin = this->fCoinEnd; |
| 2090 | const SkOpSpanBase* innerCoin = checkCoin; |
| 2091 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2092 | innerCoin = innerCoin->fCoinEnd; |
| 2093 | if (checkCoin == innerCoin) { |
| 2094 | SkDebugf("*** bad coincident end loop ***\n"); |
| 2095 | return false; |
| 2096 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2097 | } |
| 2098 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2099 | ++loop; |
| 2100 | } while ((next = nextCoin) && next != this); |
| 2101 | return true; |
| 2102 | } |
| 2103 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2104 | #if DEBUG_COINCIDENCE_VERBOSE |
| 2105 | // Commented-out lines keep this in sync with insertCoinEnd() |
| 2106 | void SkOpSpanBase::debugInsertCoinEnd(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpSpanBase* coin) const { |
| 2107 | if (containsCoinEnd(coin)) { |
| 2108 | // SkASSERT(coin->containsCoinEnd(this)); |
| 2109 | return; |
| 2110 | } |
| 2111 | debugValidate(); |
| 2112 | // SkASSERT(this != coin); |
| 2113 | log->record(kMarkCoinEnd_Glitch, id, this, coin); |
| 2114 | // coin->fCoinEnd = this->fCoinEnd; |
| 2115 | // this->fCoinEnd = coinNext; |
| 2116 | debugValidate(); |
| 2117 | } |
| 2118 | |
| 2119 | // Commented-out lines keep this in sync with mergeContained() |
| 2120 | void SkOpSpanBase::debugMergeContained(const char* id, SkPathOpsDebug::GlitchLog* log, const SkPathOpsBounds& bounds, bool* deleted) const { |
| 2121 | // while adjacent spans' points are contained by the bounds, merge them |
| 2122 | const SkOpSpanBase* prev = this; |
| 2123 | const SkOpSegment* seg = this->segment(); |
| 2124 | while ((prev = prev->prev()) && bounds.contains(prev->pt()) && !seg->ptsDisjoint(prev, this)) { |
| 2125 | if (prev->prev()) { |
| 2126 | log->record(kMergeContained_Glitch, id, this, prev); |
| 2127 | } else if (this->final()) { |
| 2128 | log->record(kMergeContained_Glitch, id, this, prev); |
| 2129 | // return; |
| 2130 | } else { |
| 2131 | log->record(kMergeContained_Glitch, id, prev, this); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2132 | } |
| 2133 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2134 | const SkOpSpanBase* current = this; |
| 2135 | const SkOpSpanBase* next = this; |
| 2136 | while (next->upCastable() && (next = next->upCast()->next()) |
| 2137 | && bounds.contains(next->pt()) && !seg->ptsDisjoint(this, next)) { |
| 2138 | if (!current->prev() && next->final()) { |
| 2139 | log->record(kMergeContained_Glitch, id, next, current); |
| 2140 | current = next; |
| 2141 | } |
| 2142 | if (current->prev()) { |
| 2143 | log->record(kMergeContained_Glitch, id, next, current); |
| 2144 | current = next; |
| 2145 | } else { |
| 2146 | log->record(kMergeContained_Glitch, id, next, current); |
| 2147 | current = next; |
| 2148 | } |
| 2149 | } |
| 2150 | #if DEBUG_COINCIDENCE |
| 2151 | // this->globalState()->coincidence()->debugValidate(); |
| 2152 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2153 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2154 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2155 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2156 | void SkOpSpanBase::debugResetCoinT() const { |
| 2157 | #if DEBUG_COINCIDENCE_ORDER |
| 2158 | const SkOpPtT* ptT = &fPtT; |
| 2159 | do { |
| 2160 | ptT->debugResetCoinT(); |
| 2161 | ptT = ptT->next(); |
| 2162 | } while (ptT != &fPtT); |
| 2163 | #endif |
| 2164 | } |
| 2165 | |
| 2166 | void SkOpSpanBase::debugSetCoinT(int index) const { |
| 2167 | #if DEBUG_COINCIDENCE_ORDER |
| 2168 | const SkOpPtT* ptT = &fPtT; |
| 2169 | do { |
| 2170 | if (!ptT->deleted()) { |
| 2171 | ptT->debugSetCoinT(index); |
| 2172 | } |
| 2173 | ptT = ptT->next(); |
| 2174 | } while (ptT != &fPtT); |
| 2175 | #endif |
| 2176 | } |
| 2177 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2178 | const SkOpSpan* SkOpSpanBase::debugStarter(SkOpSpanBase const** endPtr) const { |
| 2179 | const SkOpSpanBase* end = *endPtr; |
| 2180 | SkASSERT(this->segment() == end->segment()); |
| 2181 | const SkOpSpanBase* result; |
| 2182 | if (t() < end->t()) { |
| 2183 | result = this; |
| 2184 | } else { |
| 2185 | result = end; |
| 2186 | *endPtr = this; |
| 2187 | } |
| 2188 | return result->upCast(); |
| 2189 | } |
| 2190 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2191 | void SkOpSpanBase::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2192 | #if DEBUG_COINCIDENCE |
| 2193 | if (this->globalState()->debugCheckHealth()) { |
| 2194 | return; |
| 2195 | } |
| 2196 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2197 | #if DEBUG_VALIDATE |
| 2198 | const SkOpPtT* ptT = &fPtT; |
| 2199 | SkASSERT(ptT->span() == this); |
| 2200 | do { |
| 2201 | // SkASSERT(SkDPoint::RoughlyEqual(fPtT.fPt, ptT->fPt)); |
| 2202 | ptT->debugValidate(); |
| 2203 | ptT = ptT->next(); |
| 2204 | } while (ptT != &fPtT); |
| 2205 | SkASSERT(this->debugCoinEndLoopCheck()); |
| 2206 | if (!this->final()) { |
| 2207 | SkASSERT(this->upCast()->debugCoinLoopCheck()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2208 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2209 | if (fFromAngle) { |
| 2210 | fFromAngle->debugValidate(); |
| 2211 | } |
| 2212 | if (!this->final() && this->upCast()->toAngle()) { |
| 2213 | this->upCast()->toAngle()->debugValidate(); |
| 2214 | } |
| 2215 | #endif |
| 2216 | } |
| 2217 | |
| 2218 | bool SkOpSpan::debugCoinLoopCheck() const { |
| 2219 | int loop = 0; |
| 2220 | const SkOpSpan* next = this; |
| 2221 | SkOpSpan* nextCoin; |
| 2222 | do { |
| 2223 | nextCoin = next->fCoincident; |
| 2224 | SkASSERT(nextCoin == this || nextCoin->fCoincident != nextCoin); |
| 2225 | for (int check = 1; check < loop - 1; ++check) { |
| 2226 | const SkOpSpan* checkCoin = this->fCoincident; |
| 2227 | const SkOpSpan* innerCoin = checkCoin; |
| 2228 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2229 | innerCoin = innerCoin->fCoincident; |
| 2230 | if (checkCoin == innerCoin) { |
| 2231 | SkDebugf("*** bad coincident loop ***\n"); |
| 2232 | return false; |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | ++loop; |
| 2237 | } while ((next = nextCoin) && next != this); |
| 2238 | return true; |
| 2239 | } |
| 2240 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2241 | #if DEBUG_COINCIDENCE_VERBOSE |
| 2242 | // Commented-out lines keep this in sync with insertCoincidence() in header |
| 2243 | void SkOpSpan::debugInsertCoincidence(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpSpan* coin) const { |
| 2244 | if (containsCoincidence(coin)) { |
| 2245 | // SkASSERT(coin->containsCoincidence(this)); |
| 2246 | return; |
| 2247 | } |
| 2248 | debugValidate(); |
| 2249 | // SkASSERT(this != coin); |
| 2250 | log->record(kMarkCoinStart_Glitch, id, this, coin); |
| 2251 | // coin->fCoincident = this->fCoincident; |
| 2252 | // this->fCoincident = coinNext; |
| 2253 | debugValidate(); |
| 2254 | } |
| 2255 | |
| 2256 | // Commented-out lines keep this in sync with insertCoincidence() |
| 2257 | void SkOpSpan::debugInsertCoincidence(const char* id, SkPathOpsDebug::GlitchLog* log, const SkOpSegment* segment, bool flipped) const { |
| 2258 | if (this->containsCoincidence(segment)) { |
| 2259 | return; |
| 2260 | } |
| 2261 | const SkOpPtT* next = &fPtT; |
| 2262 | while ((next = next->next()) != &fPtT) { |
| 2263 | if (next->segment() == segment) { |
| 2264 | log->record(kMarkCoinInsert_Glitch, id, flipped ? next->span()->prev() : next->span()); |
| 2265 | return; |
| 2266 | } |
| 2267 | } |
| 2268 | #if DEBUG_COINCIDENCE |
| 2269 | log->record(kMarkCoinMissing_Glitch, id, segment, this); |
| 2270 | #endif |
| 2271 | } |
| 2272 | #endif |
| 2273 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 2274 | // called only by test code |
| 2275 | int SkIntersections::debugCoincidentUsed() const { |
| 2276 | if (!fIsCoincident[0]) { |
| 2277 | SkASSERT(!fIsCoincident[1]); |
| 2278 | return 0; |
| 2279 | } |
| 2280 | int count = 0; |
| 2281 | SkDEBUGCODE(int count2 = 0;) |
| 2282 | for (int index = 0; index < fUsed; ++index) { |
| 2283 | if (fIsCoincident[0] & (1 << index)) { |
| 2284 | ++count; |
| 2285 | } |
| 2286 | #ifdef SK_DEBUG |
| 2287 | if (fIsCoincident[1] & (1 << index)) { |
| 2288 | ++count2; |
| 2289 | } |
| 2290 | #endif |
| 2291 | } |
| 2292 | SkASSERT(count == count2); |
| 2293 | return count; |
| 2294 | } |
| 2295 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2296 | #include "SkOpContour.h" |
| 2297 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2298 | // Commented-out lines keep this in sync with addOpp() |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 2299 | void SkOpPtT::debugAddOpp(const SkOpPtT* opp, const SkOpPtT* oppPrev) const { |
| 2300 | SkDEBUGCODE(const SkOpPtT* oldNext = this->fNext); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2301 | SkASSERT(this != opp); |
| 2302 | // this->fNext = opp; |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 2303 | SkASSERT(oppPrev != oldNext); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2304 | // oppPrev->fNext = oldNext; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2307 | bool SkOpPtT::debugContains(const SkOpPtT* check) const { |
| 2308 | SkASSERT(this != check); |
| 2309 | const SkOpPtT* ptT = this; |
| 2310 | int links = 0; |
| 2311 | do { |
| 2312 | ptT = ptT->next(); |
| 2313 | if (ptT == check) { |
| 2314 | return true; |
| 2315 | } |
| 2316 | ++links; |
| 2317 | const SkOpPtT* test = this; |
| 2318 | for (int index = 0; index < links; ++index) { |
| 2319 | if (ptT == test) { |
| 2320 | return false; |
| 2321 | } |
| 2322 | test = test->next(); |
| 2323 | } |
| 2324 | } while (true); |
| 2325 | } |
| 2326 | |
| 2327 | const SkOpPtT* SkOpPtT::debugContains(const SkOpSegment* check) const { |
| 2328 | SkASSERT(this->segment() != check); |
| 2329 | const SkOpPtT* ptT = this; |
| 2330 | int links = 0; |
| 2331 | do { |
| 2332 | ptT = ptT->next(); |
| 2333 | if (ptT->segment() == check) { |
| 2334 | return ptT; |
| 2335 | } |
| 2336 | ++links; |
| 2337 | const SkOpPtT* test = this; |
| 2338 | for (int index = 0; index < links; ++index) { |
| 2339 | if (ptT == test) { |
| 2340 | return nullptr; |
| 2341 | } |
| 2342 | test = test->next(); |
| 2343 | } |
| 2344 | } while (true); |
| 2345 | } |
| 2346 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2347 | int SkOpPtT::debugLoopLimit(bool report) const { |
| 2348 | int loop = 0; |
| 2349 | const SkOpPtT* next = this; |
| 2350 | do { |
| 2351 | for (int check = 1; check < loop - 1; ++check) { |
| 2352 | const SkOpPtT* checkPtT = this->fNext; |
| 2353 | const SkOpPtT* innerPtT = checkPtT; |
| 2354 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2355 | innerPtT = innerPtT->fNext; |
| 2356 | if (checkPtT == innerPtT) { |
| 2357 | if (report) { |
| 2358 | SkDebugf("*** bad ptT loop ***\n"); |
| 2359 | } |
| 2360 | return loop; |
| 2361 | } |
| 2362 | } |
| 2363 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2364 | // there's nothing wrong with extremely large loop counts -- but this may appear to hang |
| 2365 | // by taking a very long time to figure out that no loop entry is a duplicate |
| 2366 | // -- and it's likely that a large loop count is indicative of a bug somewhere |
| 2367 | if (++loop > 1000) { |
| 2368 | SkDebugf("*** loop count exceeds 1000 ***\n"); |
| 2369 | return 1000; |
| 2370 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2371 | } while ((next = next->fNext) && next != this); |
| 2372 | return 0; |
| 2373 | } |
| 2374 | |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame^] | 2375 | const SkOpPtT* SkOpPtT::debugOppPrev(const SkOpPtT* opp) const { |
| 2376 | return this->oppPrev(const_cast<SkOpPtT*>(opp)); |
| 2377 | } |
| 2378 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2379 | void SkOpPtT::debugResetCoinT() const { |
| 2380 | #if DEBUG_COINCIDENCE_ORDER |
| 2381 | this->segment()->debugResetCoinT(); |
| 2382 | #endif |
| 2383 | } |
| 2384 | |
| 2385 | void SkOpPtT::debugSetCoinT(int index) const { |
| 2386 | #if DEBUG_COINCIDENCE_ORDER |
| 2387 | this->segment()->debugSetCoinT(index, fT); |
| 2388 | #endif |
| 2389 | } |
| 2390 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2391 | void SkOpPtT::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2392 | #if DEBUG_COINCIDENCE |
| 2393 | if (this->globalState()->debugCheckHealth()) { |
| 2394 | return; |
| 2395 | } |
| 2396 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2397 | #if DEBUG_VALIDATE |
caryclark | 4e1a4c9 | 2015-05-18 12:56:57 -0700 | [diff] [blame] | 2398 | SkOpGlobalState::Phase phase = contour()->globalState()->phase(); |
| 2399 | if (phase == SkOpGlobalState::kIntersecting |
| 2400 | || phase == SkOpGlobalState::kFixWinding) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2401 | return; |
| 2402 | } |
| 2403 | SkASSERT(fNext); |
| 2404 | SkASSERT(fNext != this); |
| 2405 | SkASSERT(fNext->fNext); |
| 2406 | SkASSERT(debugLoopLimit(false) == 0); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2407 | #endif |
| 2408 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2409 | |
| 2410 | static void output_scalar(SkScalar num) { |
| 2411 | if (num == (int) num) { |
| 2412 | SkDebugf("%d", (int) num); |
| 2413 | } else { |
| 2414 | SkString str; |
| 2415 | str.printf("%1.9g", num); |
| 2416 | int width = (int) str.size(); |
| 2417 | const char* cStr = str.c_str(); |
| 2418 | while (cStr[width - 1] == '0') { |
| 2419 | --width; |
| 2420 | } |
| 2421 | str.resize(width); |
| 2422 | SkDebugf("%sf", str.c_str()); |
| 2423 | } |
| 2424 | } |
| 2425 | |
| 2426 | static void output_points(const SkPoint* pts, int count) { |
| 2427 | for (int index = 0; index < count; ++index) { |
| 2428 | output_scalar(pts[index].fX); |
| 2429 | SkDebugf(", "); |
| 2430 | output_scalar(pts[index].fY); |
| 2431 | if (index + 1 < count) { |
| 2432 | SkDebugf(", "); |
| 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | static void showPathContours(SkPath::RawIter& iter, const char* pathName) { |
| 2438 | uint8_t verb; |
| 2439 | SkPoint pts[4]; |
| 2440 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 2441 | switch (verb) { |
| 2442 | case SkPath::kMove_Verb: |
| 2443 | SkDebugf(" %s.moveTo(", pathName); |
| 2444 | output_points(&pts[0], 1); |
| 2445 | SkDebugf(");\n"); |
| 2446 | continue; |
| 2447 | case SkPath::kLine_Verb: |
| 2448 | SkDebugf(" %s.lineTo(", pathName); |
| 2449 | output_points(&pts[1], 1); |
| 2450 | SkDebugf(");\n"); |
| 2451 | break; |
| 2452 | case SkPath::kQuad_Verb: |
| 2453 | SkDebugf(" %s.quadTo(", pathName); |
| 2454 | output_points(&pts[1], 2); |
| 2455 | SkDebugf(");\n"); |
| 2456 | break; |
| 2457 | case SkPath::kConic_Verb: |
| 2458 | SkDebugf(" %s.conicTo(", pathName); |
| 2459 | output_points(&pts[1], 2); |
| 2460 | SkDebugf(", %1.9gf);\n", iter.conicWeight()); |
| 2461 | break; |
| 2462 | case SkPath::kCubic_Verb: |
| 2463 | SkDebugf(" %s.cubicTo(", pathName); |
| 2464 | output_points(&pts[1], 3); |
| 2465 | SkDebugf(");\n"); |
| 2466 | break; |
| 2467 | case SkPath::kClose_Verb: |
| 2468 | SkDebugf(" %s.close();\n", pathName); |
| 2469 | break; |
| 2470 | default: |
| 2471 | SkDEBUGFAIL("bad verb"); |
| 2472 | return; |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | static const char* gFillTypeStr[] = { |
| 2478 | "kWinding_FillType", |
| 2479 | "kEvenOdd_FillType", |
| 2480 | "kInverseWinding_FillType", |
| 2481 | "kInverseEvenOdd_FillType" |
| 2482 | }; |
| 2483 | |
| 2484 | void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool includeDeclaration) { |
| 2485 | SkPath::RawIter iter(path); |
| 2486 | #define SUPPORT_RECT_CONTOUR_DETECTION 0 |
| 2487 | #if SUPPORT_RECT_CONTOUR_DETECTION |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2488 | int rectCount = path.isRectContours() ? path.rectContours(nullptr, nullptr) : 0; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2489 | if (rectCount > 0) { |
| 2490 | SkTDArray<SkRect> rects; |
| 2491 | SkTDArray<SkPath::Direction> directions; |
| 2492 | rects.setCount(rectCount); |
| 2493 | directions.setCount(rectCount); |
| 2494 | path.rectContours(rects.begin(), directions.begin()); |
| 2495 | for (int contour = 0; contour < rectCount; ++contour) { |
| 2496 | const SkRect& rect = rects[contour]; |
| 2497 | SkDebugf("path.addRect(%1.9g, %1.9g, %1.9g, %1.9g, %s);\n", rect.fLeft, rect.fTop, |
| 2498 | rect.fRight, rect.fBottom, directions[contour] == SkPath::kCCW_Direction |
| 2499 | ? "SkPath::kCCW_Direction" : "SkPath::kCW_Direction"); |
| 2500 | } |
| 2501 | return; |
| 2502 | } |
| 2503 | #endif |
| 2504 | SkPath::FillType fillType = path.getFillType(); |
| 2505 | SkASSERT(fillType >= SkPath::kWinding_FillType && fillType <= SkPath::kInverseEvenOdd_FillType); |
| 2506 | if (includeDeclaration) { |
| 2507 | SkDebugf(" SkPath %s;\n", name); |
| 2508 | } |
| 2509 | SkDebugf(" %s.setFillType(SkPath::%s);\n", name, gFillTypeStr[fillType]); |
| 2510 | iter.setPath(path); |
| 2511 | showPathContours(iter, name); |
| 2512 | } |