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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkPath.h" |
| 9 | #include "include/core/SkString.h" |
| 10 | #include "include/private/SkMutex.h" |
| 11 | #include "src/core/SkOSFile.h" |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 12 | #include "src/core/SkPathPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/pathops/SkOpCoincidence.h" |
| 14 | #include "src/pathops/SkOpContour.h" |
| 15 | #include "src/pathops/SkPathOpsDebug.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 16 | |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 17 | #include <utility> |
| 18 | |
Cary Clark | 918fb1f | 2016-11-15 13:22:25 -0500 | [diff] [blame] | 19 | #if DEBUG_DUMP_VERIFY |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 20 | bool SkPathOpsDebug::gDumpOp; // set to true to write op to file before a crash |
| 21 | bool SkPathOpsDebug::gVerifyOp; // set to true to compare result against regions |
| 22 | #endif |
| 23 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 24 | bool SkPathOpsDebug::gRunFail; // set to true to check for success on tests known to fail |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 25 | bool SkPathOpsDebug::gVeryVerbose; // set to true to run extensive checking tests |
| 26 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 27 | #undef FAIL_IF |
| 28 | #define FAIL_IF(cond, coin) \ |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 29 | do { if (cond) log->record(SkPathOpsDebug::kFail_Glitch, coin); } while (false) |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 30 | |
| 31 | #undef FAIL_WITH_NULL_IF |
| 32 | #define FAIL_WITH_NULL_IF(cond, span) \ |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 33 | do { if (cond) log->record(SkPathOpsDebug::kFail_Glitch, span); } while (false) |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 34 | |
| 35 | #undef RETURN_FALSE_IF |
| 36 | #define RETURN_FALSE_IF(cond, span) \ |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 37 | do { if (cond) log->record(SkPathOpsDebug::kReturnFalse_Glitch, span); \ |
| 38 | } while (false) |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 39 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 40 | class SkCoincidentSpans; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 41 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 42 | #if DEBUG_SORT |
| 43 | int SkPathOpsDebug::gSortCountDefault = SK_MaxS32; |
| 44 | int SkPathOpsDebug::gSortCount; |
| 45 | #endif |
| 46 | |
| 47 | #if DEBUG_ACTIVE_OP |
Ben Wagner | 3f98552 | 2017-10-09 10:47:47 -0400 | [diff] [blame] | 48 | const char* SkPathOpsDebug::kPathOpStr[] = {"diff", "sect", "union", "xor", "rdiff"}; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 51 | #if defined SK_DEBUG || !FORCE_RELEASE |
| 52 | |
commit-bot@chromium.org | fe41b8f | 2014-04-25 14:03:52 +0000 | [diff] [blame] | 53 | int SkPathOpsDebug::gContourID = 0; |
| 54 | int SkPathOpsDebug::gSegmentID = 0; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 55 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 56 | bool SkPathOpsDebug::ChaseContains(const SkTDArray<SkOpSpanBase* >& chaseArray, |
| 57 | const SkOpSpanBase* span) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 58 | for (int index = 0; index < chaseArray.count(); ++index) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 59 | const SkOpSpanBase* entry = chaseArray[index]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 60 | if (entry == span) { |
| 61 | return true; |
| 62 | } |
| 63 | } |
| 64 | return false; |
| 65 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 66 | #endif |
Hal Canary | d499817 | 2018-07-11 11:31:34 -0400 | [diff] [blame] | 67 | |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 68 | #if DEBUG_ACTIVE_SPANS |
| 69 | SkString SkPathOpsDebug::gActiveSpans; |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 70 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 71 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 72 | #if DEBUG_COIN |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 73 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 74 | SkPathOpsDebug::CoinDict SkPathOpsDebug::gCoinSumChangedDict; |
| 75 | SkPathOpsDebug::CoinDict SkPathOpsDebug::gCoinSumVisitedDict; |
| 76 | |
| 77 | static const int kGlitchType_Count = SkPathOpsDebug::kUnalignedTail_Glitch + 1; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 78 | |
| 79 | struct SpanGlitch { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 80 | const SkOpSpanBase* fBase; |
| 81 | const SkOpSpanBase* fSuspect; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 82 | const SkOpSegment* fSegment; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 83 | const SkOpSegment* fOppSegment; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 84 | const SkOpPtT* fCoinSpan; |
| 85 | const SkOpPtT* fEndSpan; |
| 86 | const SkOpPtT* fOppSpan; |
| 87 | const SkOpPtT* fOppEndSpan; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 88 | double fStartT; |
| 89 | double fEndT; |
| 90 | double fOppStartT; |
| 91 | double fOppEndT; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 92 | SkPoint fPt; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 93 | SkPathOpsDebug::GlitchType fType; |
| 94 | |
| 95 | void dumpType() const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct SkPathOpsDebug::GlitchLog { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 99 | void init(const SkOpGlobalState* state) { |
| 100 | fGlobalState = state; |
| 101 | } |
| 102 | |
| 103 | SpanGlitch* recordCommon(GlitchType type) { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 104 | SpanGlitch* glitch = fGlitches.push(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 105 | glitch->fBase = nullptr; |
| 106 | glitch->fSuspect = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 107 | glitch->fSegment = nullptr; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 108 | glitch->fOppSegment = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 109 | glitch->fCoinSpan = nullptr; |
| 110 | glitch->fEndSpan = nullptr; |
| 111 | glitch->fOppSpan = nullptr; |
| 112 | glitch->fOppEndSpan = nullptr; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 113 | glitch->fStartT = SK_ScalarNaN; |
| 114 | glitch->fEndT = SK_ScalarNaN; |
| 115 | glitch->fOppStartT = SK_ScalarNaN; |
| 116 | glitch->fOppEndT = SK_ScalarNaN; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 117 | glitch->fPt = { SK_ScalarNaN, SK_ScalarNaN }; |
| 118 | glitch->fType = type; |
| 119 | return glitch; |
| 120 | } |
| 121 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 122 | void record(GlitchType type, const SkOpSpanBase* base, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 123 | const SkOpSpanBase* suspect = NULL) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 124 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 125 | glitch->fBase = base; |
| 126 | glitch->fSuspect = suspect; |
| 127 | } |
| 128 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 129 | void record(GlitchType type, const SkOpSpanBase* base, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 130 | const SkOpPtT* ptT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 131 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 132 | glitch->fBase = base; |
| 133 | glitch->fCoinSpan = ptT; |
| 134 | } |
| 135 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 136 | void record(GlitchType type, const SkCoincidentSpans* coin, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 137 | const SkCoincidentSpans* opp = NULL) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 138 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 139 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 140 | glitch->fEndSpan = coin->coinPtTEnd(); |
| 141 | if (opp) { |
| 142 | glitch->fOppSpan = opp->coinPtTStart(); |
| 143 | glitch->fOppEndSpan = opp->coinPtTEnd(); |
| 144 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 147 | void record(GlitchType type, const SkOpSpanBase* base, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 148 | const SkOpSegment* seg, double t, SkPoint pt) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 149 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 150 | glitch->fBase = base; |
| 151 | glitch->fSegment = seg; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 152 | glitch->fStartT = t; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 153 | glitch->fPt = pt; |
| 154 | } |
| 155 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 156 | void record(GlitchType type, const SkOpSpanBase* base, double t, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 157 | SkPoint pt) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 158 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 159 | glitch->fBase = base; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 160 | glitch->fStartT = t; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 161 | glitch->fPt = pt; |
| 162 | } |
| 163 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 164 | void record(GlitchType type, const SkCoincidentSpans* coin, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 165 | const SkOpPtT* coinSpan, const SkOpPtT* endSpan) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 166 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 167 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 168 | glitch->fEndSpan = coin->coinPtTEnd(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 169 | glitch->fEndSpan = endSpan; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 170 | glitch->fOppSpan = coinSpan; |
| 171 | glitch->fOppEndSpan = endSpan; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 174 | void record(GlitchType type, const SkCoincidentSpans* coin, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 175 | const SkOpSpanBase* base) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 176 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 177 | glitch->fBase = base; |
| 178 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 179 | glitch->fEndSpan = coin->coinPtTEnd(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 182 | void record(GlitchType type, const SkOpPtT* ptTS, const SkOpPtT* ptTE, |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 183 | const SkOpPtT* oPtTS, const SkOpPtT* oPtTE) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 184 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 185 | glitch->fCoinSpan = ptTS; |
| 186 | glitch->fEndSpan = ptTE; |
| 187 | glitch->fOppSpan = oPtTS; |
| 188 | glitch->fOppEndSpan = oPtTE; |
| 189 | } |
| 190 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 191 | void record(GlitchType type, const SkOpSegment* seg, double startT, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 192 | double endT, const SkOpSegment* oppSeg, double oppStartT, double oppEndT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 193 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 194 | glitch->fSegment = seg; |
| 195 | glitch->fStartT = startT; |
| 196 | glitch->fEndT = endT; |
| 197 | glitch->fOppSegment = oppSeg; |
| 198 | glitch->fOppStartT = oppStartT; |
| 199 | glitch->fOppEndT = oppEndT; |
| 200 | } |
| 201 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 202 | void record(GlitchType type, const SkOpSegment* seg, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 203 | const SkOpSpan* span) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 204 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 205 | glitch->fSegment = seg; |
| 206 | glitch->fBase = span; |
| 207 | } |
| 208 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 209 | void record(GlitchType type, double t, const SkOpSpanBase* span) { |
| 210 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 211 | glitch->fStartT = t; |
| 212 | glitch->fBase = span; |
| 213 | } |
| 214 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 215 | void record(GlitchType type, const SkOpSegment* seg) { |
| 216 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 217 | glitch->fSegment = seg; |
| 218 | } |
| 219 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 220 | void record(GlitchType type, const SkCoincidentSpans* coin, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 221 | const SkOpPtT* ptT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 222 | SpanGlitch* glitch = recordCommon(type); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 223 | glitch->fCoinSpan = coin->coinPtTStart(); |
| 224 | glitch->fEndSpan = ptT; |
| 225 | } |
| 226 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 227 | SkTDArray<SpanGlitch> fGlitches; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 228 | const SkOpGlobalState* fGlobalState; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 229 | }; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 230 | |
| 231 | |
| 232 | void SkPathOpsDebug::CoinDict::add(const SkPathOpsDebug::CoinDict& dict) { |
| 233 | int count = dict.fDict.count(); |
| 234 | for (int index = 0; index < count; ++index) { |
| 235 | this->add(dict.fDict[index]); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | void SkPathOpsDebug::CoinDict::add(const CoinDictEntry& key) { |
| 240 | int count = fDict.count(); |
| 241 | for (int index = 0; index < count; ++index) { |
| 242 | CoinDictEntry* entry = &fDict[index]; |
| 243 | if (entry->fIteration == key.fIteration && entry->fLineNumber == key.fLineNumber) { |
| 244 | SkASSERT(!strcmp(entry->fFunctionName, key.fFunctionName)); |
| 245 | if (entry->fGlitchType == kUninitialized_Glitch) { |
| 246 | entry->fGlitchType = key.fGlitchType; |
| 247 | } |
| 248 | return; |
| 249 | } |
| 250 | } |
| 251 | *fDict.append() = key; |
| 252 | } |
| 253 | |
| 254 | #endif |
| 255 | |
| 256 | #if DEBUG_COIN |
| 257 | static void missing_coincidence(SkPathOpsDebug::GlitchLog* glitches, const SkOpContourHead* contourList) { |
| 258 | const SkOpContour* contour = contourList; |
| 259 | // bool result = false; |
| 260 | do { |
| 261 | /* result |= */ contour->debugMissingCoincidence(glitches); |
| 262 | } while ((contour = contour->next())); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | static void move_multiples(SkPathOpsDebug::GlitchLog* glitches, const SkOpContourHead* contourList) { |
| 267 | const SkOpContour* contour = contourList; |
| 268 | do { |
| 269 | if (contour->debugMoveMultiples(glitches), false) { |
| 270 | return; |
| 271 | } |
| 272 | } while ((contour = contour->next())); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | static void move_nearby(SkPathOpsDebug::GlitchLog* glitches, const SkOpContourHead* contourList) { |
| 277 | const SkOpContour* contour = contourList; |
| 278 | do { |
| 279 | contour->debugMoveNearby(glitches); |
| 280 | } while ((contour = contour->next())); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | #endif |
| 285 | |
| 286 | #if DEBUG_COIN |
| 287 | void SkOpGlobalState::debugAddToCoinChangedDict() { |
| 288 | |
| 289 | #if DEBUG_COINCIDENCE |
caryclark | e6522ea | 2016-10-17 07:54:33 -0700 | [diff] [blame] | 290 | SkPathOpsDebug::CheckHealth(fContourHead); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 291 | #endif |
| 292 | // see if next coincident operation makes a change; if so, record it |
| 293 | SkPathOpsDebug::GlitchLog glitches; |
| 294 | const char* funcName = fCoinDictEntry.fFunctionName; |
| 295 | if (!strcmp("calc_angles", funcName)) { |
| 296 | ; |
| 297 | } else if (!strcmp("missing_coincidence", funcName)) { |
| 298 | missing_coincidence(&glitches, fContourHead); |
| 299 | } else if (!strcmp("move_multiples", funcName)) { |
| 300 | move_multiples(&glitches, fContourHead); |
| 301 | } else if (!strcmp("move_nearby", funcName)) { |
| 302 | move_nearby(&glitches, fContourHead); |
| 303 | } else if (!strcmp("addExpanded", funcName)) { |
| 304 | fCoincidence->debugAddExpanded(&glitches); |
| 305 | } else if (!strcmp("addMissing", funcName)) { |
| 306 | bool added; |
| 307 | fCoincidence->debugAddMissing(&glitches, &added); |
| 308 | } else if (!strcmp("addEndMovedSpans", funcName)) { |
| 309 | fCoincidence->debugAddEndMovedSpans(&glitches); |
| 310 | } else if (!strcmp("correctEnds", funcName)) { |
| 311 | fCoincidence->debugCorrectEnds(&glitches); |
| 312 | } else if (!strcmp("expand", funcName)) { |
| 313 | fCoincidence->debugExpand(&glitches); |
| 314 | } else if (!strcmp("findOverlaps", funcName)) { |
| 315 | ; |
| 316 | } else if (!strcmp("mark", funcName)) { |
| 317 | fCoincidence->debugMark(&glitches); |
| 318 | } else if (!strcmp("apply", funcName)) { |
| 319 | ; |
| 320 | } else { |
| 321 | SkASSERT(0); // add missing case |
| 322 | } |
| 323 | if (glitches.fGlitches.count()) { |
| 324 | fCoinDictEntry.fGlitchType = glitches.fGlitches[0].fType; |
| 325 | } |
| 326 | fCoinChangedDict.add(fCoinDictEntry); |
| 327 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 328 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 329 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 330 | void SkPathOpsDebug::ShowActiveSpans(SkOpContourHead* contourList) { |
| 331 | #if DEBUG_ACTIVE_SPANS |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 332 | SkString str; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 333 | SkOpContour* contour = contourList; |
| 334 | do { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 335 | contour->debugShowActiveSpans(&str); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 336 | } while ((contour = contour->next())); |
Ben Wagner | 29380bd | 2017-10-09 14:43:00 -0400 | [diff] [blame] | 337 | if (!gActiveSpans.equals(str)) { |
| 338 | const char* s = str.c_str(); |
| 339 | const char* end; |
| 340 | while ((end = strchr(s, '\n'))) { |
| 341 | SkDebugf("%.*s", end - s + 1, s); |
| 342 | s = end + 1; |
| 343 | } |
| 344 | gActiveSpans.set(str); |
| 345 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 346 | #endif |
| 347 | } |
| 348 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 349 | #if DEBUG_COINCIDENCE || DEBUG_COIN |
| 350 | void SkPathOpsDebug::CheckHealth(SkOpContourHead* contourList) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 351 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 352 | contourList->globalState()->debugSetCheckHealth(true); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 353 | #endif |
| 354 | #if DEBUG_COIN |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 355 | GlitchLog glitches; |
| 356 | const SkOpContour* contour = contourList; |
| 357 | const SkOpCoincidence* coincidence = contour->globalState()->coincidence(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 358 | coincidence->debugCheckValid(&glitches); // don't call validate; spans may be inconsistent |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 359 | do { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 360 | contour->debugCheckHealth(&glitches); |
| 361 | contour->debugMissingCoincidence(&glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 362 | } while ((contour = contour->next())); |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 363 | bool added; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 364 | coincidence->debugAddMissing(&glitches, &added); |
| 365 | coincidence->debugExpand(&glitches); |
| 366 | coincidence->debugAddExpanded(&glitches); |
| 367 | coincidence->debugMark(&glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 368 | unsigned mask = 0; |
| 369 | for (int index = 0; index < glitches.fGlitches.count(); ++index) { |
| 370 | const SpanGlitch& glitch = glitches.fGlitches[index]; |
| 371 | mask |= 1 << glitch.fType; |
| 372 | } |
| 373 | for (int index = 0; index < kGlitchType_Count; ++index) { |
| 374 | SkDebugf(mask & (1 << index) ? "x" : "-"); |
| 375 | } |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 376 | SkDebugf(" %s\n", contourList->globalState()->debugCoinDictEntry().fFunctionName); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 377 | for (int index = 0; index < glitches.fGlitches.count(); ++index) { |
| 378 | const SpanGlitch& glitch = glitches.fGlitches[index]; |
| 379 | SkDebugf("%02d: ", index); |
| 380 | if (glitch.fBase) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 381 | SkDebugf(" seg/base=%d/%d", glitch.fBase->segment()->debugID(), |
| 382 | glitch.fBase->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 383 | } |
| 384 | if (glitch.fSuspect) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 385 | SkDebugf(" seg/base=%d/%d", glitch.fSuspect->segment()->debugID(), |
| 386 | glitch.fSuspect->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 387 | } |
| 388 | if (glitch.fSegment) { |
| 389 | SkDebugf(" segment=%d", glitch.fSegment->debugID()); |
| 390 | } |
| 391 | if (glitch.fCoinSpan) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 392 | SkDebugf(" coinSeg/Span/PtT=%d/%d/%d", glitch.fCoinSpan->segment()->debugID(), |
| 393 | glitch.fCoinSpan->span()->debugID(), glitch.fCoinSpan->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 394 | } |
| 395 | if (glitch.fEndSpan) { |
| 396 | SkDebugf(" endSpan=%d", glitch.fEndSpan->debugID()); |
| 397 | } |
| 398 | if (glitch.fOppSpan) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 399 | SkDebugf(" oppSeg/Span/PtT=%d/%d/%d", glitch.fOppSpan->segment()->debugID(), |
| 400 | glitch.fOppSpan->span()->debugID(), glitch.fOppSpan->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 401 | } |
| 402 | if (glitch.fOppEndSpan) { |
| 403 | SkDebugf(" oppEndSpan=%d", glitch.fOppEndSpan->debugID()); |
| 404 | } |
| 405 | if (!SkScalarIsNaN(glitch.fStartT)) { |
| 406 | SkDebugf(" startT=%g", glitch.fStartT); |
| 407 | } |
| 408 | if (!SkScalarIsNaN(glitch.fEndT)) { |
| 409 | SkDebugf(" endT=%g", glitch.fEndT); |
| 410 | } |
| 411 | if (glitch.fOppSegment) { |
| 412 | SkDebugf(" segment=%d", glitch.fOppSegment->debugID()); |
| 413 | } |
| 414 | if (!SkScalarIsNaN(glitch.fOppStartT)) { |
| 415 | SkDebugf(" oppStartT=%g", glitch.fOppStartT); |
| 416 | } |
| 417 | if (!SkScalarIsNaN(glitch.fOppEndT)) { |
| 418 | SkDebugf(" oppEndT=%g", glitch.fOppEndT); |
| 419 | } |
| 420 | if (!SkScalarIsNaN(glitch.fPt.fX) || !SkScalarIsNaN(glitch.fPt.fY)) { |
| 421 | SkDebugf(" pt=%g,%g", glitch.fPt.fX, glitch.fPt.fY); |
| 422 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 423 | DumpGlitchType(glitch.fType); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 424 | SkDebugf("\n"); |
| 425 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 426 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 427 | contourList->globalState()->debugSetCheckHealth(false); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 428 | #endif |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 429 | #if 01 && DEBUG_ACTIVE_SPANS |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 430 | // SkDebugf("active after %s:\n", id); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 431 | ShowActiveSpans(contourList); |
| 432 | #endif |
| 433 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 434 | } |
| 435 | #endif |
| 436 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 437 | #if DEBUG_COIN |
| 438 | void SkPathOpsDebug::DumpGlitchType(GlitchType glitchType) { |
| 439 | switch (glitchType) { |
| 440 | case kAddCorruptCoin_Glitch: SkDebugf(" AddCorruptCoin"); break; |
| 441 | case kAddExpandedCoin_Glitch: SkDebugf(" AddExpandedCoin"); break; |
| 442 | case kAddExpandedFail_Glitch: SkDebugf(" AddExpandedFail"); break; |
Kevin Lubick | 48ce543 | 2019-01-04 08:54:32 -0500 | [diff] [blame] | 443 | case kAddIfCollapsed_Glitch: SkDebugf(" AddIfCollapsed"); break; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 444 | case kAddIfMissingCoin_Glitch: SkDebugf(" AddIfMissingCoin"); break; |
| 445 | case kAddMissingCoin_Glitch: SkDebugf(" AddMissingCoin"); break; |
| 446 | case kAddMissingExtend_Glitch: SkDebugf(" AddMissingExtend"); break; |
| 447 | case kAddOrOverlap_Glitch: SkDebugf(" AAddOrOverlap"); break; |
| 448 | case kCollapsedCoin_Glitch: SkDebugf(" CollapsedCoin"); break; |
| 449 | case kCollapsedDone_Glitch: SkDebugf(" CollapsedDone"); break; |
| 450 | case kCollapsedOppValue_Glitch: SkDebugf(" CollapsedOppValue"); break; |
| 451 | case kCollapsedSpan_Glitch: SkDebugf(" CollapsedSpan"); break; |
| 452 | case kCollapsedWindValue_Glitch: SkDebugf(" CollapsedWindValue"); break; |
| 453 | case kCorrectEnd_Glitch: SkDebugf(" CorrectEnd"); break; |
| 454 | case kDeletedCoin_Glitch: SkDebugf(" DeletedCoin"); break; |
| 455 | case kExpandCoin_Glitch: SkDebugf(" ExpandCoin"); break; |
| 456 | case kFail_Glitch: SkDebugf(" Fail"); break; |
| 457 | case kMarkCoinEnd_Glitch: SkDebugf(" MarkCoinEnd"); break; |
| 458 | case kMarkCoinInsert_Glitch: SkDebugf(" MarkCoinInsert"); break; |
| 459 | case kMarkCoinMissing_Glitch: SkDebugf(" MarkCoinMissing"); break; |
| 460 | case kMarkCoinStart_Glitch: SkDebugf(" MarkCoinStart"); break; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 461 | case kMergeMatches_Glitch: SkDebugf(" MergeMatches"); break; |
| 462 | case kMissingCoin_Glitch: SkDebugf(" MissingCoin"); break; |
| 463 | case kMissingDone_Glitch: SkDebugf(" MissingDone"); break; |
| 464 | case kMissingIntersection_Glitch: SkDebugf(" MissingIntersection"); break; |
| 465 | case kMoveMultiple_Glitch: SkDebugf(" MoveMultiple"); break; |
| 466 | case kMoveNearbyClearAll_Glitch: SkDebugf(" MoveNearbyClearAll"); break; |
| 467 | case kMoveNearbyClearAll2_Glitch: SkDebugf(" MoveNearbyClearAll2"); break; |
| 468 | case kMoveNearbyMerge_Glitch: SkDebugf(" MoveNearbyMerge"); break; |
| 469 | case kMoveNearbyMergeFinal_Glitch: SkDebugf(" MoveNearbyMergeFinal"); break; |
| 470 | case kMoveNearbyRelease_Glitch: SkDebugf(" MoveNearbyRelease"); break; |
| 471 | case kMoveNearbyReleaseFinal_Glitch: SkDebugf(" MoveNearbyReleaseFinal"); break; |
| 472 | case kReleasedSpan_Glitch: SkDebugf(" ReleasedSpan"); break; |
| 473 | case kReturnFalse_Glitch: SkDebugf(" ReturnFalse"); break; |
| 474 | case kUnaligned_Glitch: SkDebugf(" Unaligned"); break; |
| 475 | case kUnalignedHead_Glitch: SkDebugf(" UnalignedHead"); break; |
| 476 | case kUnalignedTail_Glitch: SkDebugf(" UnalignedTail"); break; |
| 477 | case kUninitialized_Glitch: break; |
| 478 | default: SkASSERT(0); |
| 479 | } |
| 480 | } |
| 481 | #endif |
| 482 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 483 | #if defined SK_DEBUG || !FORCE_RELEASE |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 484 | void SkPathOpsDebug::MathematicaIze(char* str, size_t bufferLen) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 485 | size_t len = strlen(str); |
| 486 | bool num = false; |
| 487 | for (size_t idx = 0; idx < len; ++idx) { |
| 488 | if (num && str[idx] == 'e') { |
| 489 | if (len + 2 >= bufferLen) { |
| 490 | return; |
| 491 | } |
| 492 | memmove(&str[idx + 2], &str[idx + 1], len - idx); |
| 493 | str[idx] = '*'; |
| 494 | str[idx + 1] = '^'; |
| 495 | ++len; |
| 496 | } |
| 497 | num = str[idx] >= '0' && str[idx] <= '9'; |
| 498 | } |
| 499 | } |
| 500 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 501 | bool SkPathOpsDebug::ValidWind(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 502 | return wind > SK_MinS32 + 0xFFFF && wind < SK_MaxS32 - 0xFFFF; |
| 503 | } |
| 504 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 505 | void SkPathOpsDebug::WindingPrintf(int wind) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 506 | if (wind == SK_MinS32) { |
| 507 | SkDebugf("?"); |
| 508 | } else { |
| 509 | SkDebugf("%d", wind); |
| 510 | } |
| 511 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 512 | #endif // defined SK_DEBUG || !FORCE_RELEASE |
| 513 | |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 514 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 515 | static void show_function_header(const char* functionName) { |
| 516 | SkDebugf("\nstatic void %s(skiatest::Reporter* reporter, const char* filename) {\n", functionName); |
| 517 | if (strcmp("skphealth_com76", functionName) == 0) { |
| 518 | SkDebugf("found it\n"); |
| 519 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 520 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 521 | |
| 522 | static const char* gOpStrs[] = { |
| 523 | "kDifference_SkPathOp", |
| 524 | "kIntersect_SkPathOp", |
| 525 | "kUnion_SkPathOp", |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 526 | "kXOR_PathOp", |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 527 | "kReverseDifference_SkPathOp", |
| 528 | }; |
| 529 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 530 | const char* SkPathOpsDebug::OpStr(SkPathOp op) { |
| 531 | return gOpStrs[op]; |
| 532 | } |
| 533 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 534 | static void show_op(SkPathOp op, const char* pathOne, const char* pathTwo) { |
| 535 | SkDebugf(" testPathOp(reporter, %s, %s, %s, filename);\n", pathOne, pathTwo, gOpStrs[op]); |
| 536 | SkDebugf("}\n"); |
| 537 | } |
| 538 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 539 | void SkPathOpsDebug::ShowPath(const SkPath& a, const SkPath& b, SkPathOp shapeOp, |
| 540 | const char* testName) { |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 541 | static SkMutex& mutex = *(new SkMutex); |
| 542 | |
| 543 | SkAutoMutexExclusive ac(mutex); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 544 | show_function_header(testName); |
| 545 | ShowOnePath(a, "path", true); |
| 546 | ShowOnePath(b, "pathB", true); |
| 547 | show_op(shapeOp, "path", "pathB"); |
| 548 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 549 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 550 | #include "src/pathops/SkIntersectionHelper.h" |
| 551 | #include "src/pathops/SkIntersections.h" |
| 552 | #include "src/pathops/SkPathOpsTypes.h" |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 553 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 554 | #if DEBUG_COIN |
| 555 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 556 | void SkOpGlobalState::debugAddToGlobalCoinDicts() { |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 557 | static SkMutex& mutex = *(new SkMutex); |
| 558 | SkAutoMutexExclusive ac(mutex); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 559 | SkPathOpsDebug::gCoinSumChangedDict.add(fCoinChangedDict); |
| 560 | SkPathOpsDebug::gCoinSumVisitedDict.add(fCoinVisitedDict); |
| 561 | } |
| 562 | |
| 563 | #endif |
| 564 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 565 | #if DEBUG_T_SECT_LOOP_COUNT |
| 566 | void SkOpGlobalState::debugAddLoopCount(SkIntersections* i, const SkIntersectionHelper& wt, |
| 567 | const SkIntersectionHelper& wn) { |
| 568 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 569 | SkIntersections::DebugLoop looper = (SkIntersections::DebugLoop) index; |
| 570 | if (fDebugLoopCount[index] >= i->debugLoopCount(looper)) { |
| 571 | continue; |
| 572 | } |
| 573 | fDebugLoopCount[index] = i->debugLoopCount(looper); |
| 574 | fDebugWorstVerb[index * 2] = wt.segment()->verb(); |
| 575 | fDebugWorstVerb[index * 2 + 1] = wn.segment()->verb(); |
| 576 | sk_bzero(&fDebugWorstPts[index * 8], sizeof(SkPoint) * 8); |
| 577 | memcpy(&fDebugWorstPts[index * 2 * 4], wt.pts(), |
| 578 | (SkPathOpsVerbToPoints(wt.segment()->verb()) + 1) * sizeof(SkPoint)); |
| 579 | memcpy(&fDebugWorstPts[(index * 2 + 1) * 4], wn.pts(), |
| 580 | (SkPathOpsVerbToPoints(wn.segment()->verb()) + 1) * sizeof(SkPoint)); |
| 581 | fDebugWorstWeight[index * 2] = wt.weight(); |
| 582 | fDebugWorstWeight[index * 2 + 1] = wn.weight(); |
| 583 | } |
| 584 | i->debugResetLoopCount(); |
| 585 | } |
| 586 | |
| 587 | void SkOpGlobalState::debugDoYourWorst(SkOpGlobalState* local) { |
| 588 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 589 | if (fDebugLoopCount[index] >= local->fDebugLoopCount[index]) { |
| 590 | continue; |
| 591 | } |
| 592 | fDebugLoopCount[index] = local->fDebugLoopCount[index]; |
| 593 | fDebugWorstVerb[index * 2] = local->fDebugWorstVerb[index * 2]; |
| 594 | fDebugWorstVerb[index * 2 + 1] = local->fDebugWorstVerb[index * 2 + 1]; |
| 595 | memcpy(&fDebugWorstPts[index * 2 * 4], &local->fDebugWorstPts[index * 2 * 4], |
| 596 | sizeof(SkPoint) * 8); |
| 597 | fDebugWorstWeight[index * 2] = local->fDebugWorstWeight[index * 2]; |
| 598 | fDebugWorstWeight[index * 2 + 1] = local->fDebugWorstWeight[index * 2 + 1]; |
| 599 | } |
| 600 | local->debugResetLoopCounts(); |
| 601 | } |
| 602 | |
| 603 | static void dump_curve(SkPath::Verb verb, const SkPoint& pts, float weight) { |
| 604 | if (!verb) { |
| 605 | return; |
| 606 | } |
| 607 | const char* verbs[] = { "", "line", "quad", "conic", "cubic" }; |
| 608 | SkDebugf("%s: {{", verbs[verb]); |
| 609 | int ptCount = SkPathOpsVerbToPoints(verb); |
| 610 | for (int index = 0; index <= ptCount; ++index) { |
| 611 | SkDPoint::Dump((&pts)[index]); |
| 612 | if (index < ptCount - 1) { |
| 613 | SkDebugf(", "); |
| 614 | } |
| 615 | } |
| 616 | SkDebugf("}"); |
| 617 | if (weight != 1) { |
| 618 | SkDebugf(", "); |
| 619 | if (weight == floorf(weight)) { |
| 620 | SkDebugf("%.0f", weight); |
| 621 | } else { |
| 622 | SkDebugf("%1.9gf", weight); |
| 623 | } |
| 624 | } |
| 625 | SkDebugf("}\n"); |
| 626 | } |
| 627 | |
| 628 | void SkOpGlobalState::debugLoopReport() { |
| 629 | const char* loops[] = { "iterations", "coinChecks", "perpCalcs" }; |
| 630 | SkDebugf("\n"); |
| 631 | for (int index = 0; index < (int) SK_ARRAY_COUNT(fDebugLoopCount); ++index) { |
| 632 | SkDebugf("%s: %d\n", loops[index], fDebugLoopCount[index]); |
| 633 | dump_curve(fDebugWorstVerb[index * 2], fDebugWorstPts[index * 2 * 4], |
| 634 | fDebugWorstWeight[index * 2]); |
| 635 | dump_curve(fDebugWorstVerb[index * 2 + 1], fDebugWorstPts[(index * 2 + 1) * 4], |
| 636 | fDebugWorstWeight[index * 2 + 1]); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | void SkOpGlobalState::debugResetLoopCounts() { |
| 641 | sk_bzero(fDebugLoopCount, sizeof(fDebugLoopCount)); |
| 642 | sk_bzero(fDebugWorstVerb, sizeof(fDebugWorstVerb)); |
| 643 | sk_bzero(fDebugWorstPts, sizeof(fDebugWorstPts)); |
| 644 | sk_bzero(fDebugWorstWeight, sizeof(fDebugWorstWeight)); |
| 645 | } |
| 646 | #endif |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 647 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 648 | bool SkOpGlobalState::DebugRunFail() { |
| 649 | return SkPathOpsDebug::gRunFail; |
| 650 | } |
| 651 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 652 | // this is const so it can be called by const methods that overwise don't alter state |
| 653 | #if DEBUG_VALIDATE || DEBUG_COIN |
| 654 | void SkOpGlobalState::debugSetPhase(const char* funcName DEBUG_COIN_DECLARE_PARAMS()) const { |
| 655 | auto writable = const_cast<SkOpGlobalState*>(this); |
| 656 | #if DEBUG_VALIDATE |
| 657 | writable->setPhase(phase); |
| 658 | #endif |
| 659 | #if DEBUG_COIN |
| 660 | SkPathOpsDebug::CoinDictEntry* entry = &writable->fCoinDictEntry; |
| 661 | writable->fPreviousFuncName = entry->fFunctionName; |
| 662 | entry->fIteration = iteration; |
| 663 | entry->fLineNumber = lineNo; |
| 664 | entry->fGlitchType = SkPathOpsDebug::kUninitialized_Glitch; |
| 665 | entry->fFunctionName = funcName; |
| 666 | writable->fCoinVisitedDict.add(*entry); |
| 667 | writable->debugAddToCoinChangedDict(); |
| 668 | #endif |
| 669 | } |
| 670 | #endif |
| 671 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 672 | #if DEBUG_T_SECT_LOOP_COUNT |
| 673 | void SkIntersections::debugBumpLoopCount(DebugLoop index) { |
| 674 | fDebugLoopCount[index]++; |
| 675 | } |
| 676 | |
| 677 | int SkIntersections::debugLoopCount(DebugLoop index) const { |
| 678 | return fDebugLoopCount[index]; |
| 679 | } |
| 680 | |
| 681 | void SkIntersections::debugResetLoopCount() { |
| 682 | sk_bzero(fDebugLoopCount, sizeof(fDebugLoopCount)); |
| 683 | } |
| 684 | #endif |
| 685 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 686 | #include "src/pathops/SkPathOpsConic.h" |
| 687 | #include "src/pathops/SkPathOpsCubic.h" |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 688 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 689 | SkDCubic SkDQuad::debugToCubic() const { |
| 690 | SkDCubic cubic; |
| 691 | cubic[0] = fPts[0]; |
| 692 | cubic[2] = fPts[1]; |
| 693 | cubic[3] = fPts[2]; |
| 694 | cubic[1].fX = (cubic[0].fX + cubic[2].fX * 2) / 3; |
| 695 | cubic[1].fY = (cubic[0].fY + cubic[2].fY * 2) / 3; |
| 696 | cubic[2].fX = (cubic[3].fX + cubic[2].fX * 2) / 3; |
| 697 | cubic[2].fY = (cubic[3].fY + cubic[2].fY * 2) / 3; |
| 698 | return cubic; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 699 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 700 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 701 | void SkDQuad::debugSet(const SkDPoint* pts) { |
| 702 | memcpy(fPts, pts, sizeof(fPts)); |
| 703 | SkDEBUGCODE(fDebugGlobalState = nullptr); |
| 704 | } |
| 705 | |
| 706 | void SkDCubic::debugSet(const SkDPoint* pts) { |
| 707 | memcpy(fPts, pts, sizeof(fPts)); |
| 708 | SkDEBUGCODE(fDebugGlobalState = nullptr); |
| 709 | } |
| 710 | |
| 711 | void SkDConic::debugSet(const SkDPoint* pts, SkScalar weight) { |
| 712 | fPts.debugSet(pts); |
| 713 | fWeight = weight; |
| 714 | } |
| 715 | |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 716 | void SkDRect::debugInit() { |
| 717 | fLeft = fTop = fRight = fBottom = SK_ScalarNaN; |
| 718 | } |
| 719 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 720 | #include "src/pathops/SkOpAngle.h" |
| 721 | #include "src/pathops/SkOpSegment.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 722 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 723 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 724 | // commented-out lines keep this in sync with addT() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 725 | const SkOpPtT* SkOpSegment::debugAddT(double t, SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 726 | debugValidate(); |
| 727 | SkPoint pt = this->ptAtT(t); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 728 | const SkOpSpanBase* span = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 729 | do { |
| 730 | const SkOpPtT* result = span->ptT(); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 731 | if (t == result->fT || this->match(result, this, t, pt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 732 | // span->bumpSpanAdds(); |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 733 | return result; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 734 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 735 | if (t < result->fT) { |
| 736 | const SkOpSpan* prev = result->span()->prev(); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 737 | FAIL_WITH_NULL_IF(!prev, span); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 738 | // marks in global state that new op span has been allocated |
| 739 | this->globalState()->setAllocatedOpSpan(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 740 | // span->init(this, prev, t, pt); |
| 741 | this->debugValidate(); |
| 742 | // #if DEBUG_ADD_T |
| 743 | // SkDebugf("%s insert t=%1.9g segID=%d spanID=%d\n", __FUNCTION__, t, |
| 744 | // span->segment()->debugID(), span->debugID()); |
| 745 | // #endif |
| 746 | // span->bumpSpanAdds(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 747 | return nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 748 | } |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 749 | FAIL_WITH_NULL_IF(span != &fTail, span); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 750 | } while ((span = span->upCast()->next())); |
| 751 | SkASSERT(0); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 752 | return nullptr; // we never get here, but need this to satisfy compiler |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 753 | } |
| 754 | #endif |
| 755 | |
| 756 | #if DEBUG_ANGLE |
| 757 | void SkOpSegment::debugCheckAngleCoin() const { |
| 758 | const SkOpSpanBase* base = &fHead; |
| 759 | const SkOpSpan* span; |
| 760 | do { |
| 761 | const SkOpAngle* angle = base->fromAngle(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 762 | if (angle && angle->debugCheckCoincidence()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 763 | angle->debugCheckNearCoincidence(); |
| 764 | } |
| 765 | if (base->final()) { |
| 766 | break; |
| 767 | } |
| 768 | span = base->upCast(); |
| 769 | angle = span->toAngle(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 770 | if (angle && angle->debugCheckCoincidence()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 771 | angle->debugCheckNearCoincidence(); |
| 772 | } |
| 773 | } while ((base = span->next())); |
| 774 | } |
| 775 | #endif |
| 776 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 777 | #if DEBUG_COIN |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 778 | // this mimics the order of the checks in handle coincidence |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 779 | void SkOpSegment::debugCheckHealth(SkPathOpsDebug::GlitchLog* glitches) const { |
| 780 | debugMoveMultiples(glitches); |
| 781 | debugMoveNearby(glitches); |
| 782 | debugMissingCoincidence(glitches); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 783 | } |
| 784 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 785 | // commented-out lines keep this in sync with clearAll() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 786 | void SkOpSegment::debugClearAll(SkPathOpsDebug::GlitchLog* glitches) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 787 | const SkOpSpan* span = &fHead; |
| 788 | do { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 789 | this->debugClearOne(span, glitches); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 790 | } while ((span = span->next()->upCastable())); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 791 | this->globalState()->coincidence()->debugRelease(glitches, this); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // commented-out lines keep this in sync with clearOne() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 795 | void SkOpSegment::debugClearOne(const SkOpSpan* span, SkPathOpsDebug::GlitchLog* glitches) const { |
| 796 | if (span->windValue()) glitches->record(SkPathOpsDebug::kCollapsedWindValue_Glitch, span); |
| 797 | if (span->oppValue()) glitches->record(SkPathOpsDebug::kCollapsedOppValue_Glitch, span); |
| 798 | if (!span->done()) glitches->record(SkPathOpsDebug::kCollapsedDone_Glitch, span); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 799 | } |
| 800 | #endif |
| 801 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 802 | SkOpAngle* SkOpSegment::debugLastAngle() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 803 | SkOpAngle* result = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 804 | SkOpSpan* span = this->head(); |
| 805 | do { |
| 806 | if (span->toAngle()) { |
| 807 | SkASSERT(!result); |
| 808 | result = span->toAngle(); |
| 809 | } |
| 810 | } while ((span = span->next()->upCastable())); |
| 811 | SkASSERT(result); |
| 812 | return result; |
| 813 | } |
| 814 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 815 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 816 | // commented-out lines keep this in sync with ClearVisited |
| 817 | void SkOpSegment::DebugClearVisited(const SkOpSpanBase* span) { |
| 818 | // reset visited flag back to false |
| 819 | do { |
| 820 | const SkOpPtT* ptT = span->ptT(), * stopPtT = ptT; |
| 821 | while ((ptT = ptT->next()) != stopPtT) { |
| 822 | const SkOpSegment* opp = ptT->segment(); |
| 823 | opp->resetDebugVisited(); |
| 824 | } |
| 825 | } while (!span->final() && (span = span->upCast()->next())); |
| 826 | } |
| 827 | #endif |
| 828 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 829 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 830 | // commented-out lines keep this in sync with missingCoincidence() |
| 831 | // look for pairs of undetected coincident curves |
| 832 | // assumes that segments going in have visited flag clear |
| 833 | // Even though pairs of curves correct detect coincident runs, a run may be missed |
| 834 | // if the coincidence is a product of multiple intersections. For instance, given |
| 835 | // curves A, B, and C: |
| 836 | // A-B intersect at a point 1; A-C and B-C intersect at point 2, so near |
| 837 | // the end of C that the intersection is replaced with the end of C. |
| 838 | // Even though A-B correctly do not detect an intersection at point 2, |
| 839 | // the resulting run from point 1 to point 2 is coincident on A and B. |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 840 | void SkOpSegment::debugMissingCoincidence(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 841 | if (this->done()) { |
| 842 | return; |
| 843 | } |
| 844 | const SkOpSpan* prior = nullptr; |
| 845 | const SkOpSpanBase* spanBase = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 846 | // bool result = false; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 847 | do { |
| 848 | const SkOpPtT* ptT = spanBase->ptT(), * spanStopPtT = ptT; |
| 849 | SkASSERT(ptT->span() == spanBase); |
| 850 | while ((ptT = ptT->next()) != spanStopPtT) { |
| 851 | if (ptT->deleted()) { |
| 852 | continue; |
| 853 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 854 | const SkOpSegment* opp = ptT->span()->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 855 | if (opp->done()) { |
| 856 | continue; |
| 857 | } |
| 858 | // 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] | 859 | if (!opp->debugVisited()) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 860 | continue; |
| 861 | } |
| 862 | if (spanBase == &fHead) { |
| 863 | continue; |
| 864 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 865 | if (ptT->segment() == this) { |
| 866 | continue; |
| 867 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 868 | const SkOpSpan* span = spanBase->upCastable(); |
| 869 | // FIXME?: this assumes that if the opposite segment is coincident then no more |
| 870 | // coincidence needs to be detected. This may not be true. |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 871 | 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] | 872 | continue; |
| 873 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 874 | 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] | 875 | continue; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 876 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 877 | const SkOpPtT* priorPtT = nullptr, * priorStopPtT; |
| 878 | // find prior span containing opp segment |
| 879 | const SkOpSegment* priorOpp = nullptr; |
| 880 | const SkOpSpan* priorTest = spanBase->prev(); |
| 881 | while (!priorOpp && priorTest) { |
| 882 | priorStopPtT = priorPtT = priorTest->ptT(); |
| 883 | while ((priorPtT = priorPtT->next()) != priorStopPtT) { |
| 884 | if (priorPtT->deleted()) { |
| 885 | continue; |
| 886 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 887 | const SkOpSegment* segment = priorPtT->span()->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 888 | if (segment == opp) { |
| 889 | prior = priorTest; |
| 890 | priorOpp = opp; |
| 891 | break; |
| 892 | } |
| 893 | } |
| 894 | priorTest = priorTest->prev(); |
| 895 | } |
| 896 | if (!priorOpp) { |
| 897 | continue; |
| 898 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 899 | if (priorPtT == ptT) { |
| 900 | continue; |
| 901 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 902 | const SkOpPtT* oppStart = prior->ptT(); |
| 903 | const SkOpPtT* oppEnd = spanBase->ptT(); |
| 904 | bool swapped = priorPtT->fT > ptT->fT; |
| 905 | if (swapped) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 906 | using std::swap; |
| 907 | swap(priorPtT, ptT); |
| 908 | swap(oppStart, oppEnd); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 909 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 910 | const SkOpCoincidence* coincidence = this->globalState()->coincidence(); |
| 911 | const SkOpPtT* rootPriorPtT = priorPtT->span()->ptT(); |
| 912 | const SkOpPtT* rootPtT = ptT->span()->ptT(); |
| 913 | const SkOpPtT* rootOppStart = oppStart->span()->ptT(); |
| 914 | const SkOpPtT* rootOppEnd = oppEnd->span()->ptT(); |
| 915 | if (coincidence->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd)) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 916 | goto swapBack; |
| 917 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 918 | if (testForCoincidence(rootPriorPtT, rootPtT, prior, spanBase, opp)) { |
| 919 | // mark coincidence |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 920 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 921 | // SkDebugf("%s coinSpan=%d endSpan=%d oppSpan=%d oppEndSpan=%d\n", __FUNCTION__, |
| 922 | // rootPriorPtT->debugID(), rootPtT->debugID(), rootOppStart->debugID(), |
| 923 | // rootOppEnd->debugID()); |
| 924 | #endif |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 925 | log->record(SkPathOpsDebug::kMissingCoin_Glitch, priorPtT, ptT, oppStart, oppEnd); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 926 | // coincidences->add(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd); |
| 927 | // } |
| 928 | #if DEBUG_COINCIDENCE |
caryclark | d656200 | 2016-07-27 12:02:07 -0700 | [diff] [blame] | 929 | // SkASSERT(coincidences->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 930 | #endif |
| 931 | // result = true; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 932 | } |
| 933 | swapBack: |
| 934 | if (swapped) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 935 | using std::swap; |
| 936 | swap(priorPtT, ptT); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } while ((spanBase = spanBase->final() ? nullptr : spanBase->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 940 | DebugClearVisited(&fHead); |
| 941 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 942 | } |
| 943 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 944 | // commented-out lines keep this in sync with moveMultiples() |
| 945 | // if a span has more than one intersection, merge the other segments' span as needed |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 946 | void SkOpSegment::debugMoveMultiples(SkPathOpsDebug::GlitchLog* glitches) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 947 | debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 948 | const SkOpSpanBase* test = &fHead; |
| 949 | do { |
| 950 | int addCount = test->spanAddsCount(); |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 951 | // SkASSERT(addCount >= 1); |
| 952 | if (addCount <= 1) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 953 | continue; |
| 954 | } |
| 955 | const SkOpPtT* startPtT = test->ptT(); |
| 956 | const SkOpPtT* testPtT = startPtT; |
| 957 | do { // iterate through all spans associated with start |
| 958 | const SkOpSpanBase* oppSpan = testPtT->span(); |
| 959 | if (oppSpan->spanAddsCount() == addCount) { |
| 960 | continue; |
| 961 | } |
| 962 | if (oppSpan->deleted()) { |
| 963 | continue; |
| 964 | } |
| 965 | const SkOpSegment* oppSegment = oppSpan->segment(); |
| 966 | if (oppSegment == this) { |
| 967 | continue; |
| 968 | } |
| 969 | // find range of spans to consider merging |
| 970 | const SkOpSpanBase* oppPrev = oppSpan; |
| 971 | const SkOpSpanBase* oppFirst = oppSpan; |
| 972 | while ((oppPrev = oppPrev->prev())) { |
| 973 | if (!roughly_equal(oppPrev->t(), oppSpan->t())) { |
| 974 | break; |
| 975 | } |
| 976 | if (oppPrev->spanAddsCount() == addCount) { |
| 977 | continue; |
| 978 | } |
| 979 | if (oppPrev->deleted()) { |
| 980 | continue; |
| 981 | } |
| 982 | oppFirst = oppPrev; |
| 983 | } |
| 984 | const SkOpSpanBase* oppNext = oppSpan; |
| 985 | const SkOpSpanBase* oppLast = oppSpan; |
| 986 | while ((oppNext = oppNext->final() ? nullptr : oppNext->upCast()->next())) { |
| 987 | if (!roughly_equal(oppNext->t(), oppSpan->t())) { |
| 988 | break; |
| 989 | } |
| 990 | if (oppNext->spanAddsCount() == addCount) { |
| 991 | continue; |
| 992 | } |
| 993 | if (oppNext->deleted()) { |
| 994 | continue; |
| 995 | } |
| 996 | oppLast = oppNext; |
| 997 | } |
| 998 | if (oppFirst == oppLast) { |
| 999 | continue; |
| 1000 | } |
| 1001 | const SkOpSpanBase* oppTest = oppFirst; |
| 1002 | do { |
| 1003 | if (oppTest == oppSpan) { |
| 1004 | continue; |
| 1005 | } |
| 1006 | // check to see if the candidate meets specific criteria: |
| 1007 | // it contains spans of segments in test's loop but not including 'this' |
| 1008 | const SkOpPtT* oppStartPtT = oppTest->ptT(); |
| 1009 | const SkOpPtT* oppPtT = oppStartPtT; |
| 1010 | while ((oppPtT = oppPtT->next()) != oppStartPtT) { |
| 1011 | const SkOpSegment* oppPtTSegment = oppPtT->segment(); |
| 1012 | if (oppPtTSegment == this) { |
| 1013 | goto tryNextSpan; |
| 1014 | } |
| 1015 | const SkOpPtT* matchPtT = startPtT; |
| 1016 | do { |
| 1017 | if (matchPtT->segment() == oppPtTSegment) { |
| 1018 | goto foundMatch; |
| 1019 | } |
| 1020 | } while ((matchPtT = matchPtT->next()) != startPtT); |
| 1021 | goto tryNextSpan; |
| 1022 | foundMatch: // merge oppTest and oppSpan |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1023 | oppSegment->debugValidate(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1024 | oppTest->debugMergeMatches(glitches, oppSpan); |
| 1025 | oppTest->debugAddOpp(glitches, oppSpan); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1026 | oppSegment->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1027 | goto checkNextSpan; |
| 1028 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1029 | tryNextSpan: |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1030 | ; |
| 1031 | } while (oppTest != oppLast && (oppTest = oppTest->upCast()->next())); |
| 1032 | } while ((testPtT = testPtT->next()) != startPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1033 | checkNextSpan: |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1034 | ; |
| 1035 | } while ((test = test->final() ? nullptr : test->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1036 | debugValidate(); |
| 1037 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1040 | // commented-out lines keep this in sync with moveNearby() |
| 1041 | // Move nearby t values and pts so they all hang off the same span. Alignment happens later. |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1042 | void SkOpSegment::debugMoveNearby(SkPathOpsDebug::GlitchLog* glitches) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1043 | debugValidate(); |
| 1044 | // release undeleted spans pointing to this seg that are linked to the primary span |
| 1045 | const SkOpSpanBase* spanBase = &fHead; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1046 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1047 | const SkOpPtT* ptT = spanBase->ptT(); |
| 1048 | const SkOpPtT* headPtT = ptT; |
| 1049 | while ((ptT = ptT->next()) != headPtT) { |
| 1050 | const SkOpSpanBase* test = ptT->span(); |
| 1051 | if (ptT->segment() == this && !ptT->deleted() && test != spanBase |
| 1052 | && test->ptT() == ptT) { |
| 1053 | if (test->final()) { |
| 1054 | if (spanBase == &fHead) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1055 | glitches->record(SkPathOpsDebug::kMoveNearbyClearAll_Glitch, this); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1056 | // return; |
| 1057 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1058 | glitches->record(SkPathOpsDebug::kMoveNearbyReleaseFinal_Glitch, spanBase, ptT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1059 | } else if (test->prev()) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1060 | glitches->record(SkPathOpsDebug::kMoveNearbyRelease_Glitch, test, headPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1061 | } |
| 1062 | // break; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1065 | spanBase = spanBase->upCast()->next(); |
| 1066 | } while (!spanBase->final()); |
| 1067 | |
| 1068 | // This loop looks for adjacent spans which are near by |
| 1069 | spanBase = &fHead; |
| 1070 | do { // iterate through all spans associated with start |
| 1071 | const SkOpSpanBase* test = spanBase->upCast()->next(); |
Cary Clark | 73e597d | 2017-04-18 12:08:58 -0400 | [diff] [blame] | 1072 | bool found; |
| 1073 | if (!this->spansNearby(spanBase, test, &found)) { |
| 1074 | glitches->record(SkPathOpsDebug::kMoveNearbyMergeFinal_Glitch, test); |
| 1075 | } |
| 1076 | if (found) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1077 | if (test->final()) { |
| 1078 | if (spanBase->prev()) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1079 | glitches->record(SkPathOpsDebug::kMoveNearbyMergeFinal_Glitch, test); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1080 | } else { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1081 | glitches->record(SkPathOpsDebug::kMoveNearbyClearAll2_Glitch, this); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1082 | // return |
| 1083 | } |
| 1084 | } else { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1085 | glitches->record(SkPathOpsDebug::kMoveNearbyMerge_Glitch, spanBase); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | spanBase = test; |
| 1089 | } while (!spanBase->final()); |
| 1090 | debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1091 | } |
| 1092 | #endif |
| 1093 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1094 | void SkOpSegment::debugReset() { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1095 | this->init(this->fPts, this->fWeight, this->contour(), this->verb()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1098 | #if DEBUG_COINCIDENCE_ORDER |
| 1099 | void SkOpSegment::debugSetCoinT(int index, SkScalar t) const { |
| 1100 | if (fDebugBaseMax < 0 || fDebugBaseIndex == index) { |
| 1101 | fDebugBaseIndex = index; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1102 | fDebugBaseMin = std::min(t, fDebugBaseMin); |
| 1103 | fDebugBaseMax = std::max(t, fDebugBaseMax); |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1104 | return; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 1105 | } |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1106 | SkASSERT(fDebugBaseMin >= t || t >= fDebugBaseMax); |
| 1107 | if (fDebugLastMax < 0 || fDebugLastIndex == index) { |
| 1108 | fDebugLastIndex = index; |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1109 | fDebugLastMin = std::min(t, fDebugLastMin); |
| 1110 | fDebugLastMax = std::max(t, fDebugLastMax); |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 1111 | return; |
| 1112 | } |
| 1113 | SkASSERT(fDebugLastMin >= t || t >= fDebugLastMax); |
| 1114 | SkASSERT((t - fDebugBaseMin > 0) == (fDebugLastMin - fDebugBaseMin > 0)); |
| 1115 | } |
| 1116 | #endif |
| 1117 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1118 | #if DEBUG_ACTIVE_SPANS |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1119 | void SkOpSegment::debugShowActiveSpans(SkString* str) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1120 | debugValidate(); |
| 1121 | if (done()) { |
| 1122 | return; |
| 1123 | } |
| 1124 | int lastId = -1; |
| 1125 | double lastT = -1; |
| 1126 | const SkOpSpan* span = &fHead; |
| 1127 | do { |
| 1128 | if (span->done()) { |
| 1129 | continue; |
| 1130 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1131 | if (lastId == this->debugID() && lastT == span->t()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1132 | continue; |
| 1133 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1134 | lastId = this->debugID(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1135 | lastT = span->t(); |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1136 | str->appendf("%s id=%d", __FUNCTION__, this->debugID()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1137 | // since endpoints may have be adjusted, show actual computed curves |
| 1138 | SkDCurve curvePart; |
| 1139 | this->subDivide(span, span->next(), &curvePart); |
| 1140 | const SkDPoint* pts = curvePart.fCubic.fPts; |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1141 | str->appendf(" (%1.9g,%1.9g", pts[0].fX, pts[0].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1142 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1143 | str->appendf(" %1.9g,%1.9g", pts[vIndex].fX, pts[vIndex].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1144 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1145 | if (SkPath::kConic_Verb == fVerb) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1146 | str->appendf(" %1.9gf", curvePart.fConic.fWeight); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1147 | } |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1148 | str->appendf(") t=%1.9g tEnd=%1.9g", span->t(), span->next()->t()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1149 | if (span->windSum() == SK_MinS32) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1150 | str->appendf(" windSum=?"); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1151 | } else { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1152 | str->appendf(" windSum=%d", span->windSum()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1153 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1154 | if (span->oppValue() && span->oppSum() == SK_MinS32) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1155 | str->appendf(" oppSum=?"); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1156 | } else if (span->oppValue() || span->oppSum() != SK_MinS32) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1157 | str->appendf(" oppSum=%d", span->oppSum()); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1158 | } |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1159 | str->appendf(" windValue=%d", span->windValue()); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1160 | if (span->oppValue() || span->oppSum() != SK_MinS32) { |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1161 | str->appendf(" oppValue=%d", span->oppValue()); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1162 | } |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1163 | str->appendf("\n"); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1164 | } while ((span = span->next()->upCastable())); |
| 1165 | } |
| 1166 | #endif |
| 1167 | |
| 1168 | #if DEBUG_MARK_DONE |
| 1169 | void SkOpSegment::debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding) { |
| 1170 | const SkPoint& pt = span->ptT()->fPt; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1171 | SkDebugf("%s id=%d", fun, this->debugID()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1172 | SkDebugf(" (%1.9g,%1.9g", fPts[0].fX, fPts[0].fY); |
| 1173 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
| 1174 | SkDebugf(" %1.9g,%1.9g", fPts[vIndex].fX, fPts[vIndex].fY); |
| 1175 | } |
| 1176 | SkDebugf(") t=%1.9g [%d] (%1.9g,%1.9g) tEnd=%1.9g newWindSum=", |
| 1177 | span->t(), span->debugID(), pt.fX, pt.fY, span->next()->t()); |
| 1178 | if (winding == SK_MinS32) { |
| 1179 | SkDebugf("?"); |
| 1180 | } else { |
| 1181 | SkDebugf("%d", winding); |
| 1182 | } |
| 1183 | SkDebugf(" windSum="); |
| 1184 | if (span->windSum() == SK_MinS32) { |
| 1185 | SkDebugf("?"); |
| 1186 | } else { |
| 1187 | SkDebugf("%d", span->windSum()); |
| 1188 | } |
| 1189 | SkDebugf(" windValue=%d\n", span->windValue()); |
| 1190 | } |
| 1191 | |
| 1192 | void SkOpSegment::debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding, |
| 1193 | int oppWinding) { |
| 1194 | const SkPoint& pt = span->ptT()->fPt; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1195 | SkDebugf("%s id=%d", fun, this->debugID()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1196 | SkDebugf(" (%1.9g,%1.9g", fPts[0].fX, fPts[0].fY); |
| 1197 | for (int vIndex = 1; vIndex <= SkPathOpsVerbToPoints(fVerb); ++vIndex) { |
| 1198 | SkDebugf(" %1.9g,%1.9g", fPts[vIndex].fX, fPts[vIndex].fY); |
| 1199 | } |
| 1200 | SkDebugf(") t=%1.9g [%d] (%1.9g,%1.9g) tEnd=%1.9g newWindSum=", |
| 1201 | span->t(), span->debugID(), pt.fX, pt.fY, span->next()->t(), winding, oppWinding); |
| 1202 | if (winding == SK_MinS32) { |
| 1203 | SkDebugf("?"); |
| 1204 | } else { |
| 1205 | SkDebugf("%d", winding); |
| 1206 | } |
| 1207 | SkDebugf(" newOppSum="); |
| 1208 | if (oppWinding == SK_MinS32) { |
| 1209 | SkDebugf("?"); |
| 1210 | } else { |
| 1211 | SkDebugf("%d", oppWinding); |
| 1212 | } |
| 1213 | SkDebugf(" oppSum="); |
| 1214 | if (span->oppSum() == SK_MinS32) { |
| 1215 | SkDebugf("?"); |
| 1216 | } else { |
| 1217 | SkDebugf("%d", span->oppSum()); |
| 1218 | } |
| 1219 | SkDebugf(" windSum="); |
| 1220 | if (span->windSum() == SK_MinS32) { |
| 1221 | SkDebugf("?"); |
| 1222 | } else { |
| 1223 | SkDebugf("%d", span->windSum()); |
| 1224 | } |
| 1225 | SkDebugf(" windValue=%d oppValue=%d\n", span->windValue(), span->oppValue()); |
| 1226 | } |
| 1227 | |
| 1228 | #endif |
| 1229 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1230 | // loop looking for a pair of angle parts that are too close to be sorted |
| 1231 | /* This is called after other more simple intersection and angle sorting tests have been exhausted. |
| 1232 | This should be rarely called -- the test below is thorough and time consuming. |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1233 | This checks the distance between start points; the distance between |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1234 | */ |
| 1235 | #if DEBUG_ANGLE |
| 1236 | void SkOpAngle::debugCheckNearCoincidence() const { |
| 1237 | const SkOpAngle* test = this; |
| 1238 | do { |
| 1239 | const SkOpSegment* testSegment = test->segment(); |
| 1240 | double testStartT = test->start()->t(); |
| 1241 | SkDPoint testStartPt = testSegment->dPtAtT(testStartT); |
| 1242 | double testEndT = test->end()->t(); |
| 1243 | SkDPoint testEndPt = testSegment->dPtAtT(testEndT); |
| 1244 | double testLenSq = testStartPt.distanceSquared(testEndPt); |
| 1245 | SkDebugf("%s testLenSq=%1.9g id=%d\n", __FUNCTION__, testLenSq, testSegment->debugID()); |
| 1246 | double testMidT = (testStartT + testEndT) / 2; |
| 1247 | const SkOpAngle* next = test; |
| 1248 | while ((next = next->fNext) != this) { |
| 1249 | SkOpSegment* nextSegment = next->segment(); |
| 1250 | double testMidDistSq = testSegment->distSq(testMidT, next); |
| 1251 | double testEndDistSq = testSegment->distSq(testEndT, next); |
| 1252 | double nextStartT = next->start()->t(); |
| 1253 | SkDPoint nextStartPt = nextSegment->dPtAtT(nextStartT); |
| 1254 | double distSq = testStartPt.distanceSquared(nextStartPt); |
| 1255 | double nextEndT = next->end()->t(); |
| 1256 | double nextMidT = (nextStartT + nextEndT) / 2; |
| 1257 | double nextMidDistSq = nextSegment->distSq(nextMidT, test); |
| 1258 | double nextEndDistSq = nextSegment->distSq(nextEndT, test); |
| 1259 | SkDebugf("%s distSq=%1.9g testId=%d nextId=%d\n", __FUNCTION__, distSq, |
| 1260 | testSegment->debugID(), nextSegment->debugID()); |
| 1261 | SkDebugf("%s testMidDistSq=%1.9g\n", __FUNCTION__, testMidDistSq); |
| 1262 | SkDebugf("%s testEndDistSq=%1.9g\n", __FUNCTION__, testEndDistSq); |
| 1263 | SkDebugf("%s nextMidDistSq=%1.9g\n", __FUNCTION__, nextMidDistSq); |
| 1264 | SkDebugf("%s nextEndDistSq=%1.9g\n", __FUNCTION__, nextEndDistSq); |
| 1265 | SkDPoint nextEndPt = nextSegment->dPtAtT(nextEndT); |
| 1266 | double nextLenSq = nextStartPt.distanceSquared(nextEndPt); |
| 1267 | SkDebugf("%s nextLenSq=%1.9g\n", __FUNCTION__, nextLenSq); |
| 1268 | SkDebugf("\n"); |
| 1269 | } |
| 1270 | test = test->fNext; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1271 | } while (test->fNext != this); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1272 | } |
| 1273 | #endif |
| 1274 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1275 | #if DEBUG_ANGLE |
| 1276 | SkString SkOpAngle::debugPart() const { |
| 1277 | SkString result; |
| 1278 | switch (this->segment()->verb()) { |
| 1279 | case SkPath::kLine_Verb: |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1280 | result.printf(LINE_DEBUG_STR " id=%d", LINE_DEBUG_DATA(fPart.fCurve), |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1281 | this->segment()->debugID()); |
| 1282 | break; |
| 1283 | case SkPath::kQuad_Verb: |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1284 | result.printf(QUAD_DEBUG_STR " id=%d", QUAD_DEBUG_DATA(fPart.fCurve), |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1285 | this->segment()->debugID()); |
| 1286 | break; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1287 | case SkPath::kConic_Verb: |
| 1288 | result.printf(CONIC_DEBUG_STR " id=%d", |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1289 | CONIC_DEBUG_DATA(fPart.fCurve, fPart.fCurve.fConic.fWeight), |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1290 | this->segment()->debugID()); |
| 1291 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1292 | case SkPath::kCubic_Verb: |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1293 | result.printf(CUBIC_DEBUG_STR " id=%d", CUBIC_DEBUG_DATA(fPart.fCurve), |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1294 | this->segment()->debugID()); |
| 1295 | break; |
| 1296 | default: |
| 1297 | SkASSERT(0); |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 1298 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1299 | return result; |
| 1300 | } |
| 1301 | #endif |
| 1302 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1303 | #if DEBUG_SORT |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1304 | void SkOpAngle::debugLoop() const { |
caryclark | e4097e3 | 2014-06-18 07:24:19 -0700 | [diff] [blame] | 1305 | const SkOpAngle* first = this; |
| 1306 | const SkOpAngle* next = this; |
| 1307 | do { |
| 1308 | next->dumpOne(true); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1309 | SkDebugf("\n"); |
caryclark | e4097e3 | 2014-06-18 07:24:19 -0700 | [diff] [blame] | 1310 | next = next->fNext; |
| 1311 | } while (next && next != first); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1312 | next = first; |
| 1313 | do { |
| 1314 | next->debugValidate(); |
| 1315 | next = next->fNext; |
| 1316 | } while (next && next != first); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1317 | } |
| 1318 | #endif |
| 1319 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1320 | void SkOpAngle::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1321 | #if DEBUG_COINCIDENCE |
| 1322 | if (this->globalState()->debugCheckHealth()) { |
| 1323 | return; |
| 1324 | } |
| 1325 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1326 | #if DEBUG_VALIDATE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1327 | const SkOpAngle* first = this; |
| 1328 | const SkOpAngle* next = this; |
| 1329 | int wind = 0; |
| 1330 | int opp = 0; |
| 1331 | int lastXor = -1; |
| 1332 | int lastOppXor = -1; |
| 1333 | do { |
| 1334 | if (next->unorderable()) { |
| 1335 | return; |
| 1336 | } |
| 1337 | const SkOpSpan* minSpan = next->start()->starter(next->end()); |
| 1338 | if (minSpan->windValue() == SK_MinS32) { |
| 1339 | return; |
| 1340 | } |
| 1341 | bool op = next->segment()->operand(); |
| 1342 | bool isXor = next->segment()->isXor(); |
| 1343 | bool oppXor = next->segment()->oppXor(); |
| 1344 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || between(0, minSpan->windValue(), DEBUG_LIMIT_WIND_SUM)); |
| 1345 | SkASSERT(!DEBUG_LIMIT_WIND_SUM |
| 1346 | || between(-DEBUG_LIMIT_WIND_SUM, minSpan->oppValue(), DEBUG_LIMIT_WIND_SUM)); |
| 1347 | bool useXor = op ? oppXor : isXor; |
| 1348 | SkASSERT(lastXor == -1 || lastXor == (int) useXor); |
| 1349 | lastXor = (int) useXor; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1350 | wind += next->debugSign() * (op ? minSpan->oppValue() : minSpan->windValue()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1351 | if (useXor) { |
| 1352 | wind &= 1; |
| 1353 | } |
| 1354 | useXor = op ? isXor : oppXor; |
| 1355 | SkASSERT(lastOppXor == -1 || lastOppXor == (int) useXor); |
| 1356 | lastOppXor = (int) useXor; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1357 | opp += next->debugSign() * (op ? minSpan->windValue() : minSpan->oppValue()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1358 | if (useXor) { |
| 1359 | opp &= 1; |
| 1360 | } |
| 1361 | next = next->fNext; |
| 1362 | } while (next && next != first); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1363 | SkASSERT(wind == 0 || !SkPathOpsDebug::gRunFail); |
| 1364 | SkASSERT(opp == 0 || !SkPathOpsDebug::gRunFail); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1365 | #endif |
| 1366 | } |
| 1367 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1368 | void SkOpAngle::debugValidateNext() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1369 | #if !FORCE_RELEASE |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1370 | const SkOpAngle* first = this; |
| 1371 | const SkOpAngle* next = first; |
| 1372 | SkTDArray<const SkOpAngle*>(angles); |
| 1373 | do { |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1374 | // SkASSERT_RELEASE(next->fSegment->debugContains(next)); |
Mike Reed | b547579 | 2018-08-08 16:17:42 -0400 | [diff] [blame] | 1375 | angles.push_back(next); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1376 | next = next->next(); |
| 1377 | if (next == first) { |
| 1378 | break; |
| 1379 | } |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1380 | SkASSERT_RELEASE(!angles.contains(next)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1381 | if (!next) { |
| 1382 | return; |
| 1383 | } |
| 1384 | } while (true); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1385 | #endif |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1386 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1387 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1388 | #ifdef SK_DEBUG |
| 1389 | void SkCoincidentSpans::debugStartCheck(const SkOpSpanBase* outer, const SkOpSpanBase* over, |
| 1390 | const SkOpGlobalState* debugState) const { |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1391 | SkASSERT(coinPtTEnd()->span() == over || !SkOpGlobalState::DebugRunFail()); |
| 1392 | SkASSERT(oppPtTEnd()->span() == outer || !SkOpGlobalState::DebugRunFail()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1393 | } |
| 1394 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1395 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1396 | #if DEBUG_COIN |
| 1397 | // sets the span's end to the ptT referenced by the previous-next |
| 1398 | void SkCoincidentSpans::debugCorrectOneEnd(SkPathOpsDebug::GlitchLog* log, |
| 1399 | const SkOpPtT* (SkCoincidentSpans::* getEnd)() const, |
| 1400 | void (SkCoincidentSpans::*setEnd)(const SkOpPtT* ptT) const ) const { |
| 1401 | const SkOpPtT* origPtT = (this->*getEnd)(); |
| 1402 | const SkOpSpanBase* origSpan = origPtT->span(); |
| 1403 | const SkOpSpan* prev = origSpan->prev(); |
| 1404 | const SkOpPtT* testPtT = prev ? prev->next()->ptT() |
| 1405 | : origSpan->upCast()->next()->prev()->ptT(); |
| 1406 | if (origPtT != testPtT) { |
| 1407 | log->record(SkPathOpsDebug::kCorrectEnd_Glitch, this, origPtT, testPtT); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | /* Commented-out lines keep this in sync with correctEnds */ |
| 1413 | // FIXME: member pointers have fallen out of favor and can be replaced with |
| 1414 | // an alternative approach. |
| 1415 | // makes all span ends agree with the segment's spans that define them |
| 1416 | void SkCoincidentSpans::debugCorrectEnds(SkPathOpsDebug::GlitchLog* log) const { |
| 1417 | this->debugCorrectOneEnd(log, &SkCoincidentSpans::coinPtTStart, nullptr); |
| 1418 | this->debugCorrectOneEnd(log, &SkCoincidentSpans::coinPtTEnd, nullptr); |
| 1419 | this->debugCorrectOneEnd(log, &SkCoincidentSpans::oppPtTStart, nullptr); |
| 1420 | this->debugCorrectOneEnd(log, &SkCoincidentSpans::oppPtTEnd, nullptr); |
| 1421 | } |
| 1422 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1423 | /* Commented-out lines keep this in sync with expand */ |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1424 | // expand the range by checking adjacent spans for coincidence |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1425 | bool SkCoincidentSpans::debugExpand(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1426 | bool expanded = false; |
| 1427 | const SkOpSegment* segment = coinPtTStart()->segment(); |
| 1428 | const SkOpSegment* oppSegment = oppPtTStart()->segment(); |
| 1429 | do { |
| 1430 | const SkOpSpan* start = coinPtTStart()->span()->upCast(); |
| 1431 | const SkOpSpan* prev = start->prev(); |
| 1432 | const SkOpPtT* oppPtT; |
| 1433 | if (!prev || !(oppPtT = prev->contains(oppSegment))) { |
| 1434 | break; |
| 1435 | } |
| 1436 | double midT = (prev->t() + start->t()) / 2; |
| 1437 | if (!segment->isClose(midT, oppSegment)) { |
| 1438 | break; |
| 1439 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1440 | if (log) log->record(SkPathOpsDebug::kExpandCoin_Glitch, this, prev->ptT(), oppPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1441 | expanded = true; |
| 1442 | } while (false); // actual continues while expansion is possible |
| 1443 | do { |
| 1444 | const SkOpSpanBase* end = coinPtTEnd()->span(); |
| 1445 | SkOpSpanBase* next = end->final() ? nullptr : end->upCast()->next(); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1446 | if (next && next->deleted()) { |
| 1447 | break; |
| 1448 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1449 | const SkOpPtT* oppPtT; |
| 1450 | if (!next || !(oppPtT = next->contains(oppSegment))) { |
| 1451 | break; |
| 1452 | } |
| 1453 | double midT = (end->t() + next->t()) / 2; |
| 1454 | if (!segment->isClose(midT, oppSegment)) { |
| 1455 | break; |
| 1456 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1457 | if (log) log->record(SkPathOpsDebug::kExpandCoin_Glitch, this, next->ptT(), oppPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1458 | expanded = true; |
| 1459 | } while (false); // actual continues while expansion is possible |
| 1460 | return expanded; |
| 1461 | } |
| 1462 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1463 | // description below |
| 1464 | void SkOpCoincidence::debugAddEndMovedSpans(SkPathOpsDebug::GlitchLog* log, const SkOpSpan* base, const SkOpSpanBase* testSpan) const { |
| 1465 | const SkOpPtT* testPtT = testSpan->ptT(); |
| 1466 | const SkOpPtT* stopPtT = testPtT; |
| 1467 | const SkOpSegment* baseSeg = base->segment(); |
| 1468 | while ((testPtT = testPtT->next()) != stopPtT) { |
| 1469 | const SkOpSegment* testSeg = testPtT->segment(); |
| 1470 | if (testPtT->deleted()) { |
| 1471 | continue; |
| 1472 | } |
| 1473 | if (testSeg == baseSeg) { |
| 1474 | continue; |
| 1475 | } |
| 1476 | if (testPtT->span()->ptT() != testPtT) { |
| 1477 | continue; |
| 1478 | } |
| 1479 | if (this->contains(baseSeg, testSeg, testPtT->fT)) { |
| 1480 | continue; |
| 1481 | } |
| 1482 | // intersect perp with base->ptT() with testPtT->segment() |
| 1483 | SkDVector dxdy = baseSeg->dSlopeAtT(base->t()); |
| 1484 | const SkPoint& pt = base->pt(); |
| 1485 | SkDLine ray = {{{pt.fX, pt.fY}, {pt.fX + dxdy.fY, pt.fY - dxdy.fX}}}; |
| 1486 | SkIntersections i; |
| 1487 | (*CurveIntersectRay[testSeg->verb()])(testSeg->pts(), testSeg->weight(), ray, &i); |
| 1488 | for (int index = 0; index < i.used(); ++index) { |
| 1489 | double t = i[0][index]; |
| 1490 | if (!between(0, t, 1)) { |
| 1491 | continue; |
| 1492 | } |
| 1493 | SkDPoint oppPt = i.pt(index); |
| 1494 | if (!oppPt.approximatelyEqual(pt)) { |
| 1495 | continue; |
| 1496 | } |
| 1497 | SkOpSegment* writableSeg = const_cast<SkOpSegment*>(testSeg); |
| 1498 | SkOpPtT* oppStart = writableSeg->addT(t); |
| 1499 | if (oppStart == testPtT) { |
| 1500 | continue; |
| 1501 | } |
| 1502 | SkOpSpan* writableBase = const_cast<SkOpSpan*>(base); |
| 1503 | oppStart->span()->addOpp(writableBase); |
| 1504 | if (oppStart->deleted()) { |
| 1505 | continue; |
| 1506 | } |
| 1507 | SkOpSegment* coinSeg = base->segment(); |
| 1508 | SkOpSegment* oppSeg = oppStart->segment(); |
| 1509 | double coinTs, coinTe, oppTs, oppTe; |
| 1510 | if (Ordered(coinSeg, oppSeg)) { |
| 1511 | coinTs = base->t(); |
| 1512 | coinTe = testSpan->t(); |
| 1513 | oppTs = oppStart->fT; |
| 1514 | oppTe = testPtT->fT; |
| 1515 | } else { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1516 | using std::swap; |
| 1517 | swap(coinSeg, oppSeg); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1518 | coinTs = oppStart->fT; |
| 1519 | coinTe = testPtT->fT; |
| 1520 | oppTs = base->t(); |
| 1521 | oppTe = testSpan->t(); |
| 1522 | } |
| 1523 | if (coinTs > coinTe) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1524 | using std::swap; |
| 1525 | swap(coinTs, coinTe); |
| 1526 | swap(oppTs, oppTe); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1527 | } |
| 1528 | bool added; |
| 1529 | if (this->debugAddOrOverlap(log, coinSeg, oppSeg, coinTs, coinTe, oppTs, oppTe, &added), false) { |
| 1530 | return; |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | return; |
| 1535 | } |
| 1536 | |
| 1537 | // description below |
| 1538 | void SkOpCoincidence::debugAddEndMovedSpans(SkPathOpsDebug::GlitchLog* log, const SkOpPtT* ptT) const { |
| 1539 | FAIL_IF(!ptT->span()->upCastable(), ptT->span()); |
| 1540 | const SkOpSpan* base = ptT->span()->upCast(); |
| 1541 | const SkOpSpan* prev = base->prev(); |
| 1542 | FAIL_IF(!prev, ptT->span()); |
| 1543 | if (!prev->isCanceled()) { |
| 1544 | if (this->debugAddEndMovedSpans(log, base, base->prev()), false) { |
| 1545 | return; |
| 1546 | } |
| 1547 | } |
| 1548 | if (!base->isCanceled()) { |
| 1549 | if (this->debugAddEndMovedSpans(log, base, base->next()), false) { |
| 1550 | return; |
| 1551 | } |
| 1552 | } |
| 1553 | return; |
| 1554 | } |
| 1555 | |
| 1556 | /* If A is coincident with B and B includes an endpoint, and A's matching point |
| 1557 | is not the endpoint (i.e., there's an implied line connecting B-end and A) |
| 1558 | then assume that the same implied line may intersect another curve close to B. |
| 1559 | Since we only care about coincidence that was undetected, look at the |
| 1560 | ptT list on B-segment adjacent to the B-end/A ptT loop (not in the loop, but |
| 1561 | next door) and see if the A matching point is close enough to form another |
| 1562 | coincident pair. If so, check for a new coincident span between B-end/A ptT loop |
| 1563 | and the adjacent ptT loop. |
| 1564 | */ |
| 1565 | void SkOpCoincidence::debugAddEndMovedSpans(SkPathOpsDebug::GlitchLog* log) const { |
| 1566 | const SkCoincidentSpans* span = fHead; |
| 1567 | if (!span) { |
| 1568 | return; |
| 1569 | } |
| 1570 | // fTop = span; |
| 1571 | // fHead = nullptr; |
| 1572 | do { |
| 1573 | if (span->coinPtTStart()->fPt != span->oppPtTStart()->fPt) { |
| 1574 | FAIL_IF(1 == span->coinPtTStart()->fT, span); |
| 1575 | bool onEnd = span->coinPtTStart()->fT == 0; |
| 1576 | bool oOnEnd = zero_or_one(span->oppPtTStart()->fT); |
| 1577 | if (onEnd) { |
| 1578 | if (!oOnEnd) { // if both are on end, any nearby intersect was already found |
| 1579 | if (this->debugAddEndMovedSpans(log, span->oppPtTStart()), false) { |
| 1580 | return; |
| 1581 | } |
| 1582 | } |
| 1583 | } else if (oOnEnd) { |
| 1584 | if (this->debugAddEndMovedSpans(log, span->coinPtTStart()), false) { |
| 1585 | return; |
| 1586 | } |
| 1587 | } |
| 1588 | } |
| 1589 | if (span->coinPtTEnd()->fPt != span->oppPtTEnd()->fPt) { |
| 1590 | bool onEnd = span->coinPtTEnd()->fT == 1; |
| 1591 | bool oOnEnd = zero_or_one(span->oppPtTEnd()->fT); |
| 1592 | if (onEnd) { |
| 1593 | if (!oOnEnd) { |
| 1594 | if (this->debugAddEndMovedSpans(log, span->oppPtTEnd()), false) { |
| 1595 | return; |
| 1596 | } |
| 1597 | } |
| 1598 | } else if (oOnEnd) { |
| 1599 | if (this->debugAddEndMovedSpans(log, span->coinPtTEnd()), false) { |
| 1600 | return; |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | } while ((span = span->next())); |
| 1605 | // this->restoreHead(); |
| 1606 | return; |
| 1607 | } |
| 1608 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1609 | /* Commented-out lines keep this in sync with addExpanded */ |
| 1610 | // for each coincident pair, match the spans |
| 1611 | // if the spans don't match, add the mssing pt to the segment and loop it in the opposite span |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1612 | void SkOpCoincidence::debugAddExpanded(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 1613 | // DEBUG_SET_PHASE(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1614 | const SkCoincidentSpans* coin = this->fHead; |
| 1615 | if (!coin) { |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 1616 | return; |
| 1617 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1618 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1619 | const SkOpPtT* startPtT = coin->coinPtTStart(); |
| 1620 | const SkOpPtT* oStartPtT = coin->oppPtTStart(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1621 | double priorT = startPtT->fT; |
| 1622 | double oPriorT = oStartPtT->fT; |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 1623 | FAIL_IF(!startPtT->contains(oStartPtT), coin); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1624 | SkOPASSERT(coin->coinPtTEnd()->contains(coin->oppPtTEnd())); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1625 | const SkOpSpanBase* start = startPtT->span(); |
| 1626 | const SkOpSpanBase* oStart = oStartPtT->span(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1627 | const SkOpSpanBase* end = coin->coinPtTEnd()->span(); |
| 1628 | const SkOpSpanBase* oEnd = coin->oppPtTEnd()->span(); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1629 | FAIL_IF(oEnd->deleted(), coin); |
| 1630 | FAIL_IF(!start->upCastable(), coin); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1631 | const SkOpSpanBase* test = start->upCast()->next(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1632 | FAIL_IF(!coin->flipped() && !oStart->upCastable(), coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1633 | const SkOpSpanBase* oTest = coin->flipped() ? oStart->prev() : oStart->upCast()->next(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1634 | FAIL_IF(!oTest, coin); |
| 1635 | const SkOpSegment* seg = start->segment(); |
| 1636 | const SkOpSegment* oSeg = oStart->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1637 | while (test != end || oTest != oEnd) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1638 | const SkOpPtT* containedOpp = test->ptT()->contains(oSeg); |
| 1639 | const SkOpPtT* containedThis = oTest->ptT()->contains(seg); |
| 1640 | if (!containedOpp || !containedThis) { |
| 1641 | // choose the ends, or the first common pt-t list shared by both |
| 1642 | double nextT, oNextT; |
| 1643 | if (containedOpp) { |
| 1644 | nextT = test->t(); |
| 1645 | oNextT = containedOpp->fT; |
| 1646 | } else if (containedThis) { |
| 1647 | nextT = containedThis->fT; |
| 1648 | oNextT = oTest->t(); |
| 1649 | } else { |
| 1650 | // iterate through until a pt-t list found that contains the other |
| 1651 | const SkOpSpanBase* walk = test; |
| 1652 | const SkOpPtT* walkOpp; |
| 1653 | do { |
| 1654 | FAIL_IF(!walk->upCastable(), coin); |
| 1655 | walk = walk->upCast()->next(); |
| 1656 | } while (!(walkOpp = walk->ptT()->contains(oSeg)) |
| 1657 | && walk != coin->coinPtTEnd()->span()); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 1658 | FAIL_IF(!walkOpp, coin); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1659 | nextT = walk->t(); |
| 1660 | oNextT = walkOpp->fT; |
| 1661 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1662 | // use t ranges to guess which one is missing |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 1663 | double startRange = nextT - priorT; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1664 | FAIL_IF(!startRange, coin); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 1665 | double startPart = (test->t() - priorT) / startRange; |
| 1666 | double oStartRange = oNextT - oPriorT; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1667 | FAIL_IF(!oStartRange, coin); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1668 | double oStartPart = (oTest->t() - oStartPtT->fT) / oStartRange; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1669 | FAIL_IF(startPart == oStartPart, coin); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1670 | bool addToOpp = !containedOpp && !containedThis ? startPart < oStartPart |
| 1671 | : !!containedThis; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1672 | bool startOver = false; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1673 | addToOpp ? log->record(SkPathOpsDebug::kAddExpandedCoin_Glitch, |
| 1674 | oPriorT + oStartRange * startPart, test) |
| 1675 | : log->record(SkPathOpsDebug::kAddExpandedCoin_Glitch, |
| 1676 | priorT + startRange * oStartPart, oTest); |
| 1677 | // FAIL_IF(!success, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1678 | if (startOver) { |
| 1679 | test = start; |
| 1680 | oTest = oStart; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1681 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1682 | end = coin->coinPtTEnd()->span(); |
| 1683 | oEnd = coin->oppPtTEnd()->span(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1684 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1685 | if (test != end) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1686 | FAIL_IF(!test->upCastable(), coin); |
| 1687 | priorT = test->t(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1688 | test = test->upCast()->next(); |
| 1689 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1690 | if (oTest != oEnd) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1691 | oPriorT = oTest->t(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1692 | oTest = coin->flipped() ? oTest->prev() : oTest->upCast()->next(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1693 | FAIL_IF(!oTest, coin); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1694 | } |
| 1695 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1696 | } while ((coin = coin->next())); |
| 1697 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1700 | /* Commented-out lines keep this in sync addIfMissing() */ |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1701 | // note that over1s, over1e, over2s, over2e are ordered |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1702 | void SkOpCoincidence::debugAddIfMissing(SkPathOpsDebug::GlitchLog* log, const SkOpPtT* over1s, const SkOpPtT* over2s, |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1703 | double tStart, double tEnd, const SkOpSegment* coinSeg, const SkOpSegment* oppSeg, bool* added, |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1704 | const SkOpPtT* over1e, const SkOpPtT* over2e) const { |
| 1705 | SkASSERT(tStart < tEnd); |
| 1706 | SkASSERT(over1s->fT < over1e->fT); |
| 1707 | SkASSERT(between(over1s->fT, tStart, over1e->fT)); |
| 1708 | SkASSERT(between(over1s->fT, tEnd, over1e->fT)); |
| 1709 | SkASSERT(over2s->fT < over2e->fT); |
| 1710 | SkASSERT(between(over2s->fT, tStart, over2e->fT)); |
| 1711 | SkASSERT(between(over2s->fT, tEnd, over2e->fT)); |
| 1712 | SkASSERT(over1s->segment() == over1e->segment()); |
| 1713 | SkASSERT(over2s->segment() == over2e->segment()); |
| 1714 | SkASSERT(over1s->segment() == over2s->segment()); |
| 1715 | SkASSERT(over1s->segment() != coinSeg); |
| 1716 | SkASSERT(over1s->segment() != oppSeg); |
| 1717 | SkASSERT(coinSeg != oppSeg); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1718 | double coinTs, coinTe, oppTs, oppTe; |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1719 | coinTs = TRange(over1s, tStart, coinSeg SkDEBUGPARAMS(over1e)); |
| 1720 | coinTe = TRange(over1s, tEnd, coinSeg SkDEBUGPARAMS(over1e)); |
Cary Clark | ba61029 | 2018-06-19 09:47:15 -0400 | [diff] [blame] | 1721 | SkOpSpanBase::Collapsed result = coinSeg->collapsed(coinTs, coinTe); |
| 1722 | if (SkOpSpanBase::Collapsed::kNo != result) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1723 | return log->record(SkPathOpsDebug::kAddIfCollapsed_Glitch, coinSeg); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1724 | } |
| 1725 | oppTs = TRange(over2s, tStart, oppSeg SkDEBUGPARAMS(over2e)); |
| 1726 | oppTe = TRange(over2s, tEnd, oppSeg SkDEBUGPARAMS(over2e)); |
Cary Clark | ba61029 | 2018-06-19 09:47:15 -0400 | [diff] [blame] | 1727 | result = oppSeg->collapsed(oppTs, oppTe); |
| 1728 | if (SkOpSpanBase::Collapsed::kNo != result) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1729 | return log->record(SkPathOpsDebug::kAddIfCollapsed_Glitch, oppSeg); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1730 | } |
| 1731 | if (coinTs > coinTe) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1732 | using std::swap; |
| 1733 | swap(coinTs, coinTe); |
| 1734 | swap(oppTs, oppTe); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1735 | } |
Cary Clark | ba61029 | 2018-06-19 09:47:15 -0400 | [diff] [blame] | 1736 | this->debugAddOrOverlap(log, coinSeg, oppSeg, coinTs, coinTe, oppTs, oppTe, added); |
| 1737 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1740 | /* Commented-out lines keep this in sync addOrOverlap() */ |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1741 | // If this is called by addEndMovedSpans(), a returned false propogates out to an abort. |
| 1742 | // If this is called by AddIfMissing(), a returned false indicates there was nothing to add |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1743 | void SkOpCoincidence::debugAddOrOverlap(SkPathOpsDebug::GlitchLog* log, |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1744 | const SkOpSegment* coinSeg, const SkOpSegment* oppSeg, |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1745 | double coinTs, double coinTe, double oppTs, double oppTe, bool* added) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1746 | SkTDArray<SkCoincidentSpans*> overlaps; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1747 | SkOPASSERT(!fTop); // this is (correctly) reversed in addifMissing() |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1748 | if (fTop && !this->checkOverlap(fTop, coinSeg, oppSeg, coinTs, coinTe, oppTs, oppTe, |
| 1749 | &overlaps)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1750 | return; |
| 1751 | } |
| 1752 | if (fHead && !this->checkOverlap(fHead, coinSeg, oppSeg, coinTs, |
| 1753 | coinTe, oppTs, oppTe, &overlaps)) { |
| 1754 | return; |
| 1755 | } |
| 1756 | const SkCoincidentSpans* overlap = overlaps.count() ? overlaps[0] : nullptr; |
| 1757 | for (int index = 1; index < overlaps.count(); ++index) { // combine overlaps before continuing |
| 1758 | const SkCoincidentSpans* test = overlaps[index]; |
| 1759 | if (overlap->coinPtTStart()->fT > test->coinPtTStart()->fT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1760 | log->record(SkPathOpsDebug::kAddOrOverlap_Glitch, overlap, test->coinPtTStart()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1761 | } |
| 1762 | if (overlap->coinPtTEnd()->fT < test->coinPtTEnd()->fT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1763 | log->record(SkPathOpsDebug::kAddOrOverlap_Glitch, overlap, test->coinPtTEnd()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1764 | } |
| 1765 | if (overlap->flipped() |
| 1766 | ? overlap->oppPtTStart()->fT < test->oppPtTStart()->fT |
| 1767 | : overlap->oppPtTStart()->fT > test->oppPtTStart()->fT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1768 | log->record(SkPathOpsDebug::kAddOrOverlap_Glitch, overlap, test->oppPtTStart()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1769 | } |
| 1770 | if (overlap->flipped() |
| 1771 | ? overlap->oppPtTEnd()->fT > test->oppPtTEnd()->fT |
| 1772 | : overlap->oppPtTEnd()->fT < test->oppPtTEnd()->fT) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1773 | log->record(SkPathOpsDebug::kAddOrOverlap_Glitch, overlap, test->oppPtTEnd()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1774 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1775 | if (!fHead) { this->debugRelease(log, fHead, test); |
| 1776 | this->debugRelease(log, fTop, test); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | const SkOpPtT* cs = coinSeg->existing(coinTs, oppSeg); |
| 1780 | const SkOpPtT* ce = coinSeg->existing(coinTe, oppSeg); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1781 | RETURN_FALSE_IF(overlap && cs && ce && overlap->contains(cs, ce), coinSeg); |
| 1782 | RETURN_FALSE_IF(cs != ce || !cs, coinSeg); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1783 | const SkOpPtT* os = oppSeg->existing(oppTs, coinSeg); |
| 1784 | const SkOpPtT* oe = oppSeg->existing(oppTe, coinSeg); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1785 | RETURN_FALSE_IF(overlap && os && oe && overlap->contains(os, oe), oppSeg); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1786 | SkASSERT(true || !cs || !cs->deleted()); |
| 1787 | SkASSERT(true || !os || !os->deleted()); |
| 1788 | SkASSERT(true || !ce || !ce->deleted()); |
| 1789 | SkASSERT(true || !oe || !oe->deleted()); |
| 1790 | const SkOpPtT* csExisting = !cs ? coinSeg->existing(coinTs, nullptr) : nullptr; |
| 1791 | const SkOpPtT* ceExisting = !ce ? coinSeg->existing(coinTe, nullptr) : nullptr; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1792 | RETURN_FALSE_IF(csExisting && csExisting == ceExisting, coinSeg); |
| 1793 | RETURN_FALSE_IF(csExisting && (csExisting == ce || |
| 1794 | csExisting->contains(ceExisting ? ceExisting : ce)), coinSeg); |
| 1795 | RETURN_FALSE_IF(ceExisting && (ceExisting == cs || |
| 1796 | ceExisting->contains(csExisting ? csExisting : cs)), coinSeg); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1797 | const SkOpPtT* osExisting = !os ? oppSeg->existing(oppTs, nullptr) : nullptr; |
| 1798 | const SkOpPtT* oeExisting = !oe ? oppSeg->existing(oppTe, nullptr) : nullptr; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1799 | RETURN_FALSE_IF(osExisting && osExisting == oeExisting, oppSeg); |
| 1800 | RETURN_FALSE_IF(osExisting && (osExisting == oe || |
| 1801 | osExisting->contains(oeExisting ? oeExisting : oe)), oppSeg); |
| 1802 | RETURN_FALSE_IF(oeExisting && (oeExisting == os || |
| 1803 | oeExisting->contains(osExisting ? osExisting : os)), oppSeg); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1804 | bool csDeleted = false, osDeleted = false, ceDeleted = false, oeDeleted = false; |
| 1805 | this->debugValidate(); |
| 1806 | if (!cs || !os) { |
| 1807 | if (!cs) |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1808 | cs = coinSeg->debugAddT(coinTs, log); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1809 | if (!os) |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1810 | os = oppSeg->debugAddT(oppTs, log); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1811 | // RETURN_FALSE_IF(callerAborts, !csWritable || !osWritable); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1812 | if (cs && os) cs->span()->debugAddOpp(log, os->span()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1813 | // cs = csWritable; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1814 | // os = osWritable->active(); |
| 1815 | RETURN_FALSE_IF((ce && ce->deleted()) || (oe && oe->deleted()), coinSeg); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1816 | } |
| 1817 | if (!ce || !oe) { |
| 1818 | if (!ce) |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1819 | ce = coinSeg->debugAddT(coinTe, log); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1820 | if (!oe) |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1821 | oe = oppSeg->debugAddT(oppTe, log); |
| 1822 | if (ce && oe) ce->span()->debugAddOpp(log, oe->span()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1823 | // ce = ceWritable; |
| 1824 | // oe = oeWritable; |
| 1825 | } |
| 1826 | this->debugValidate(); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1827 | RETURN_FALSE_IF(csDeleted, coinSeg); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 1828 | RETURN_FALSE_IF(osDeleted, oppSeg); |
| 1829 | RETURN_FALSE_IF(ceDeleted, coinSeg); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1830 | RETURN_FALSE_IF(oeDeleted, oppSeg); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1831 | RETURN_FALSE_IF(!cs || !ce || cs == ce || cs->contains(ce) || !os || !oe || os == oe || os->contains(oe), coinSeg); |
| 1832 | bool result = true; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1833 | if (overlap) { |
| 1834 | if (overlap->coinPtTStart()->segment() == coinSeg) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1835 | log->record(SkPathOpsDebug::kAddMissingExtend_Glitch, coinSeg, coinTs, coinTe, oppSeg, oppTs, oppTe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1836 | } else { |
| 1837 | if (oppTs > oppTe) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 1838 | using std::swap; |
| 1839 | swap(coinTs, coinTe); |
| 1840 | swap(oppTs, oppTe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1841 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1842 | log->record(SkPathOpsDebug::kAddMissingExtend_Glitch, oppSeg, oppTs, oppTe, coinSeg, coinTs, coinTe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1843 | } |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1844 | #if 0 && DEBUG_COINCIDENCE_VERBOSE |
| 1845 | if (result) { |
| 1846 | overlap->debugShow(); |
| 1847 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1848 | #endif |
| 1849 | } else { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1850 | log->record(SkPathOpsDebug::kAddMissingCoin_Glitch, coinSeg, coinTs, coinTe, oppSeg, oppTs, oppTe); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1851 | #if 0 && DEBUG_COINCIDENCE_VERBOSE |
| 1852 | fHead->debugShow(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1853 | #endif |
| 1854 | } |
| 1855 | this->debugValidate(); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1856 | return (void) result; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | // Extra commented-out lines keep this in sync with addMissing() |
| 1860 | /* detects overlaps of different coincident runs on same segment */ |
| 1861 | /* does not detect overlaps for pairs without any segments in common */ |
| 1862 | // returns true if caller should loop again |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1863 | void SkOpCoincidence::debugAddMissing(SkPathOpsDebug::GlitchLog* log, bool* added) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1864 | const SkCoincidentSpans* outer = fHead; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1865 | *added = false; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1866 | if (!outer) { |
| 1867 | return; |
| 1868 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1869 | // fTop = outer; |
| 1870 | // fHead = nullptr; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1871 | do { |
| 1872 | // addifmissing can modify the list that this is walking |
| 1873 | // save head so that walker can iterate over old data unperturbed |
| 1874 | // addifmissing adds to head freely then add saved head in the end |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1875 | const SkOpPtT* ocs = outer->coinPtTStart(); |
| 1876 | SkASSERT(!ocs->deleted()); |
| 1877 | const SkOpSegment* outerCoin = ocs->segment(); |
| 1878 | SkASSERT(!outerCoin->done()); // if it's done, should have already been removed from list |
| 1879 | const SkOpPtT* oos = outer->oppPtTStart(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1880 | if (oos->deleted()) { |
| 1881 | return; |
| 1882 | } |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1883 | const SkOpSegment* outerOpp = oos->segment(); |
| 1884 | SkASSERT(!outerOpp->done()); |
| 1885 | // SkOpSegment* outerCoinWritable = const_cast<SkOpSegment*>(outerCoin); |
| 1886 | // SkOpSegment* outerOppWritable = const_cast<SkOpSegment*>(outerOpp); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1887 | const SkCoincidentSpans* inner = outer; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1888 | while ((inner = inner->next())) { |
| 1889 | this->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1890 | double overS, overE; |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1891 | const SkOpPtT* ics = inner->coinPtTStart(); |
| 1892 | SkASSERT(!ics->deleted()); |
| 1893 | const SkOpSegment* innerCoin = ics->segment(); |
| 1894 | SkASSERT(!innerCoin->done()); |
| 1895 | const SkOpPtT* ios = inner->oppPtTStart(); |
| 1896 | SkASSERT(!ios->deleted()); |
| 1897 | const SkOpSegment* innerOpp = ios->segment(); |
| 1898 | SkASSERT(!innerOpp->done()); |
| 1899 | // SkOpSegment* innerCoinWritable = const_cast<SkOpSegment*>(innerCoin); |
| 1900 | // SkOpSegment* innerOppWritable = const_cast<SkOpSegment*>(innerOpp); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1901 | if (outerCoin == innerCoin) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1902 | const SkOpPtT* oce = outer->coinPtTEnd(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1903 | if (oce->deleted()) { |
| 1904 | return; |
| 1905 | } |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1906 | const SkOpPtT* ice = inner->coinPtTEnd(); |
| 1907 | SkASSERT(!ice->deleted()); |
| 1908 | if (outerOpp != innerOpp && this->overlap(ocs, oce, ics, ice, &overS, &overE)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1909 | this->debugAddIfMissing(log, ocs->starter(oce), ics->starter(ice), |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1910 | overS, overE, outerOpp, innerOpp, added, |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1911 | ocs->debugEnder(oce), |
| 1912 | ics->debugEnder(ice)); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1913 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1914 | } else if (outerCoin == innerOpp) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1915 | const SkOpPtT* oce = outer->coinPtTEnd(); |
| 1916 | SkASSERT(!oce->deleted()); |
| 1917 | const SkOpPtT* ioe = inner->oppPtTEnd(); |
| 1918 | SkASSERT(!ioe->deleted()); |
| 1919 | if (outerOpp != innerCoin && this->overlap(ocs, oce, ios, ioe, &overS, &overE)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1920 | this->debugAddIfMissing(log, ocs->starter(oce), ios->starter(ioe), |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1921 | overS, overE, outerOpp, innerCoin, added, |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1922 | ocs->debugEnder(oce), |
| 1923 | ios->debugEnder(ioe)); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1924 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1925 | } else if (outerOpp == innerCoin) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1926 | const SkOpPtT* ooe = outer->oppPtTEnd(); |
| 1927 | SkASSERT(!ooe->deleted()); |
| 1928 | const SkOpPtT* ice = inner->coinPtTEnd(); |
| 1929 | SkASSERT(!ice->deleted()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1930 | SkASSERT(outerCoin != innerOpp); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1931 | if (this->overlap(oos, ooe, ics, ice, &overS, &overE)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1932 | this->debugAddIfMissing(log, oos->starter(ooe), ics->starter(ice), |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1933 | overS, overE, outerCoin, innerOpp, added, |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1934 | oos->debugEnder(ooe), |
| 1935 | ics->debugEnder(ice)); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1936 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1937 | } else if (outerOpp == innerOpp) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1938 | const SkOpPtT* ooe = outer->oppPtTEnd(); |
| 1939 | SkASSERT(!ooe->deleted()); |
| 1940 | const SkOpPtT* ioe = inner->oppPtTEnd(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1941 | if (ioe->deleted()) { |
| 1942 | return; |
| 1943 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1944 | SkASSERT(outerCoin != innerCoin); |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1945 | if (this->overlap(oos, ooe, ios, ioe, &overS, &overE)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1946 | this->debugAddIfMissing(log, oos->starter(ooe), ios->starter(ioe), |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 1947 | overS, overE, outerCoin, innerCoin, added, |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 1948 | oos->debugEnder(ooe), |
| 1949 | ios->debugEnder(ioe)); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1950 | } |
| 1951 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1952 | this->debugValidate(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1953 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1954 | } while ((outer = outer->next())); |
| 1955 | // this->restoreHead(); |
| 1956 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1959 | // Commented-out lines keep this in sync with release() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1960 | void SkOpCoincidence::debugRelease(SkPathOpsDebug::GlitchLog* log, const SkCoincidentSpans* coin, const SkCoincidentSpans* remove) const { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1961 | const SkCoincidentSpans* head = coin; |
| 1962 | const SkCoincidentSpans* prev = nullptr; |
| 1963 | const SkCoincidentSpans* next; |
| 1964 | do { |
| 1965 | next = coin->next(); |
| 1966 | if (coin == remove) { |
| 1967 | if (prev) { |
| 1968 | // prev->setNext(next); |
| 1969 | } else if (head == fHead) { |
| 1970 | // fHead = next; |
| 1971 | } else { |
| 1972 | // fTop = next; |
| 1973 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1974 | log->record(SkPathOpsDebug::kReleasedSpan_Glitch, coin); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1975 | } |
| 1976 | prev = coin; |
| 1977 | } while ((coin = next)); |
| 1978 | return; |
| 1979 | } |
| 1980 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1981 | void SkOpCoincidence::debugRelease(SkPathOpsDebug::GlitchLog* log, const SkOpSegment* deleted) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1982 | const SkCoincidentSpans* coin = fHead; |
| 1983 | if (!coin) { |
| 1984 | return; |
| 1985 | } |
| 1986 | do { |
| 1987 | if (coin->coinPtTStart()->segment() == deleted |
| 1988 | || coin->coinPtTEnd()->segment() == deleted |
| 1989 | || coin->oppPtTStart()->segment() == deleted |
| 1990 | || coin->oppPtTEnd()->segment() == deleted) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1991 | log->record(SkPathOpsDebug::kReleasedSpan_Glitch, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1992 | } |
| 1993 | } while ((coin = coin->next())); |
| 1994 | } |
| 1995 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1996 | // Commented-out lines keep this in sync with expand() |
| 1997 | // expand the range by checking adjacent spans for coincidence |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 1998 | bool SkOpCoincidence::debugExpand(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1999 | const SkCoincidentSpans* coin = fHead; |
| 2000 | if (!coin) { |
| 2001 | return false; |
| 2002 | } |
| 2003 | bool expanded = false; |
| 2004 | do { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2005 | if (coin->debugExpand(log)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2006 | // check to see if multiple spans expanded so they are now identical |
| 2007 | const SkCoincidentSpans* test = fHead; |
| 2008 | do { |
| 2009 | if (coin == test) { |
| 2010 | continue; |
| 2011 | } |
| 2012 | if (coin->coinPtTStart() == test->coinPtTStart() |
| 2013 | && coin->oppPtTStart() == test->oppPtTStart()) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2014 | if (log) log->record(SkPathOpsDebug::kExpandCoin_Glitch, fHead, test->coinPtTStart()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2015 | break; |
| 2016 | } |
| 2017 | } while ((test = test->next())); |
| 2018 | expanded = true; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2019 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2020 | } while ((coin = coin->next())); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2021 | return expanded; |
| 2022 | } |
| 2023 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2024 | // Commented-out lines keep this in sync with mark() |
| 2025 | /* this sets up the coincidence links in the segments when the coincidence crosses multiple spans */ |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2026 | void SkOpCoincidence::debugMark(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2027 | const SkCoincidentSpans* coin = fHead; |
| 2028 | if (!coin) { |
| 2029 | return; |
| 2030 | } |
| 2031 | do { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2032 | FAIL_IF(!coin->coinPtTStartWritable()->span()->upCastable(), coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2033 | const SkOpSpan* start = coin->coinPtTStartWritable()->span()->upCast(); |
| 2034 | // SkASSERT(start->deleted()); |
| 2035 | const SkOpSpanBase* end = coin->coinPtTEndWritable()->span(); |
| 2036 | // SkASSERT(end->deleted()); |
| 2037 | const SkOpSpanBase* oStart = coin->oppPtTStartWritable()->span(); |
| 2038 | // SkASSERT(oStart->deleted()); |
| 2039 | const SkOpSpanBase* oEnd = coin->oppPtTEndWritable()->span(); |
| 2040 | // SkASSERT(oEnd->deleted()); |
| 2041 | bool flipped = coin->flipped(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2042 | if (flipped) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 2043 | using std::swap; |
| 2044 | swap(oStart, oEnd); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2045 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2046 | /* coin and opp spans may not match up. Mark the ends, and then let the interior |
| 2047 | get marked as many times as the spans allow */ |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2048 | start->debugInsertCoincidence(log, oStart->upCast()); |
| 2049 | end->debugInsertCoinEnd(log, oEnd); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2050 | const SkOpSegment* segment = start->segment(); |
| 2051 | const SkOpSegment* oSegment = oStart->segment(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2052 | const SkOpSpanBase* next = start; |
| 2053 | const SkOpSpanBase* oNext = oStart; |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 2054 | bool ordered; |
| 2055 | FAIL_IF(!coin->ordered(&ordered), coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2056 | while ((next = next->upCast()->next()) != end) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2057 | FAIL_IF(!next->upCastable(), coin); |
| 2058 | if (next->upCast()->debugInsertCoincidence(log, oSegment, flipped, ordered), false) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2059 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2060 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2061 | } |
| 2062 | while ((oNext = oNext->upCast()->next()) != oEnd) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2063 | FAIL_IF(!oNext->upCastable(), coin); |
| 2064 | if (oNext->upCast()->debugInsertCoincidence(log, segment, flipped, ordered), false) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2065 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2066 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2067 | } |
| 2068 | } while ((coin = coin->next())); |
| 2069 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2070 | } |
| 2071 | #endif |
| 2072 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2073 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2074 | // Commented-out lines keep this in sync with markCollapsed() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2075 | void SkOpCoincidence::debugMarkCollapsed(SkPathOpsDebug::GlitchLog* log, const SkCoincidentSpans* coin, const SkOpPtT* test) const { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2076 | const SkCoincidentSpans* head = coin; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2077 | while (coin) { |
| 2078 | if (coin->collapsed(test)) { |
| 2079 | if (zero_or_one(coin->coinPtTStart()->fT) && zero_or_one(coin->coinPtTEnd()->fT)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2080 | log->record(SkPathOpsDebug::kCollapsedCoin_Glitch, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2081 | } |
| 2082 | if (zero_or_one(coin->oppPtTStart()->fT) && zero_or_one(coin->oppPtTEnd()->fT)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2083 | log->record(SkPathOpsDebug::kCollapsedCoin_Glitch, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2084 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2085 | this->debugRelease(log, head, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2086 | } |
| 2087 | coin = coin->next(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2091 | // Commented-out lines keep this in sync with markCollapsed() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2092 | void SkOpCoincidence::debugMarkCollapsed(SkPathOpsDebug::GlitchLog* log, const SkOpPtT* test) const { |
| 2093 | this->debugMarkCollapsed(log, fHead, test); |
| 2094 | this->debugMarkCollapsed(log, fTop, test); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2095 | } |
| 2096 | #endif |
| 2097 | |
| 2098 | void SkCoincidentSpans::debugShow() const { |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2099 | SkDebugf("coinSpan - id=%d t=%1.9g tEnd=%1.9g\n", coinPtTStart()->segment()->debugID(), |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2100 | coinPtTStart()->fT, coinPtTEnd()->fT); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2101 | SkDebugf("coinSpan + id=%d t=%1.9g tEnd=%1.9g\n", oppPtTStart()->segment()->debugID(), |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2102 | oppPtTStart()->fT, oppPtTEnd()->fT); |
| 2103 | } |
| 2104 | |
| 2105 | void SkOpCoincidence::debugShowCoincidence() const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2106 | #if DEBUG_COINCIDENCE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2107 | const SkCoincidentSpans* span = fHead; |
| 2108 | while (span) { |
| 2109 | span->debugShow(); |
| 2110 | span = span->next(); |
| 2111 | } |
| 2112 | #endif |
| 2113 | } |
| 2114 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2115 | #if DEBUG_COIN |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2116 | static void DebugCheckBetween(const SkOpSpanBase* next, const SkOpSpanBase* end, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2117 | double oStart, double oEnd, const SkOpSegment* oSegment, |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2118 | SkPathOpsDebug::GlitchLog* log) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2119 | SkASSERT(next != end); |
| 2120 | SkASSERT(!next->contains(end) || log); |
| 2121 | if (next->t() > end->t()) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 2122 | using std::swap; |
| 2123 | swap(next, end); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2124 | } |
| 2125 | do { |
| 2126 | const SkOpPtT* ptT = next->ptT(); |
| 2127 | int index = 0; |
caryclark | 27c015d | 2016-09-23 05:47:20 -0700 | [diff] [blame] | 2128 | bool somethingBetween = false; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2129 | do { |
| 2130 | ++index; |
| 2131 | ptT = ptT->next(); |
| 2132 | const SkOpPtT* checkPtT = next->ptT(); |
| 2133 | if (ptT == checkPtT) { |
| 2134 | break; |
| 2135 | } |
| 2136 | bool looped = false; |
| 2137 | for (int check = 0; check < index; ++check) { |
| 2138 | if ((looped = checkPtT == ptT)) { |
| 2139 | break; |
| 2140 | } |
| 2141 | checkPtT = checkPtT->next(); |
| 2142 | } |
| 2143 | if (looped) { |
| 2144 | SkASSERT(0); |
| 2145 | break; |
| 2146 | } |
| 2147 | if (ptT->deleted()) { |
| 2148 | continue; |
| 2149 | } |
| 2150 | if (ptT->segment() != oSegment) { |
| 2151 | continue; |
| 2152 | } |
| 2153 | somethingBetween |= between(oStart, ptT->fT, oEnd); |
| 2154 | } while (true); |
| 2155 | SkASSERT(somethingBetween); |
| 2156 | } while (next != end && (next = next->upCast()->next())); |
| 2157 | } |
| 2158 | |
| 2159 | static void DebugCheckOverlap(const SkCoincidentSpans* test, const SkCoincidentSpans* list, |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2160 | SkPathOpsDebug::GlitchLog* log) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2161 | if (!list) { |
| 2162 | return; |
| 2163 | } |
| 2164 | const SkOpSegment* coinSeg = test->coinPtTStart()->segment(); |
| 2165 | SkASSERT(coinSeg == test->coinPtTEnd()->segment()); |
| 2166 | const SkOpSegment* oppSeg = test->oppPtTStart()->segment(); |
| 2167 | SkASSERT(oppSeg == test->oppPtTEnd()->segment()); |
| 2168 | SkASSERT(coinSeg != test->oppPtTStart()->segment()); |
| 2169 | SkDEBUGCODE(double tcs = test->coinPtTStart()->fT); |
| 2170 | SkASSERT(between(0, tcs, 1)); |
| 2171 | SkDEBUGCODE(double tce = test->coinPtTEnd()->fT); |
| 2172 | SkASSERT(between(0, tce, 1)); |
| 2173 | SkASSERT(tcs < tce); |
| 2174 | double tos = test->oppPtTStart()->fT; |
| 2175 | SkASSERT(between(0, tos, 1)); |
| 2176 | double toe = test->oppPtTEnd()->fT; |
| 2177 | SkASSERT(between(0, toe, 1)); |
| 2178 | SkASSERT(tos != toe); |
| 2179 | if (tos > toe) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 2180 | using std::swap; |
| 2181 | swap(tos, toe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2182 | } |
| 2183 | do { |
| 2184 | double lcs, lce, los, loe; |
| 2185 | if (coinSeg == list->coinPtTStart()->segment()) { |
| 2186 | if (oppSeg != list->oppPtTStart()->segment()) { |
| 2187 | continue; |
| 2188 | } |
| 2189 | lcs = list->coinPtTStart()->fT; |
| 2190 | lce = list->coinPtTEnd()->fT; |
| 2191 | los = list->oppPtTStart()->fT; |
| 2192 | loe = list->oppPtTEnd()->fT; |
| 2193 | if (los > loe) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 2194 | using std::swap; |
| 2195 | swap(los, loe); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2196 | } |
| 2197 | } else if (coinSeg == list->oppPtTStart()->segment()) { |
| 2198 | if (oppSeg != list->coinPtTStart()->segment()) { |
| 2199 | continue; |
| 2200 | } |
| 2201 | lcs = list->oppPtTStart()->fT; |
| 2202 | lce = list->oppPtTEnd()->fT; |
| 2203 | if (lcs > lce) { |
Ben Wagner | f08d1d0 | 2018-06-18 15:11:00 -0400 | [diff] [blame] | 2204 | using std::swap; |
| 2205 | swap(lcs, lce); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2206 | } |
| 2207 | los = list->coinPtTStart()->fT; |
| 2208 | loe = list->coinPtTEnd()->fT; |
| 2209 | } else { |
| 2210 | continue; |
| 2211 | } |
| 2212 | SkASSERT(tce < lcs || lce < tcs); |
| 2213 | SkASSERT(toe < los || loe < tos); |
| 2214 | } while ((list = list->next())); |
| 2215 | } |
| 2216 | |
| 2217 | |
| 2218 | static void DebugCheckOverlapTop(const SkCoincidentSpans* head, const SkCoincidentSpans* opt, |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2219 | SkPathOpsDebug::GlitchLog* log) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2220 | // check for overlapping coincident spans |
| 2221 | const SkCoincidentSpans* test = head; |
| 2222 | while (test) { |
| 2223 | const SkCoincidentSpans* next = test->next(); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2224 | DebugCheckOverlap(test, next, log); |
| 2225 | DebugCheckOverlap(test, opt, log); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2226 | test = next; |
| 2227 | } |
| 2228 | } |
| 2229 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2230 | static void DebugValidate(const SkCoincidentSpans* head, const SkCoincidentSpans* opt, |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2231 | SkPathOpsDebug::GlitchLog* log) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2232 | // look for pts inside coincident spans that are not inside the opposite spans |
| 2233 | const SkCoincidentSpans* coin = head; |
| 2234 | while (coin) { |
| 2235 | SkASSERT(SkOpCoincidence::Ordered(coin->coinPtTStart()->segment(), |
| 2236 | coin->oppPtTStart()->segment())); |
| 2237 | SkASSERT(coin->coinPtTStart()->span()->ptT() == coin->coinPtTStart()); |
| 2238 | SkASSERT(coin->coinPtTEnd()->span()->ptT() == coin->coinPtTEnd()); |
| 2239 | SkASSERT(coin->oppPtTStart()->span()->ptT() == coin->oppPtTStart()); |
| 2240 | SkASSERT(coin->oppPtTEnd()->span()->ptT() == coin->oppPtTEnd()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2241 | coin = coin->next(); |
| 2242 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2243 | DebugCheckOverlapTop(head, opt, log); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2244 | } |
| 2245 | #endif |
| 2246 | |
| 2247 | void SkOpCoincidence::debugValidate() const { |
| 2248 | #if DEBUG_COINCIDENCE |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2249 | DebugValidate(fHead, fTop, nullptr); |
| 2250 | DebugValidate(fTop, nullptr, nullptr); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2251 | #endif |
| 2252 | } |
| 2253 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2254 | #if DEBUG_COIN |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2255 | static void DebugCheckBetween(const SkCoincidentSpans* head, const SkCoincidentSpans* opt, |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2256 | SkPathOpsDebug::GlitchLog* log) { |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2257 | // look for pts inside coincident spans that are not inside the opposite spans |
| 2258 | const SkCoincidentSpans* coin = head; |
| 2259 | while (coin) { |
| 2260 | DebugCheckBetween(coin->coinPtTStart()->span(), coin->coinPtTEnd()->span(), |
| 2261 | coin->oppPtTStart()->fT, coin->oppPtTEnd()->fT, coin->oppPtTStart()->segment(), |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2262 | log); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2263 | DebugCheckBetween(coin->oppPtTStart()->span(), coin->oppPtTEnd()->span(), |
| 2264 | coin->coinPtTStart()->fT, coin->coinPtTEnd()->fT, coin->coinPtTStart()->segment(), |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2265 | log); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2266 | coin = coin->next(); |
| 2267 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2268 | DebugCheckOverlapTop(head, opt, log); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2269 | } |
| 2270 | #endif |
| 2271 | |
| 2272 | void SkOpCoincidence::debugCheckBetween() const { |
| 2273 | #if DEBUG_COINCIDENCE |
| 2274 | if (fGlobalState->debugCheckHealth()) { |
| 2275 | return; |
| 2276 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2277 | DebugCheckBetween(fHead, fTop, nullptr); |
| 2278 | DebugCheckBetween(fTop, nullptr, nullptr); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 2279 | #endif |
| 2280 | } |
| 2281 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2282 | #if DEBUG_COIN |
| 2283 | void SkOpContour::debugCheckHealth(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2284 | const SkOpSegment* segment = &fHead; |
| 2285 | do { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2286 | segment->debugCheckHealth(log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2287 | } while ((segment = segment->next())); |
| 2288 | } |
| 2289 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2290 | void SkOpCoincidence::debugCheckValid(SkPathOpsDebug::GlitchLog* log) const { |
| 2291 | #if DEBUG_VALIDATE |
| 2292 | DebugValidate(fHead, fTop, log); |
| 2293 | DebugValidate(fTop, nullptr, log); |
| 2294 | #endif |
| 2295 | } |
| 2296 | |
| 2297 | void SkOpCoincidence::debugCorrectEnds(SkPathOpsDebug::GlitchLog* log) const { |
| 2298 | const SkCoincidentSpans* coin = fHead; |
| 2299 | if (!coin) { |
| 2300 | return; |
| 2301 | } |
| 2302 | do { |
| 2303 | coin->debugCorrectEnds(log); |
| 2304 | } while ((coin = coin->next())); |
| 2305 | } |
| 2306 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2307 | // commmented-out lines keep this aligned with missingCoincidence() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2308 | void SkOpContour::debugMissingCoincidence(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2309 | // SkASSERT(fCount > 0); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2310 | const SkOpSegment* segment = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2311 | // bool result = false; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2312 | do { |
Cary Clark | e47ae29 | 2016-10-05 08:51:39 -0400 | [diff] [blame] | 2313 | if (segment->debugMissingCoincidence(log), false) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2314 | // result = true; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | segment = segment->next(); |
| 2317 | } while (segment); |
| 2318 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2319 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2320 | |
| 2321 | void SkOpContour::debugMoveMultiples(SkPathOpsDebug::GlitchLog* log) const { |
| 2322 | SkASSERT(fCount > 0); |
| 2323 | const SkOpSegment* segment = &fHead; |
| 2324 | do { |
| 2325 | if (segment->debugMoveMultiples(log), false) { |
| 2326 | return; |
| 2327 | } |
| 2328 | } while ((segment = segment->next())); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
| 2332 | void SkOpContour::debugMoveNearby(SkPathOpsDebug::GlitchLog* log) const { |
| 2333 | SkASSERT(fCount > 0); |
| 2334 | const SkOpSegment* segment = &fHead; |
| 2335 | do { |
| 2336 | segment->debugMoveNearby(log); |
| 2337 | } while ((segment = segment->next())); |
| 2338 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2339 | #endif |
| 2340 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2341 | #if DEBUG_COINCIDENCE_ORDER |
| 2342 | void SkOpSegment::debugResetCoinT() const { |
| 2343 | fDebugBaseIndex = -1; |
| 2344 | fDebugBaseMin = 1; |
| 2345 | fDebugBaseMax = -1; |
| 2346 | fDebugLastIndex = -1; |
| 2347 | fDebugLastMin = 1; |
| 2348 | fDebugLastMax = -1; |
| 2349 | } |
| 2350 | #endif |
| 2351 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2352 | void SkOpSegment::debugValidate() const { |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2353 | #if DEBUG_COINCIDENCE_ORDER |
| 2354 | { |
| 2355 | const SkOpSpanBase* span = &fHead; |
| 2356 | do { |
| 2357 | span->debugResetCoinT(); |
| 2358 | } while (!span->final() && (span = span->upCast()->next())); |
| 2359 | span = &fHead; |
| 2360 | int index = 0; |
| 2361 | do { |
| 2362 | span->debugSetCoinT(index++); |
| 2363 | } while (!span->final() && (span = span->upCast()->next())); |
| 2364 | } |
| 2365 | #endif |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2366 | #if DEBUG_COINCIDENCE |
| 2367 | if (this->globalState()->debugCheckHealth()) { |
| 2368 | return; |
| 2369 | } |
| 2370 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2371 | #if DEBUG_VALIDATE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2372 | const SkOpSpanBase* span = &fHead; |
| 2373 | double lastT = -1; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2374 | const SkOpSpanBase* prev = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2375 | int count = 0; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2376 | int done = 0; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2377 | do { |
| 2378 | if (!span->final()) { |
| 2379 | ++count; |
| 2380 | done += span->upCast()->done() ? 1 : 0; |
| 2381 | } |
| 2382 | SkASSERT(span->segment() == this); |
| 2383 | SkASSERT(!prev || prev->upCast()->next() == span); |
| 2384 | SkASSERT(!prev || prev == span->prev()); |
| 2385 | prev = span; |
| 2386 | double t = span->ptT()->fT; |
| 2387 | SkASSERT(lastT < t); |
| 2388 | lastT = t; |
| 2389 | span->debugValidate(); |
| 2390 | } while (!span->final() && (span = span->upCast()->next())); |
| 2391 | SkASSERT(count == fCount); |
| 2392 | SkASSERT(done == fDoneCount); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 2393 | SkASSERT(count >= fDoneCount); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2394 | SkASSERT(span->final()); |
| 2395 | span->debugValidate(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2396 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2399 | #if DEBUG_COIN |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2400 | |
| 2401 | // Commented-out lines keep this in sync with addOpp() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2402 | void SkOpSpanBase::debugAddOpp(SkPathOpsDebug::GlitchLog* log, const SkOpSpanBase* opp) const { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2403 | const SkOpPtT* oppPrev = this->ptT()->oppPrev(opp->ptT()); |
| 2404 | if (!oppPrev) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2405 | return; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2406 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2407 | this->debugMergeMatches(log, opp); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2408 | this->ptT()->debugAddOpp(opp->ptT(), oppPrev); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2409 | this->debugCheckForCollapsedCoincidence(log); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2412 | // Commented-out lines keep this in sync with checkForCollapsedCoincidence() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2413 | void SkOpSpanBase::debugCheckForCollapsedCoincidence(SkPathOpsDebug::GlitchLog* log) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2414 | const SkOpCoincidence* coins = this->globalState()->coincidence(); |
| 2415 | if (coins->isEmpty()) { |
| 2416 | return; |
| 2417 | } |
| 2418 | // the insert above may have put both ends of a coincident run in the same span |
| 2419 | // for each coincident ptT in loop; see if its opposite in is also in the loop |
| 2420 | // this implementation is the motivation for marking that a ptT is referenced by a coincident span |
| 2421 | const SkOpPtT* head = this->ptT(); |
| 2422 | const SkOpPtT* test = head; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2423 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2424 | if (!test->coincident()) { |
| 2425 | continue; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2426 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2427 | coins->debugMarkCollapsed(log, test); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2428 | } while ((test = test->next()) != head); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2429 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2430 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2431 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2432 | bool SkOpSpanBase::debugCoinEndLoopCheck() const { |
| 2433 | int loop = 0; |
| 2434 | const SkOpSpanBase* next = this; |
| 2435 | SkOpSpanBase* nextCoin; |
| 2436 | do { |
| 2437 | nextCoin = next->fCoinEnd; |
| 2438 | SkASSERT(nextCoin == this || nextCoin->fCoinEnd != nextCoin); |
| 2439 | for (int check = 1; check < loop - 1; ++check) { |
| 2440 | const SkOpSpanBase* checkCoin = this->fCoinEnd; |
| 2441 | const SkOpSpanBase* innerCoin = checkCoin; |
| 2442 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2443 | innerCoin = innerCoin->fCoinEnd; |
| 2444 | if (checkCoin == innerCoin) { |
| 2445 | SkDebugf("*** bad coincident end loop ***\n"); |
| 2446 | return false; |
| 2447 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2448 | } |
| 2449 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2450 | ++loop; |
| 2451 | } while ((next = nextCoin) && next != this); |
| 2452 | return true; |
| 2453 | } |
| 2454 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2455 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2456 | // Commented-out lines keep this in sync with insertCoinEnd() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2457 | void SkOpSpanBase::debugInsertCoinEnd(SkPathOpsDebug::GlitchLog* log, const SkOpSpanBase* coin) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2458 | if (containsCoinEnd(coin)) { |
| 2459 | // SkASSERT(coin->containsCoinEnd(this)); |
| 2460 | return; |
| 2461 | } |
| 2462 | debugValidate(); |
| 2463 | // SkASSERT(this != coin); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2464 | log->record(SkPathOpsDebug::kMarkCoinEnd_Glitch, this, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2465 | // coin->fCoinEnd = this->fCoinEnd; |
| 2466 | // this->fCoinEnd = coinNext; |
| 2467 | debugValidate(); |
| 2468 | } |
| 2469 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2470 | // Commented-out lines keep this in sync with mergeMatches() |
| 2471 | // Look to see if pt-t linked list contains same segment more than once |
| 2472 | // if so, and if each pt-t is directly pointed to by spans in that segment, |
| 2473 | // merge them |
| 2474 | // keep the points, but remove spans so that the segment doesn't have 2 or more |
| 2475 | // spans pointing to the same pt-t loop at different loop elements |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2476 | void SkOpSpanBase::debugMergeMatches(SkPathOpsDebug::GlitchLog* log, const SkOpSpanBase* opp) const { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2477 | const SkOpPtT* test = &fPtT; |
| 2478 | const SkOpPtT* testNext; |
| 2479 | const SkOpPtT* stop = test; |
| 2480 | do { |
| 2481 | testNext = test->next(); |
| 2482 | if (test->deleted()) { |
| 2483 | continue; |
| 2484 | } |
| 2485 | const SkOpSpanBase* testBase = test->span(); |
| 2486 | SkASSERT(testBase->ptT() == test); |
| 2487 | const SkOpSegment* segment = test->segment(); |
| 2488 | if (segment->done()) { |
| 2489 | continue; |
| 2490 | } |
| 2491 | const SkOpPtT* inner = opp->ptT(); |
| 2492 | const SkOpPtT* innerStop = inner; |
| 2493 | do { |
| 2494 | if (inner->segment() != segment) { |
| 2495 | continue; |
| 2496 | } |
| 2497 | if (inner->deleted()) { |
| 2498 | continue; |
| 2499 | } |
| 2500 | const SkOpSpanBase* innerBase = inner->span(); |
| 2501 | SkASSERT(innerBase->ptT() == inner); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 2502 | // when the intersection is first detected, the span base is marked if there are |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2503 | // more than one point in the intersection. |
| 2504 | // if (!innerBase->hasMultipleHint() && !testBase->hasMultipleHint()) { |
| 2505 | if (!zero_or_one(inner->fT)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2506 | log->record(SkPathOpsDebug::kMergeMatches_Glitch, innerBase, test); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2507 | } else { |
| 2508 | SkASSERT(inner->fT != test->fT); |
| 2509 | if (!zero_or_one(test->fT)) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2510 | log->record(SkPathOpsDebug::kMergeMatches_Glitch, testBase, inner); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2511 | } else { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2512 | log->record(SkPathOpsDebug::kMergeMatches_Glitch, segment); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2513 | // SkDEBUGCODE(testBase->debugSetDeleted()); |
| 2514 | // test->setDeleted(); |
| 2515 | // SkDEBUGCODE(innerBase->debugSetDeleted()); |
| 2516 | // inner->setDeleted(); |
| 2517 | } |
| 2518 | } |
| 2519 | #ifdef SK_DEBUG // assert if another undeleted entry points to segment |
| 2520 | const SkOpPtT* debugInner = inner; |
| 2521 | while ((debugInner = debugInner->next()) != innerStop) { |
| 2522 | if (debugInner->segment() != segment) { |
| 2523 | continue; |
| 2524 | } |
| 2525 | if (debugInner->deleted()) { |
| 2526 | continue; |
| 2527 | } |
| 2528 | SkOPASSERT(0); |
| 2529 | } |
| 2530 | #endif |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 2531 | break; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2532 | // } |
| 2533 | break; |
| 2534 | } while ((inner = inner->next()) != innerStop); |
| 2535 | } while ((test = testNext) != stop); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2536 | this->debugCheckForCollapsedCoincidence(log); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2539 | #endif |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2540 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2541 | void SkOpSpanBase::debugResetCoinT() const { |
| 2542 | #if DEBUG_COINCIDENCE_ORDER |
| 2543 | const SkOpPtT* ptT = &fPtT; |
| 2544 | do { |
| 2545 | ptT->debugResetCoinT(); |
| 2546 | ptT = ptT->next(); |
| 2547 | } while (ptT != &fPtT); |
| 2548 | #endif |
| 2549 | } |
| 2550 | |
| 2551 | void SkOpSpanBase::debugSetCoinT(int index) const { |
| 2552 | #if DEBUG_COINCIDENCE_ORDER |
| 2553 | const SkOpPtT* ptT = &fPtT; |
| 2554 | do { |
| 2555 | if (!ptT->deleted()) { |
| 2556 | ptT->debugSetCoinT(index); |
| 2557 | } |
| 2558 | ptT = ptT->next(); |
| 2559 | } while (ptT != &fPtT); |
| 2560 | #endif |
| 2561 | } |
| 2562 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2563 | const SkOpSpan* SkOpSpanBase::debugStarter(SkOpSpanBase const** endPtr) const { |
| 2564 | const SkOpSpanBase* end = *endPtr; |
| 2565 | SkASSERT(this->segment() == end->segment()); |
| 2566 | const SkOpSpanBase* result; |
| 2567 | if (t() < end->t()) { |
| 2568 | result = this; |
| 2569 | } else { |
| 2570 | result = end; |
| 2571 | *endPtr = this; |
| 2572 | } |
| 2573 | return result->upCast(); |
| 2574 | } |
| 2575 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2576 | void SkOpSpanBase::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2577 | #if DEBUG_COINCIDENCE |
| 2578 | if (this->globalState()->debugCheckHealth()) { |
| 2579 | return; |
| 2580 | } |
| 2581 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2582 | #if DEBUG_VALIDATE |
| 2583 | const SkOpPtT* ptT = &fPtT; |
| 2584 | SkASSERT(ptT->span() == this); |
| 2585 | do { |
| 2586 | // SkASSERT(SkDPoint::RoughlyEqual(fPtT.fPt, ptT->fPt)); |
| 2587 | ptT->debugValidate(); |
| 2588 | ptT = ptT->next(); |
| 2589 | } while (ptT != &fPtT); |
| 2590 | SkASSERT(this->debugCoinEndLoopCheck()); |
| 2591 | if (!this->final()) { |
| 2592 | SkASSERT(this->upCast()->debugCoinLoopCheck()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2593 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2594 | if (fFromAngle) { |
| 2595 | fFromAngle->debugValidate(); |
| 2596 | } |
| 2597 | if (!this->final() && this->upCast()->toAngle()) { |
| 2598 | this->upCast()->toAngle()->debugValidate(); |
| 2599 | } |
| 2600 | #endif |
| 2601 | } |
| 2602 | |
| 2603 | bool SkOpSpan::debugCoinLoopCheck() const { |
| 2604 | int loop = 0; |
| 2605 | const SkOpSpan* next = this; |
| 2606 | SkOpSpan* nextCoin; |
| 2607 | do { |
| 2608 | nextCoin = next->fCoincident; |
| 2609 | SkASSERT(nextCoin == this || nextCoin->fCoincident != nextCoin); |
| 2610 | for (int check = 1; check < loop - 1; ++check) { |
| 2611 | const SkOpSpan* checkCoin = this->fCoincident; |
| 2612 | const SkOpSpan* innerCoin = checkCoin; |
| 2613 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2614 | innerCoin = innerCoin->fCoincident; |
| 2615 | if (checkCoin == innerCoin) { |
| 2616 | SkDebugf("*** bad coincident loop ***\n"); |
| 2617 | return false; |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | ++loop; |
| 2622 | } while ((next = nextCoin) && next != this); |
| 2623 | return true; |
| 2624 | } |
| 2625 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2626 | #if DEBUG_COIN |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2627 | // Commented-out lines keep this in sync with insertCoincidence() in header |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2628 | void SkOpSpan::debugInsertCoincidence(SkPathOpsDebug::GlitchLog* log, const SkOpSpan* coin) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2629 | if (containsCoincidence(coin)) { |
| 2630 | // SkASSERT(coin->containsCoincidence(this)); |
| 2631 | return; |
| 2632 | } |
| 2633 | debugValidate(); |
| 2634 | // SkASSERT(this != coin); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2635 | log->record(SkPathOpsDebug::kMarkCoinStart_Glitch, this, coin); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2636 | // coin->fCoincident = this->fCoincident; |
| 2637 | // this->fCoincident = coinNext; |
| 2638 | debugValidate(); |
| 2639 | } |
| 2640 | |
| 2641 | // Commented-out lines keep this in sync with insertCoincidence() |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2642 | void SkOpSpan::debugInsertCoincidence(SkPathOpsDebug::GlitchLog* log, const SkOpSegment* segment, bool flipped, bool ordered) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2643 | if (this->containsCoincidence(segment)) { |
| 2644 | return; |
| 2645 | } |
| 2646 | const SkOpPtT* next = &fPtT; |
| 2647 | while ((next = next->next()) != &fPtT) { |
| 2648 | if (next->segment() == segment) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2649 | const SkOpSpan* span; |
| 2650 | const SkOpSpanBase* base = next->span(); |
| 2651 | if (!ordered) { |
| 2652 | const SkOpSpanBase* spanEnd = fNext->contains(segment)->span(); |
| 2653 | const SkOpPtT* start = base->ptT()->starter(spanEnd->ptT()); |
| 2654 | FAIL_IF(!start->span()->upCastable(), this); |
| 2655 | span = const_cast<SkOpSpan*>(start->span()->upCast()); |
| 2656 | } |
| 2657 | else if (flipped) { |
| 2658 | span = base->prev(); |
| 2659 | FAIL_IF(!span, this); |
| 2660 | } |
| 2661 | else { |
| 2662 | FAIL_IF(!base->upCastable(), this); |
| 2663 | span = base->upCast(); |
| 2664 | } |
| 2665 | log->record(SkPathOpsDebug::kMarkCoinInsert_Glitch, span); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2666 | return; |
| 2667 | } |
| 2668 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2669 | #if DEBUG_COIN |
| 2670 | log->record(SkPathOpsDebug::kMarkCoinMissing_Glitch, segment, this); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2671 | #endif |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2672 | return; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2673 | } |
| 2674 | #endif |
| 2675 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 2676 | // called only by test code |
| 2677 | int SkIntersections::debugCoincidentUsed() const { |
| 2678 | if (!fIsCoincident[0]) { |
| 2679 | SkASSERT(!fIsCoincident[1]); |
| 2680 | return 0; |
| 2681 | } |
| 2682 | int count = 0; |
| 2683 | SkDEBUGCODE(int count2 = 0;) |
| 2684 | for (int index = 0; index < fUsed; ++index) { |
| 2685 | if (fIsCoincident[0] & (1 << index)) { |
| 2686 | ++count; |
| 2687 | } |
| 2688 | #ifdef SK_DEBUG |
| 2689 | if (fIsCoincident[1] & (1 << index)) { |
| 2690 | ++count2; |
| 2691 | } |
| 2692 | #endif |
| 2693 | } |
| 2694 | SkASSERT(count == count2); |
| 2695 | return count; |
| 2696 | } |
| 2697 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 2698 | #include "src/pathops/SkOpContour.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2699 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2700 | // Commented-out lines keep this in sync with addOpp() |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 2701 | void SkOpPtT::debugAddOpp(const SkOpPtT* opp, const SkOpPtT* oppPrev) const { |
| 2702 | SkDEBUGCODE(const SkOpPtT* oldNext = this->fNext); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2703 | SkASSERT(this != opp); |
| 2704 | // this->fNext = opp; |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 2705 | SkASSERT(oppPrev != oldNext); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2706 | // oppPrev->fNext = oldNext; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2709 | bool SkOpPtT::debugContains(const SkOpPtT* check) const { |
| 2710 | SkASSERT(this != check); |
| 2711 | const SkOpPtT* ptT = this; |
| 2712 | int links = 0; |
| 2713 | do { |
| 2714 | ptT = ptT->next(); |
| 2715 | if (ptT == check) { |
| 2716 | return true; |
| 2717 | } |
| 2718 | ++links; |
| 2719 | const SkOpPtT* test = this; |
| 2720 | for (int index = 0; index < links; ++index) { |
| 2721 | if (ptT == test) { |
| 2722 | return false; |
| 2723 | } |
| 2724 | test = test->next(); |
| 2725 | } |
| 2726 | } while (true); |
| 2727 | } |
| 2728 | |
| 2729 | const SkOpPtT* SkOpPtT::debugContains(const SkOpSegment* check) const { |
| 2730 | SkASSERT(this->segment() != check); |
| 2731 | const SkOpPtT* ptT = this; |
| 2732 | int links = 0; |
| 2733 | do { |
| 2734 | ptT = ptT->next(); |
| 2735 | if (ptT->segment() == check) { |
| 2736 | return ptT; |
| 2737 | } |
| 2738 | ++links; |
| 2739 | const SkOpPtT* test = this; |
| 2740 | for (int index = 0; index < links; ++index) { |
| 2741 | if (ptT == test) { |
| 2742 | return nullptr; |
| 2743 | } |
| 2744 | test = test->next(); |
| 2745 | } |
| 2746 | } while (true); |
| 2747 | } |
| 2748 | |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 2749 | const SkOpPtT* SkOpPtT::debugEnder(const SkOpPtT* end) const { |
| 2750 | return fT < end->fT ? end : this; |
| 2751 | } |
| 2752 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2753 | int SkOpPtT::debugLoopLimit(bool report) const { |
| 2754 | int loop = 0; |
| 2755 | const SkOpPtT* next = this; |
| 2756 | do { |
| 2757 | for (int check = 1; check < loop - 1; ++check) { |
| 2758 | const SkOpPtT* checkPtT = this->fNext; |
| 2759 | const SkOpPtT* innerPtT = checkPtT; |
| 2760 | for (int inner = check + 1; inner < loop; ++inner) { |
| 2761 | innerPtT = innerPtT->fNext; |
| 2762 | if (checkPtT == innerPtT) { |
| 2763 | if (report) { |
| 2764 | SkDebugf("*** bad ptT loop ***\n"); |
| 2765 | } |
| 2766 | return loop; |
| 2767 | } |
| 2768 | } |
| 2769 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 2770 | // there's nothing wrong with extremely large loop counts -- but this may appear to hang |
| 2771 | // by taking a very long time to figure out that no loop entry is a duplicate |
| 2772 | // -- and it's likely that a large loop count is indicative of a bug somewhere |
| 2773 | if (++loop > 1000) { |
| 2774 | SkDebugf("*** loop count exceeds 1000 ***\n"); |
| 2775 | return 1000; |
| 2776 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2777 | } while ((next = next->fNext) && next != this); |
| 2778 | return 0; |
| 2779 | } |
| 2780 | |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 2781 | const SkOpPtT* SkOpPtT::debugOppPrev(const SkOpPtT* opp) const { |
| 2782 | return this->oppPrev(const_cast<SkOpPtT*>(opp)); |
| 2783 | } |
| 2784 | |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2785 | void SkOpPtT::debugResetCoinT() const { |
| 2786 | #if DEBUG_COINCIDENCE_ORDER |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 2787 | this->segment()->debugResetCoinT(); |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2788 | #endif |
| 2789 | } |
| 2790 | |
| 2791 | void SkOpPtT::debugSetCoinT(int index) const { |
| 2792 | #if DEBUG_COINCIDENCE_ORDER |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 2793 | this->segment()->debugSetCoinT(index, fT); |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 2794 | #endif |
| 2795 | } |
| 2796 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2797 | void SkOpPtT::debugValidate() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 2798 | #if DEBUG_COINCIDENCE |
| 2799 | if (this->globalState()->debugCheckHealth()) { |
| 2800 | return; |
| 2801 | } |
| 2802 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2803 | #if DEBUG_VALIDATE |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 2804 | SkOpPhase phase = contour()->globalState()->phase(); |
| 2805 | if (phase == SkOpPhase::kIntersecting || phase == SkOpPhase::kFixWinding) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 2806 | return; |
| 2807 | } |
| 2808 | SkASSERT(fNext); |
| 2809 | SkASSERT(fNext != this); |
| 2810 | SkASSERT(fNext->fNext); |
| 2811 | SkASSERT(debugLoopLimit(false) == 0); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 2812 | #endif |
| 2813 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2814 | |
| 2815 | static void output_scalar(SkScalar num) { |
| 2816 | if (num == (int) num) { |
| 2817 | SkDebugf("%d", (int) num); |
| 2818 | } else { |
| 2819 | SkString str; |
| 2820 | str.printf("%1.9g", num); |
| 2821 | int width = (int) str.size(); |
| 2822 | const char* cStr = str.c_str(); |
| 2823 | while (cStr[width - 1] == '0') { |
| 2824 | --width; |
| 2825 | } |
| 2826 | str.resize(width); |
| 2827 | SkDebugf("%sf", str.c_str()); |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | static void output_points(const SkPoint* pts, int count) { |
| 2832 | for (int index = 0; index < count; ++index) { |
| 2833 | output_scalar(pts[index].fX); |
| 2834 | SkDebugf(", "); |
| 2835 | output_scalar(pts[index].fY); |
| 2836 | if (index + 1 < count) { |
| 2837 | SkDebugf(", "); |
| 2838 | } |
| 2839 | } |
| 2840 | } |
| 2841 | |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2842 | static void showPathContours(const SkPath& path, const char* pathName) { |
| 2843 | for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2844 | switch (verb) { |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2845 | case SkPathVerb::kMove: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2846 | SkDebugf(" %s.moveTo(", pathName); |
| 2847 | output_points(&pts[0], 1); |
| 2848 | SkDebugf(");\n"); |
| 2849 | continue; |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2850 | case SkPathVerb::kLine: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2851 | SkDebugf(" %s.lineTo(", pathName); |
| 2852 | output_points(&pts[1], 1); |
| 2853 | SkDebugf(");\n"); |
| 2854 | break; |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2855 | case SkPathVerb::kQuad: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2856 | SkDebugf(" %s.quadTo(", pathName); |
| 2857 | output_points(&pts[1], 2); |
| 2858 | SkDebugf(");\n"); |
| 2859 | break; |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2860 | case SkPathVerb::kConic: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2861 | SkDebugf(" %s.conicTo(", pathName); |
| 2862 | output_points(&pts[1], 2); |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2863 | SkDebugf(", %1.9gf);\n", *w); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2864 | break; |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2865 | case SkPathVerb::kCubic: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2866 | SkDebugf(" %s.cubicTo(", pathName); |
| 2867 | output_points(&pts[1], 3); |
| 2868 | SkDebugf(");\n"); |
| 2869 | break; |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2870 | case SkPathVerb::kClose: |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2871 | SkDebugf(" %s.close();\n", pathName); |
| 2872 | break; |
| 2873 | default: |
| 2874 | SkDEBUGFAIL("bad verb"); |
| 2875 | return; |
| 2876 | } |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | static const char* gFillTypeStr[] = { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 2881 | "kWinding", |
| 2882 | "kEvenOdd", |
| 2883 | "kInverseWinding", |
| 2884 | "kInverseEvenOdd" |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2885 | }; |
| 2886 | |
| 2887 | void SkPathOpsDebug::ShowOnePath(const SkPath& path, const char* name, bool includeDeclaration) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2888 | #define SUPPORT_RECT_CONTOUR_DETECTION 0 |
| 2889 | #if SUPPORT_RECT_CONTOUR_DETECTION |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2890 | int rectCount = path.isRectContours() ? path.rectContours(nullptr, nullptr) : 0; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2891 | if (rectCount > 0) { |
| 2892 | SkTDArray<SkRect> rects; |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 2893 | SkTDArray<SkPathDirection> directions; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2894 | rects.setCount(rectCount); |
| 2895 | directions.setCount(rectCount); |
| 2896 | path.rectContours(rects.begin(), directions.begin()); |
| 2897 | for (int contour = 0; contour < rectCount; ++contour) { |
| 2898 | const SkRect& rect = rects[contour]; |
| 2899 | SkDebugf("path.addRect(%1.9g, %1.9g, %1.9g, %1.9g, %s);\n", rect.fLeft, rect.fTop, |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 2900 | rect.fRight, rect.fBottom, directions[contour] == SkPathDirection::kCCW |
| 2901 | ? "SkPathDirection::kCCW" : "SkPathDirection::kCW"); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2902 | } |
| 2903 | return; |
| 2904 | } |
| 2905 | #endif |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 2906 | SkPathFillType fillType = path.getFillType(); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 2907 | SkASSERT(fillType >= SkPathFillType::kWinding && fillType <= SkPathFillType::kInverseEvenOdd); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2908 | if (includeDeclaration) { |
| 2909 | SkDebugf(" SkPath %s;\n", name); |
| 2910 | } |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 2911 | SkDebugf(" %s.setFillType(SkPath::%s);\n", name, gFillTypeStr[(int)fillType]); |
Chris Dalton | 957189b | 2020-05-07 12:47:26 -0600 | [diff] [blame^] | 2912 | showPathContours(path, name); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 2913 | } |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 2914 | |
Cary Clark | 918fb1f | 2016-11-15 13:22:25 -0500 | [diff] [blame] | 2915 | #if DEBUG_DUMP_VERIFY |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 2916 | #include "include/core/SkData.h" |
| 2917 | #include "include/core/SkStream.h" |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 2918 | |
| 2919 | static void dump_path(FILE* file, const SkPath& path, bool force, bool dumpAsHex) { |
| 2920 | SkDynamicMemoryWStream wStream; |
| 2921 | path.dump(&wStream, force, dumpAsHex); |
| 2922 | sk_sp<SkData> data(wStream.detachAsData()); |
| 2923 | fprintf(file, "%.*s\n", (int) data->size(), (char*) data->data()); |
| 2924 | } |
| 2925 | |
| 2926 | static int dumpID = 0; |
| 2927 | |
| 2928 | void SkPathOpsDebug::DumpOp(const SkPath& one, const SkPath& two, SkPathOp op, |
| 2929 | const char* testName) { |
| 2930 | FILE* file = sk_fopen("op_dump.txt", kWrite_SkFILE_Flag); |
| 2931 | DumpOp(file, one, two, op, testName); |
| 2932 | } |
| 2933 | |
| 2934 | void SkPathOpsDebug::DumpOp(FILE* file, const SkPath& one, const SkPath& two, SkPathOp op, |
| 2935 | const char* testName) { |
| 2936 | const char* name = testName ? testName : "op"; |
| 2937 | fprintf(file, |
| 2938 | "\nstatic void %s_%d(skiatest::Reporter* reporter, const char* filename) {\n", |
| 2939 | name, ++dumpID); |
| 2940 | fprintf(file, " SkPath path;\n"); |
| 2941 | fprintf(file, " path.setFillType((SkPath::FillType) %d);\n", one.getFillType()); |
| 2942 | dump_path(file, one, false, true); |
| 2943 | fprintf(file, " SkPath path1(path);\n"); |
| 2944 | fprintf(file, " path.reset();\n"); |
| 2945 | fprintf(file, " path.setFillType((SkPath::FillType) %d);\n", two.getFillType()); |
| 2946 | dump_path(file, two, false, true); |
| 2947 | fprintf(file, " SkPath path2(path);\n"); |
| 2948 | fprintf(file, " testPathOp(reporter, path1, path2, (SkPathOp) %d, filename);\n", op); |
| 2949 | fprintf(file, "}\n\n"); |
| 2950 | fclose(file); |
| 2951 | } |
| 2952 | |
| 2953 | void SkPathOpsDebug::DumpSimplify(const SkPath& path, const char* testName) { |
| 2954 | FILE* file = sk_fopen("simplify_dump.txt", kWrite_SkFILE_Flag); |
| 2955 | DumpSimplify(file, path, testName); |
| 2956 | } |
| 2957 | |
| 2958 | void SkPathOpsDebug::DumpSimplify(FILE* file, const SkPath& path, const char* testName) { |
| 2959 | const char* name = testName ? testName : "simplify"; |
| 2960 | fprintf(file, |
| 2961 | "\nstatic void %s_%d(skiatest::Reporter* reporter, const char* filename) {\n", |
| 2962 | name, ++dumpID); |
| 2963 | fprintf(file, " SkPath path;\n"); |
| 2964 | fprintf(file, " path.setFillType((SkPath::FillType) %d);\n", path.getFillType()); |
| 2965 | dump_path(file, path, false, true); |
| 2966 | fprintf(file, " testSimplify(reporter, path, filename);\n"); |
| 2967 | fprintf(file, "}\n\n"); |
| 2968 | fclose(file); |
| 2969 | } |
| 2970 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 2971 | #include "include/core/SkBitmap.h" |
| 2972 | #include "include/core/SkCanvas.h" |
| 2973 | #include "include/core/SkPaint.h" |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 2974 | |
| 2975 | const int bitWidth = 64; |
| 2976 | const int bitHeight = 64; |
| 2977 | |
| 2978 | static void debug_scale_matrix(const SkPath& one, const SkPath* two, SkMatrix& scale) { |
| 2979 | SkRect larger = one.getBounds(); |
| 2980 | if (two) { |
| 2981 | larger.join(two->getBounds()); |
| 2982 | } |
| 2983 | SkScalar largerWidth = larger.width(); |
| 2984 | if (largerWidth < 4) { |
| 2985 | largerWidth = 4; |
| 2986 | } |
| 2987 | SkScalar largerHeight = larger.height(); |
| 2988 | if (largerHeight < 4) { |
| 2989 | largerHeight = 4; |
| 2990 | } |
| 2991 | SkScalar hScale = (bitWidth - 2) / largerWidth; |
| 2992 | SkScalar vScale = (bitHeight - 2) / largerHeight; |
| 2993 | scale.reset(); |
| 2994 | scale.preScale(hScale, vScale); |
| 2995 | larger.fLeft *= hScale; |
| 2996 | larger.fRight *= hScale; |
| 2997 | larger.fTop *= vScale; |
| 2998 | larger.fBottom *= vScale; |
| 2999 | SkScalar dx = -16000 > larger.fLeft ? -16000 - larger.fLeft |
| 3000 | : 16000 < larger.fRight ? 16000 - larger.fRight : 0; |
| 3001 | SkScalar dy = -16000 > larger.fTop ? -16000 - larger.fTop |
| 3002 | : 16000 < larger.fBottom ? 16000 - larger.fBottom : 0; |
| 3003 | scale.preTranslate(dx, dy); |
| 3004 | } |
| 3005 | |
| 3006 | static int debug_paths_draw_the_same(const SkPath& one, const SkPath& two, SkBitmap& bits) { |
| 3007 | if (bits.width() == 0) { |
| 3008 | bits.allocN32Pixels(bitWidth * 2, bitHeight); |
| 3009 | } |
| 3010 | SkCanvas canvas(bits); |
| 3011 | canvas.drawColor(SK_ColorWHITE); |
| 3012 | SkPaint paint; |
| 3013 | canvas.save(); |
| 3014 | const SkRect& bounds1 = one.getBounds(); |
| 3015 | canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1); |
| 3016 | canvas.drawPath(one, paint); |
| 3017 | canvas.restore(); |
| 3018 | canvas.save(); |
| 3019 | canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1); |
| 3020 | canvas.drawPath(two, paint); |
| 3021 | canvas.restore(); |
| 3022 | int errors = 0; |
| 3023 | for (int y = 0; y < bitHeight - 1; ++y) { |
| 3024 | uint32_t* addr1 = bits.getAddr32(0, y); |
| 3025 | uint32_t* addr2 = bits.getAddr32(0, y + 1); |
| 3026 | uint32_t* addr3 = bits.getAddr32(bitWidth, y); |
| 3027 | uint32_t* addr4 = bits.getAddr32(bitWidth, y + 1); |
| 3028 | for (int x = 0; x < bitWidth - 1; ++x) { |
| 3029 | // count 2x2 blocks |
| 3030 | bool err = addr1[x] != addr3[x]; |
| 3031 | if (err) { |
| 3032 | errors += addr1[x + 1] != addr3[x + 1] |
| 3033 | && addr2[x] != addr4[x] && addr2[x + 1] != addr4[x + 1]; |
| 3034 | } |
| 3035 | } |
| 3036 | } |
| 3037 | return errors; |
| 3038 | } |
| 3039 | |
| 3040 | void SkPathOpsDebug::ReportOpFail(const SkPath& one, const SkPath& two, SkPathOp op) { |
| 3041 | SkDebugf("// Op did not expect failure\n"); |
| 3042 | DumpOp(stderr, one, two, op, "opTest"); |
| 3043 | fflush(stderr); |
| 3044 | } |
| 3045 | |
| 3046 | void SkPathOpsDebug::VerifyOp(const SkPath& one, const SkPath& two, SkPathOp op, |
| 3047 | const SkPath& result) { |
| 3048 | SkPath pathOut, scaledPathOut; |
| 3049 | SkRegion rgnA, rgnB, openClip, rgnOut; |
| 3050 | openClip.setRect(-16000, -16000, 16000, 16000); |
| 3051 | rgnA.setPath(one, openClip); |
| 3052 | rgnB.setPath(two, openClip); |
| 3053 | rgnOut.op(rgnA, rgnB, (SkRegion::Op) op); |
| 3054 | rgnOut.getBoundaryPath(&pathOut); |
| 3055 | SkMatrix scale; |
| 3056 | debug_scale_matrix(one, &two, scale); |
| 3057 | SkRegion scaledRgnA, scaledRgnB, scaledRgnOut; |
| 3058 | SkPath scaledA, scaledB; |
| 3059 | scaledA.addPath(one, scale); |
| 3060 | scaledA.setFillType(one.getFillType()); |
| 3061 | scaledB.addPath(two, scale); |
| 3062 | scaledB.setFillType(two.getFillType()); |
| 3063 | scaledRgnA.setPath(scaledA, openClip); |
| 3064 | scaledRgnB.setPath(scaledB, openClip); |
| 3065 | scaledRgnOut.op(scaledRgnA, scaledRgnB, (SkRegion::Op) op); |
| 3066 | scaledRgnOut.getBoundaryPath(&scaledPathOut); |
| 3067 | SkBitmap bitmap; |
| 3068 | SkPath scaledOut; |
| 3069 | scaledOut.addPath(result, scale); |
| 3070 | scaledOut.setFillType(result.getFillType()); |
| 3071 | int errors = debug_paths_draw_the_same(scaledPathOut, scaledOut, bitmap); |
| 3072 | const int MAX_ERRORS = 9; |
| 3073 | if (errors > MAX_ERRORS) { |
| 3074 | fprintf(stderr, "// Op did not expect errors=%d\n", errors); |
| 3075 | DumpOp(stderr, one, two, op, "opTest"); |
| 3076 | fflush(stderr); |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | void SkPathOpsDebug::ReportSimplifyFail(const SkPath& path) { |
| 3081 | SkDebugf("// Simplify did not expect failure\n"); |
| 3082 | DumpSimplify(stderr, path, "simplifyTest"); |
| 3083 | fflush(stderr); |
| 3084 | } |
| 3085 | |
| 3086 | void SkPathOpsDebug::VerifySimplify(const SkPath& path, const SkPath& result) { |
| 3087 | SkPath pathOut, scaledPathOut; |
| 3088 | SkRegion rgnA, openClip, rgnOut; |
| 3089 | openClip.setRect(-16000, -16000, 16000, 16000); |
| 3090 | rgnA.setPath(path, openClip); |
| 3091 | rgnOut.getBoundaryPath(&pathOut); |
| 3092 | SkMatrix scale; |
| 3093 | debug_scale_matrix(path, nullptr, scale); |
| 3094 | SkRegion scaledRgnA; |
| 3095 | SkPath scaledA; |
| 3096 | scaledA.addPath(path, scale); |
| 3097 | scaledA.setFillType(path.getFillType()); |
| 3098 | scaledRgnA.setPath(scaledA, openClip); |
| 3099 | scaledRgnA.getBoundaryPath(&scaledPathOut); |
| 3100 | SkBitmap bitmap; |
| 3101 | SkPath scaledOut; |
| 3102 | scaledOut.addPath(result, scale); |
| 3103 | scaledOut.setFillType(result.getFillType()); |
| 3104 | int errors = debug_paths_draw_the_same(scaledPathOut, scaledOut, bitmap); |
| 3105 | const int MAX_ERRORS = 9; |
| 3106 | if (errors > MAX_ERRORS) { |
| 3107 | fprintf(stderr, "// Simplify did not expect errors=%d\n", errors); |
| 3108 | DumpSimplify(stderr, path, "simplifyTest"); |
| 3109 | fflush(stderr); |
| 3110 | } |
| 3111 | } |
| 3112 | |
| 3113 | #endif |
Cary Clark | b8421ed | 2018-03-14 15:55:02 -0400 | [diff] [blame] | 3114 | |
| 3115 | // global path dumps for msvs Visual Studio 17 to use from Immediate Window |
| 3116 | void Dump(const SkPath& path) { |
| 3117 | path.dump(); |
| 3118 | } |
| 3119 | |
| 3120 | void DumpHex(const SkPath& path) { |
| 3121 | path.dumpHex(); |
| 3122 | } |