caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 7 | #include "SkOpCoincidence.h" |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 8 | #include "SkOpContour.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 9 | #include "SkOpSegment.h" |
| 10 | #include "SkPathWriter.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | After computing raw intersections, post process all segments to: |
| 14 | - find small collections of points that can be collapsed to a single point |
| 15 | - find missing intersections to resolve differences caused by different algorithms |
| 16 | |
| 17 | Consider segments containing tiny or small intervals. Consider coincident segments |
| 18 | because coincidence finds intersections through distance measurement that non-coincident |
| 19 | intersection tests cannot. |
| 20 | */ |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 21 | |
| 22 | #define F (false) // discard the edge |
| 23 | #define T (true) // keep the edge |
| 24 | |
| 25 | static const bool gUnaryActiveEdge[2][2] = { |
| 26 | // from=0 from=1 |
| 27 | // to=0,1 to=0,1 |
| 28 | {F, T}, {T, F}, |
| 29 | }; |
| 30 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 31 | static const bool gActiveEdge[kXOR_SkPathOp + 1][2][2][2][2] = { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 32 | // miFrom=0 miFrom=1 |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 33 | // miTo=0 miTo=1 miTo=0 miTo=1 |
| 34 | // suFrom=0 1 suFrom=0 1 suFrom=0 1 suFrom=0 1 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 35 | // suTo=0,1 suTo=0,1 suTo=0,1 suTo=0,1 suTo=0,1 suTo=0,1 suTo=0,1 suTo=0,1 |
| 36 | {{{{F, F}, {F, F}}, {{T, F}, {T, F}}}, {{{T, T}, {F, F}}, {{F, T}, {T, F}}}}, // mi - su |
| 37 | {{{{F, F}, {F, F}}, {{F, T}, {F, T}}}, {{{F, F}, {T, T}}, {{F, T}, {T, F}}}}, // mi & su |
| 38 | {{{{F, T}, {T, F}}, {{T, T}, {F, F}}}, {{{T, F}, {T, F}}, {{F, F}, {F, F}}}}, // mi | su |
| 39 | {{{{F, T}, {T, F}}, {{T, F}, {F, T}}}, {{{T, F}, {F, T}}, {{F, T}, {T, F}}}}, // mi ^ su |
| 40 | }; |
| 41 | |
| 42 | #undef F |
| 43 | #undef T |
| 44 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 45 | SkOpAngle* SkOpSegment::activeAngle(SkOpSpanBase* start, SkOpSpanBase** startPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 46 | SkOpSpanBase** endPtr, bool* done) { |
| 47 | if (SkOpAngle* result = activeAngleInner(start, startPtr, endPtr, done)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 48 | return result; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 49 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 50 | if (SkOpAngle* result = activeAngleOther(start, startPtr, endPtr, done)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 51 | return result; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 52 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 53 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 54 | } |
| 55 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 56 | SkOpAngle* SkOpSegment::activeAngleInner(SkOpSpanBase* start, SkOpSpanBase** startPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 57 | SkOpSpanBase** endPtr, bool* done) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 58 | SkOpSpan* upSpan = start->upCastable(); |
| 59 | if (upSpan) { |
| 60 | if (upSpan->windValue() || upSpan->oppValue()) { |
| 61 | SkOpSpanBase* next = upSpan->next(); |
| 62 | if (!*endPtr) { |
| 63 | *startPtr = start; |
| 64 | *endPtr = next; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 65 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 66 | if (!upSpan->done()) { |
| 67 | if (upSpan->windSum() != SK_MinS32) { |
| 68 | return spanToAngle(start, next); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 69 | } |
| 70 | *done = false; |
| 71 | } |
| 72 | } else { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 73 | SkASSERT(upSpan->done()); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 76 | SkOpSpan* downSpan = start->prev(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 77 | // edge leading into junction |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 78 | if (downSpan) { |
| 79 | if (downSpan->windValue() || downSpan->oppValue()) { |
| 80 | if (!*endPtr) { |
| 81 | *startPtr = start; |
| 82 | *endPtr = downSpan; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 83 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 84 | if (!downSpan->done()) { |
| 85 | if (downSpan->windSum() != SK_MinS32) { |
| 86 | return spanToAngle(start, downSpan); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 87 | } |
| 88 | *done = false; |
| 89 | } |
| 90 | } else { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 91 | SkASSERT(downSpan->done()); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 92 | } |
| 93 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 94 | return nullptr; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 95 | } |
| 96 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 97 | SkOpAngle* SkOpSegment::activeAngleOther(SkOpSpanBase* start, SkOpSpanBase** startPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 98 | SkOpSpanBase** endPtr, bool* done) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 99 | SkOpPtT* oPtT = start->ptT()->next(); |
| 100 | SkOpSegment* other = oPtT->segment(); |
| 101 | SkOpSpanBase* oSpan = oPtT->span(); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 102 | return other->activeAngleInner(oSpan, startPtr, endPtr, done); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 103 | } |
| 104 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 105 | bool SkOpSegment::activeOp(SkOpSpanBase* start, SkOpSpanBase* end, int xorMiMask, int xorSuMask, |
| 106 | SkPathOp op) { |
| 107 | int sumMiWinding = this->updateWinding(end, start); |
| 108 | int sumSuWinding = this->updateOppWinding(end, start); |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 109 | #if DEBUG_LIMIT_WIND_SUM |
| 110 | SkASSERT(abs(sumMiWinding) <= DEBUG_LIMIT_WIND_SUM); |
| 111 | SkASSERT(abs(sumSuWinding) <= DEBUG_LIMIT_WIND_SUM); |
| 112 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 113 | if (this->operand()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 114 | SkTSwap<int>(sumMiWinding, sumSuWinding); |
| 115 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 116 | return this->activeOp(xorMiMask, xorSuMask, start, end, op, &sumMiWinding, &sumSuWinding); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 117 | } |
| 118 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 119 | bool SkOpSegment::activeOp(int xorMiMask, int xorSuMask, SkOpSpanBase* start, SkOpSpanBase* end, |
| 120 | SkPathOp op, int* sumMiWinding, int* sumSuWinding) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 121 | int maxWinding, sumWinding, oppMaxWinding, oppSumWinding; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 122 | this->setUpWindings(start, end, sumMiWinding, sumSuWinding, |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 123 | &maxWinding, &sumWinding, &oppMaxWinding, &oppSumWinding); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 124 | bool miFrom; |
| 125 | bool miTo; |
| 126 | bool suFrom; |
| 127 | bool suTo; |
| 128 | if (operand()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 129 | miFrom = (oppMaxWinding & xorMiMask) != 0; |
| 130 | miTo = (oppSumWinding & xorMiMask) != 0; |
| 131 | suFrom = (maxWinding & xorSuMask) != 0; |
| 132 | suTo = (sumWinding & xorSuMask) != 0; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 133 | } else { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 134 | miFrom = (maxWinding & xorMiMask) != 0; |
| 135 | miTo = (sumWinding & xorMiMask) != 0; |
| 136 | suFrom = (oppMaxWinding & xorSuMask) != 0; |
| 137 | suTo = (oppSumWinding & xorSuMask) != 0; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 138 | } |
| 139 | bool result = gActiveEdge[op][miFrom][miTo][suFrom][suTo]; |
| 140 | #if DEBUG_ACTIVE_OP |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 141 | SkDebugf("%s id=%d t=%1.9g tEnd=%1.9g op=%s miFrom=%d miTo=%d suFrom=%d suTo=%d result=%d\n", |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 142 | __FUNCTION__, debugID(), start->t(), end->t(), |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 143 | SkPathOpsDebug::kPathOpStr[op], miFrom, miTo, suFrom, suTo, result); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 144 | #endif |
| 145 | return result; |
| 146 | } |
| 147 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 148 | bool SkOpSegment::activeWinding(SkOpSpanBase* start, SkOpSpanBase* end) { |
| 149 | int sumWinding = updateWinding(end, start); |
| 150 | return activeWinding(start, end, &sumWinding); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 151 | } |
| 152 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 153 | bool SkOpSegment::activeWinding(SkOpSpanBase* start, SkOpSpanBase* end, int* sumWinding) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 154 | int maxWinding; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 155 | setUpWinding(start, end, &maxWinding, sumWinding); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 156 | bool from = maxWinding != 0; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 157 | bool to = *sumWinding != 0; |
| 158 | bool result = gUnaryActiveEdge[from][to]; |
| 159 | return result; |
| 160 | } |
| 161 | |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 162 | bool SkOpSegment::addCurveTo(const SkOpSpanBase* start, const SkOpSpanBase* end, |
| 163 | SkPathWriter* path) const { |
caryclark | 025b11e | 2016-08-25 05:21:14 -0700 | [diff] [blame] | 164 | FAIL_IF(start->starter(end)->alreadyAdded()); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 165 | SkDCurveSweep curvePart; |
| 166 | start->segment()->subDivide(start, end, &curvePart.fCurve); |
| 167 | curvePart.setCurveHullSweep(fVerb); |
| 168 | SkPath::Verb verb = curvePart.isCurve() ? fVerb : SkPath::kLine_Verb; |
| 169 | path->deferredMove(start->ptT()); |
| 170 | switch (verb) { |
| 171 | case SkPath::kLine_Verb: |
| 172 | path->deferredLine(end->ptT()); |
| 173 | break; |
| 174 | case SkPath::kQuad_Verb: |
| 175 | path->quadTo(curvePart.fCurve.fQuad.fPts[1].asSkPoint(), end->ptT()); |
| 176 | break; |
| 177 | case SkPath::kConic_Verb: |
| 178 | path->conicTo(curvePart.fCurve.fConic.fPts[1].asSkPoint(), end->ptT(), |
| 179 | curvePart.fCurve.fConic.fWeight); |
| 180 | break; |
| 181 | case SkPath::kCubic_Verb: |
| 182 | path->cubicTo(curvePart.fCurve.fCubic.fPts[1].asSkPoint(), |
| 183 | curvePart.fCurve.fCubic.fPts[2].asSkPoint(), end->ptT()); |
| 184 | break; |
| 185 | default: |
| 186 | SkASSERT(0); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 187 | } |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 188 | return true; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 189 | } |
| 190 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 191 | const SkOpPtT* SkOpSegment::existing(double t, const SkOpSegment* opp) const { |
| 192 | const SkOpSpanBase* test = &fHead; |
| 193 | const SkOpPtT* testPtT; |
| 194 | SkPoint pt = this->ptAtT(t); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 195 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 196 | testPtT = test->ptT(); |
| 197 | if (testPtT->fT == t) { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 200 | if (!this->match(testPtT, this, t, pt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 201 | if (t < testPtT->fT) { |
| 202 | return nullptr; |
| 203 | } |
| 204 | continue; |
| 205 | } |
| 206 | if (!opp) { |
| 207 | return testPtT; |
| 208 | } |
| 209 | const SkOpPtT* loop = testPtT->next(); |
| 210 | while (loop != testPtT) { |
| 211 | if (loop->segment() == this && loop->fT == t && loop->fPt == pt) { |
| 212 | goto foundMatch; |
| 213 | } |
| 214 | loop = loop->next(); |
| 215 | } |
| 216 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 217 | } while ((test = test->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 218 | foundMatch: |
| 219 | return opp && !test->contains(opp) ? nullptr : testPtT; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 220 | } |
| 221 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 222 | // break the span so that the coincident part does not change the angle of the remainder |
| 223 | bool SkOpSegment::addExpanded(double newT, const SkOpSpanBase* test, bool* startOver) { |
| 224 | if (this->contains(newT)) { |
| 225 | return true; |
| 226 | } |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 227 | this->globalState()->resetAllocatedOpSpan(); |
| 228 | SkOpPtT* newPtT = this->addT(newT); |
| 229 | *startOver |= this->globalState()->allocatedOpSpan(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 230 | if (!newPtT) { |
| 231 | return false; |
| 232 | } |
| 233 | newPtT->fPt = this->ptAtT(newT); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 234 | SkOpPtT* oppPrev = test->ptT()->oppPrev(newPtT); |
| 235 | if (oppPrev) { |
caryclark | 8016b26 | 2016-09-06 05:59:47 -0700 | [diff] [blame] | 236 | // const cast away to change linked list; pt/t values stays unchanged |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 237 | SkOpSpanBase* writableTest = const_cast<SkOpSpanBase*>(test); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 238 | writableTest->mergeMatches(newPtT->span()); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 239 | writableTest->ptT()->addOpp(newPtT, oppPrev); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 240 | writableTest->checkForCollapsedCoincidence(); |
| 241 | } |
| 242 | return true; |
| 243 | } |
| 244 | |
| 245 | // Please keep this in sync with debugAddT() |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 246 | SkOpPtT* SkOpSegment::addT(double t) { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 247 | debugValidate(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 248 | SkPoint pt = this->ptAtT(t); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 249 | SkOpSpanBase* spanBase = &fHead; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 250 | do { |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 251 | SkOpPtT* result = spanBase->ptT(); |
caryclark | 27c015d | 2016-09-23 05:47:20 -0700 | [diff] [blame] | 252 | if (t == result->fT || (!zero_or_one(t) && this->match(result, this, t, pt))) { |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 253 | spanBase->bumpSpanAdds(); |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 254 | return result; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 255 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 256 | if (t < result->fT) { |
| 257 | SkOpSpan* prev = result->span()->prev(); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 258 | FAIL_WITH_NULL_IF(!prev); |
| 259 | // marks in global state that new op span has been allocated |
| 260 | SkOpSpan* span = this->insert(prev); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 261 | span->init(this, prev, t, pt); |
| 262 | this->debugValidate(); |
| 263 | #if DEBUG_ADD_T |
| 264 | SkDebugf("%s insert t=%1.9g segID=%d spanID=%d\n", __FUNCTION__, t, |
| 265 | span->segment()->debugID(), span->debugID()); |
| 266 | #endif |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 267 | span->bumpSpanAdds(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 268 | return span->ptT(); |
| 269 | } |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 270 | FAIL_WITH_NULL_IF(spanBase == &fTail); |
| 271 | } while ((spanBase = spanBase->upCast()->next())); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 272 | SkASSERT(0); |
caryclark | 29b2563 | 2016-08-25 11:27:17 -0700 | [diff] [blame] | 273 | return nullptr; // we never get here, but need this to satisfy compiler |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 274 | } |
| 275 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 276 | void SkOpSegment::calcAngles() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 277 | bool activePrior = !fHead.isCanceled(); |
| 278 | if (activePrior && !fHead.simple()) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 279 | addStartSpan(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 280 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 281 | SkOpSpan* prior = &fHead; |
| 282 | SkOpSpanBase* spanBase = fHead.next(); |
| 283 | while (spanBase != &fTail) { |
| 284 | if (activePrior) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 285 | SkOpAngle* priorAngle = SkOpTAllocator<SkOpAngle>::Allocate( |
| 286 | this->globalState()->allocator()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 287 | priorAngle->set(spanBase, prior); |
| 288 | spanBase->setFromAngle(priorAngle); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 289 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 290 | SkOpSpan* span = spanBase->upCast(); |
| 291 | bool active = !span->isCanceled(); |
| 292 | SkOpSpanBase* next = span->next(); |
| 293 | if (active) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 294 | SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate( |
| 295 | this->globalState()->allocator()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 296 | angle->set(span, next); |
| 297 | span->setToAngle(angle); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 298 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 299 | activePrior = active; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 300 | prior = span; |
| 301 | spanBase = next; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 302 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 303 | if (activePrior && !fTail.simple()) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 304 | addEndSpan(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 305 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 306 | } |
| 307 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 308 | // Please keep this in sync with debugClearAll() |
| 309 | void SkOpSegment::clearAll() { |
| 310 | SkOpSpan* span = &fHead; |
| 311 | do { |
| 312 | this->clearOne(span); |
| 313 | } while ((span = span->next()->upCastable())); |
| 314 | this->globalState()->coincidence()->release(this); |
| 315 | } |
| 316 | |
| 317 | // Please keep this in sync with debugClearOne() |
| 318 | void SkOpSegment::clearOne(SkOpSpan* span) { |
| 319 | span->setWindValue(0); |
| 320 | span->setOppValue(0); |
| 321 | this->markDone(span); |
| 322 | } |
| 323 | |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 324 | bool SkOpSegment::collapsed(double s, double e) const { |
| 325 | const SkOpSpanBase* span = &fHead; |
| 326 | do { |
| 327 | if (span->collapsed(s, e)) { |
| 328 | return true; |
| 329 | } |
| 330 | } while (span->upCastable() && (span = span->upCast()->next())); |
| 331 | return false; |
| 332 | } |
| 333 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 334 | void SkOpSegment::ComputeOneSum(const SkOpAngle* baseAngle, SkOpAngle* nextAngle, |
| 335 | SkOpAngle::IncludeType includeType) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 336 | SkOpSegment* baseSegment = baseAngle->segment(); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 337 | int sumMiWinding = baseSegment->updateWindingReverse(baseAngle); |
| 338 | int sumSuWinding; |
| 339 | bool binary = includeType >= SkOpAngle::kBinarySingle; |
| 340 | if (binary) { |
| 341 | sumSuWinding = baseSegment->updateOppWindingReverse(baseAngle); |
| 342 | if (baseSegment->operand()) { |
| 343 | SkTSwap<int>(sumMiWinding, sumSuWinding); |
| 344 | } |
| 345 | } |
| 346 | SkOpSegment* nextSegment = nextAngle->segment(); |
| 347 | int maxWinding, sumWinding; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 348 | SkOpSpanBase* last; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 349 | if (binary) { |
| 350 | int oppMaxWinding, oppSumWinding; |
| 351 | nextSegment->setUpWindings(nextAngle->start(), nextAngle->end(), &sumMiWinding, |
| 352 | &sumSuWinding, &maxWinding, &sumWinding, &oppMaxWinding, &oppSumWinding); |
| 353 | last = nextSegment->markAngle(maxWinding, sumWinding, oppMaxWinding, oppSumWinding, |
commit-bot@chromium.org | 866f4e3 | 2013-11-21 17:04:29 +0000 | [diff] [blame] | 354 | nextAngle); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 355 | } else { |
| 356 | nextSegment->setUpWindings(nextAngle->start(), nextAngle->end(), &sumMiWinding, |
| 357 | &maxWinding, &sumWinding); |
commit-bot@chromium.org | 866f4e3 | 2013-11-21 17:04:29 +0000 | [diff] [blame] | 358 | last = nextSegment->markAngle(maxWinding, sumWinding, nextAngle); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 359 | } |
| 360 | nextAngle->setLastMarked(last); |
| 361 | } |
| 362 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 363 | void SkOpSegment::ComputeOneSumReverse(SkOpAngle* baseAngle, SkOpAngle* nextAngle, |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 364 | SkOpAngle::IncludeType includeType) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 365 | SkOpSegment* baseSegment = baseAngle->segment(); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 366 | int sumMiWinding = baseSegment->updateWinding(baseAngle); |
| 367 | int sumSuWinding; |
| 368 | bool binary = includeType >= SkOpAngle::kBinarySingle; |
| 369 | if (binary) { |
| 370 | sumSuWinding = baseSegment->updateOppWinding(baseAngle); |
| 371 | if (baseSegment->operand()) { |
| 372 | SkTSwap<int>(sumMiWinding, sumSuWinding); |
| 373 | } |
| 374 | } |
| 375 | SkOpSegment* nextSegment = nextAngle->segment(); |
| 376 | int maxWinding, sumWinding; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 377 | SkOpSpanBase* last; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 378 | if (binary) { |
| 379 | int oppMaxWinding, oppSumWinding; |
| 380 | nextSegment->setUpWindings(nextAngle->end(), nextAngle->start(), &sumMiWinding, |
| 381 | &sumSuWinding, &maxWinding, &sumWinding, &oppMaxWinding, &oppSumWinding); |
| 382 | last = nextSegment->markAngle(maxWinding, sumWinding, oppMaxWinding, oppSumWinding, |
commit-bot@chromium.org | 866f4e3 | 2013-11-21 17:04:29 +0000 | [diff] [blame] | 383 | nextAngle); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 384 | } else { |
| 385 | nextSegment->setUpWindings(nextAngle->end(), nextAngle->start(), &sumMiWinding, |
| 386 | &maxWinding, &sumWinding); |
commit-bot@chromium.org | 866f4e3 | 2013-11-21 17:04:29 +0000 | [diff] [blame] | 387 | last = nextSegment->markAngle(maxWinding, sumWinding, nextAngle); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 388 | } |
| 389 | nextAngle->setLastMarked(last); |
| 390 | } |
| 391 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 392 | // at this point, the span is already ordered, or unorderable |
| 393 | int SkOpSegment::computeSum(SkOpSpanBase* start, SkOpSpanBase* end, |
| 394 | SkOpAngle::IncludeType includeType) { |
| 395 | SkASSERT(includeType != SkOpAngle::kUnaryXor); |
| 396 | SkOpAngle* firstAngle = this->spanToAngle(end, start); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 397 | if (nullptr == firstAngle || nullptr == firstAngle->next()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 398 | return SK_NaN32; |
| 399 | } |
| 400 | // if all angles have a computed winding, |
| 401 | // or if no adjacent angles are orderable, |
| 402 | // or if adjacent orderable angles have no computed winding, |
| 403 | // there's nothing to do |
| 404 | // if two orderable angles are adjacent, and both are next to orderable angles, |
| 405 | // and one has winding computed, transfer to the other |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 406 | SkOpAngle* baseAngle = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 407 | bool tryReverse = false; |
| 408 | // look for counterclockwise transfers |
| 409 | SkOpAngle* angle = firstAngle->previous(); |
| 410 | SkOpAngle* next = angle->next(); |
| 411 | firstAngle = next; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 412 | do { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 413 | SkOpAngle* prior = angle; |
| 414 | angle = next; |
| 415 | next = angle->next(); |
| 416 | SkASSERT(prior->next() == angle); |
| 417 | SkASSERT(angle->next() == next); |
| 418 | if (prior->unorderable() || angle->unorderable() || next->unorderable()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 419 | baseAngle = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 420 | continue; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 421 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 422 | int testWinding = angle->starter()->windSum(); |
| 423 | if (SK_MinS32 != testWinding) { |
| 424 | baseAngle = angle; |
| 425 | tryReverse = true; |
| 426 | continue; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 427 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 428 | if (baseAngle) { |
| 429 | ComputeOneSum(baseAngle, angle, includeType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 430 | baseAngle = SK_MinS32 != angle->starter()->windSum() ? angle : nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 431 | } |
| 432 | } while (next != firstAngle); |
| 433 | if (baseAngle && SK_MinS32 == firstAngle->starter()->windSum()) { |
| 434 | firstAngle = baseAngle; |
| 435 | tryReverse = true; |
| 436 | } |
| 437 | if (tryReverse) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 438 | baseAngle = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 439 | SkOpAngle* prior = firstAngle; |
| 440 | do { |
| 441 | angle = prior; |
| 442 | prior = angle->previous(); |
| 443 | SkASSERT(prior->next() == angle); |
| 444 | next = angle->next(); |
| 445 | if (prior->unorderable() || angle->unorderable() || next->unorderable()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 446 | baseAngle = nullptr; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 447 | continue; |
| 448 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 449 | int testWinding = angle->starter()->windSum(); |
| 450 | if (SK_MinS32 != testWinding) { |
| 451 | baseAngle = angle; |
| 452 | continue; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 453 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 454 | if (baseAngle) { |
| 455 | ComputeOneSumReverse(baseAngle, angle, includeType); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 456 | baseAngle = SK_MinS32 != angle->starter()->windSum() ? angle : nullptr; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 457 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 458 | } while (prior != firstAngle); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 459 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 460 | return start->starter(end)->windSum(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 461 | } |
| 462 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 463 | bool SkOpSegment::contains(double newT) const { |
| 464 | const SkOpSpanBase* spanBase = &fHead; |
| 465 | do { |
| 466 | if (spanBase->ptT()->contains(this, newT)) { |
| 467 | return true; |
| 468 | } |
| 469 | if (spanBase == &fTail) { |
| 470 | break; |
| 471 | } |
| 472 | spanBase = spanBase->upCast()->next(); |
| 473 | } while (true); |
| 474 | return false; |
| 475 | } |
| 476 | |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 477 | void SkOpSegment::release(const SkOpSpan* span) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 478 | if (span->done()) { |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 479 | --fDoneCount; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 480 | } |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 481 | --fCount; |
caryclark | 1597628 | 2016-07-21 05:48:43 -0700 | [diff] [blame] | 482 | SkOPASSERT(fCount >= fDoneCount); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Cary Clark | e47ae29 | 2016-10-05 08:51:39 -0400 | [diff] [blame] | 485 | #if DEBUG_ANGLE |
| 486 | // called only by debugCheckNearCoincidence |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 487 | double SkOpSegment::distSq(double t, const SkOpAngle* oppAngle) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 488 | SkDPoint testPt = this->dPtAtT(t); |
| 489 | SkDLine testPerp = {{ testPt, testPt }}; |
| 490 | SkDVector slope = this->dSlopeAtT(t); |
| 491 | testPerp[1].fX += slope.fY; |
| 492 | testPerp[1].fY -= slope.fX; |
| 493 | SkIntersections i; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 494 | const SkOpSegment* oppSegment = oppAngle->segment(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 495 | (*CurveIntersectRay[oppSegment->verb()])(oppSegment->pts(), oppSegment->weight(), testPerp, &i); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 496 | double closestDistSq = SK_ScalarInfinity; |
| 497 | for (int index = 0; index < i.used(); ++index) { |
| 498 | if (!between(oppAngle->start()->t(), i[0][index], oppAngle->end()->t())) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 499 | continue; |
| 500 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 501 | double testDistSq = testPt.distanceSquared(i.pt(index)); |
| 502 | if (closestDistSq > testDistSq) { |
| 503 | closestDistSq = testDistSq; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 506 | return closestDistSq; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 507 | } |
Cary Clark | e47ae29 | 2016-10-05 08:51:39 -0400 | [diff] [blame] | 508 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 509 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 510 | /* |
| 511 | The M and S variable name parts stand for the operators. |
| 512 | Mi stands for Minuend (see wiki subtraction, analogous to difference) |
| 513 | Su stands for Subtrahend |
| 514 | The Opp variable name part designates that the value is for the Opposite operator. |
| 515 | Opposite values result from combining coincident spans. |
| 516 | */ |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 517 | SkOpSegment* SkOpSegment::findNextOp(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** nextStart, |
| 518 | SkOpSpanBase** nextEnd, bool* unsortable, SkPathOp op, int xorMiMask, int xorSuMask) { |
| 519 | SkOpSpanBase* start = *nextStart; |
| 520 | SkOpSpanBase* end = *nextEnd; |
| 521 | SkASSERT(start != end); |
| 522 | int step = start->step(end); |
| 523 | SkOpSegment* other = this->isSimple(nextStart, &step); // advances nextStart |
| 524 | if (other) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 525 | // mark the smaller of startIndex, endIndex done, and all adjacent |
| 526 | // spans with the same T value (but not 'other' spans) |
| 527 | #if DEBUG_WINDING |
| 528 | SkDebugf("%s simple\n", __FUNCTION__); |
| 529 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 530 | SkOpSpan* startSpan = start->starter(end); |
| 531 | if (startSpan->done()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 532 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 533 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 534 | markDone(startSpan); |
| 535 | *nextEnd = step > 0 ? (*nextStart)->upCast()->next() : (*nextStart)->prev(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 536 | return other; |
| 537 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 538 | SkOpSpanBase* endNear = step > 0 ? (*nextStart)->upCast()->next() : (*nextStart)->prev(); |
| 539 | SkASSERT(endNear == end); // is this ever not end? |
| 540 | SkASSERT(endNear); |
| 541 | SkASSERT(start != endNear); |
| 542 | SkASSERT((start->t() < endNear->t()) ^ (step < 0)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 543 | // more than one viable candidate -- measure angles to find best |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 544 | int calcWinding = computeSum(start, endNear, SkOpAngle::kBinaryOpp); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 545 | bool sortable = calcWinding != SK_NaN32; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 546 | if (!sortable) { |
| 547 | *unsortable = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 548 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 549 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 550 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 551 | SkOpAngle* angle = this->spanToAngle(end, start); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 552 | if (angle->unorderable()) { |
| 553 | *unsortable = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 554 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 555 | return nullptr; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 556 | } |
| 557 | #if DEBUG_SORT |
| 558 | SkDebugf("%s\n", __FUNCTION__); |
| 559 | angle->debugLoop(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 560 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 561 | int sumMiWinding = updateWinding(end, start); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 562 | if (sumMiWinding == SK_MinS32) { |
| 563 | *unsortable = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 564 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 565 | return nullptr; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 566 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 567 | int sumSuWinding = updateOppWinding(end, start); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 568 | if (operand()) { |
| 569 | SkTSwap<int>(sumMiWinding, sumSuWinding); |
| 570 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 571 | SkOpAngle* nextAngle = angle->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 572 | const SkOpAngle* foundAngle = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 573 | bool foundDone = false; |
| 574 | // iterate through the angle, and compute everyone's winding |
| 575 | SkOpSegment* nextSegment; |
| 576 | int activeCount = 0; |
| 577 | do { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 578 | nextSegment = nextAngle->segment(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 579 | bool activeAngle = nextSegment->activeOp(xorMiMask, xorSuMask, nextAngle->start(), |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 580 | nextAngle->end(), op, &sumMiWinding, &sumSuWinding); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 581 | if (activeAngle) { |
| 582 | ++activeCount; |
| 583 | if (!foundAngle || (foundDone && activeCount & 1)) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 584 | foundAngle = nextAngle; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 585 | foundDone = nextSegment->done(nextAngle); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | if (nextSegment->done()) { |
| 589 | continue; |
| 590 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 591 | if (!activeAngle) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 592 | (void) nextSegment->markAndChaseDone(nextAngle->start(), nextAngle->end()); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 593 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 594 | SkOpSpanBase* last = nextAngle->lastMarked(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 595 | if (last) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 596 | SkASSERT(!SkPathOpsDebug::ChaseContains(*chase, last)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 597 | *chase->append() = last; |
| 598 | #if DEBUG_WINDING |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 599 | SkDebugf("%s chase.append segment=%d span=%d", __FUNCTION__, |
| 600 | last->segment()->debugID(), last->debugID()); |
| 601 | if (!last->final()) { |
| 602 | SkDebugf(" windSum=%d", last->upCast()->windSum()); |
| 603 | } |
| 604 | SkDebugf("\n"); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 605 | #endif |
| 606 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 607 | } while ((nextAngle = nextAngle->next()) != angle); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 608 | start->segment()->markDone(start->starter(end)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 609 | if (!foundAngle) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 610 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 611 | } |
| 612 | *nextStart = foundAngle->start(); |
| 613 | *nextEnd = foundAngle->end(); |
| 614 | nextSegment = foundAngle->segment(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 615 | #if DEBUG_WINDING |
| 616 | SkDebugf("%s from:[%d] to:[%d] start=%d end=%d\n", |
| 617 | __FUNCTION__, debugID(), nextSegment->debugID(), *nextStart, *nextEnd); |
| 618 | #endif |
| 619 | return nextSegment; |
| 620 | } |
| 621 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 622 | SkOpSegment* SkOpSegment::findNextWinding(SkTDArray<SkOpSpanBase*>* chase, |
| 623 | SkOpSpanBase** nextStart, SkOpSpanBase** nextEnd, bool* unsortable) { |
| 624 | SkOpSpanBase* start = *nextStart; |
| 625 | SkOpSpanBase* end = *nextEnd; |
| 626 | SkASSERT(start != end); |
| 627 | int step = start->step(end); |
| 628 | SkOpSegment* other = this->isSimple(nextStart, &step); // advances nextStart |
| 629 | if (other) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 630 | // mark the smaller of startIndex, endIndex done, and all adjacent |
| 631 | // spans with the same T value (but not 'other' spans) |
| 632 | #if DEBUG_WINDING |
| 633 | SkDebugf("%s simple\n", __FUNCTION__); |
| 634 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 635 | SkOpSpan* startSpan = start->starter(end); |
| 636 | if (startSpan->done()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 637 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 638 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 639 | markDone(startSpan); |
| 640 | *nextEnd = step > 0 ? (*nextStart)->upCast()->next() : (*nextStart)->prev(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 641 | return other; |
| 642 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 643 | SkOpSpanBase* endNear = step > 0 ? (*nextStart)->upCast()->next() : (*nextStart)->prev(); |
| 644 | SkASSERT(endNear == end); // is this ever not end? |
| 645 | SkASSERT(endNear); |
| 646 | SkASSERT(start != endNear); |
| 647 | SkASSERT((start->t() < endNear->t()) ^ (step < 0)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 648 | // more than one viable candidate -- measure angles to find best |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 649 | int calcWinding = computeSum(start, endNear, SkOpAngle::kUnaryWinding); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 650 | bool sortable = calcWinding != SK_NaN32; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 651 | if (!sortable) { |
| 652 | *unsortable = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 653 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 654 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 655 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 656 | SkOpAngle* angle = this->spanToAngle(end, start); |
| 657 | if (angle->unorderable()) { |
| 658 | *unsortable = true; |
| 659 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 660 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 661 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 662 | #if DEBUG_SORT |
| 663 | SkDebugf("%s\n", __FUNCTION__); |
| 664 | angle->debugLoop(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 665 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 666 | int sumWinding = updateWinding(end, start); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 667 | SkOpAngle* nextAngle = angle->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 668 | const SkOpAngle* foundAngle = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 669 | bool foundDone = false; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 670 | // iterate through the angle, and compute everyone's winding |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 671 | SkOpSegment* nextSegment; |
| 672 | int activeCount = 0; |
| 673 | do { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 674 | nextSegment = nextAngle->segment(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 675 | bool activeAngle = nextSegment->activeWinding(nextAngle->start(), nextAngle->end(), |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 676 | &sumWinding); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 677 | if (activeAngle) { |
| 678 | ++activeCount; |
| 679 | if (!foundAngle || (foundDone && activeCount & 1)) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 680 | foundAngle = nextAngle; |
| 681 | foundDone = nextSegment->done(nextAngle); |
| 682 | } |
| 683 | } |
| 684 | if (nextSegment->done()) { |
| 685 | continue; |
| 686 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 687 | if (!activeAngle) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 688 | (void) nextSegment->markAndChaseDone(nextAngle->start(), nextAngle->end()); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 689 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 690 | SkOpSpanBase* last = nextAngle->lastMarked(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 691 | if (last) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 692 | SkASSERT(!SkPathOpsDebug::ChaseContains(*chase, last)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 693 | *chase->append() = last; |
| 694 | #if DEBUG_WINDING |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 695 | SkDebugf("%s chase.append segment=%d span=%d", __FUNCTION__, |
| 696 | last->segment()->debugID(), last->debugID()); |
| 697 | if (!last->final()) { |
| 698 | SkDebugf(" windSum=%d", last->upCast()->windSum()); |
| 699 | } |
| 700 | SkDebugf("\n"); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 701 | #endif |
| 702 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 703 | } while ((nextAngle = nextAngle->next()) != angle); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 704 | start->segment()->markDone(start->starter(end)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 705 | if (!foundAngle) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 706 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 707 | } |
| 708 | *nextStart = foundAngle->start(); |
| 709 | *nextEnd = foundAngle->end(); |
| 710 | nextSegment = foundAngle->segment(); |
| 711 | #if DEBUG_WINDING |
| 712 | SkDebugf("%s from:[%d] to:[%d] start=%d end=%d\n", |
| 713 | __FUNCTION__, debugID(), nextSegment->debugID(), *nextStart, *nextEnd); |
| 714 | #endif |
| 715 | return nextSegment; |
| 716 | } |
| 717 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 718 | SkOpSegment* SkOpSegment::findNextXor(SkOpSpanBase** nextStart, SkOpSpanBase** nextEnd, |
| 719 | bool* unsortable) { |
| 720 | SkOpSpanBase* start = *nextStart; |
| 721 | SkOpSpanBase* end = *nextEnd; |
| 722 | SkASSERT(start != end); |
| 723 | int step = start->step(end); |
| 724 | SkOpSegment* other = this->isSimple(nextStart, &step); // advances nextStart |
| 725 | if (other) { |
| 726 | // mark the smaller of startIndex, endIndex done, and all adjacent |
| 727 | // spans with the same T value (but not 'other' spans) |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 728 | #if DEBUG_WINDING |
| 729 | SkDebugf("%s simple\n", __FUNCTION__); |
| 730 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 731 | SkOpSpan* startSpan = start->starter(end); |
| 732 | if (startSpan->done()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 733 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 734 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 735 | markDone(startSpan); |
| 736 | *nextEnd = step > 0 ? (*nextStart)->upCast()->next() : (*nextStart)->prev(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 737 | return other; |
| 738 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 739 | SkDEBUGCODE(SkOpSpanBase* endNear = step > 0 ? (*nextStart)->upCast()->next() \ |
| 740 | : (*nextStart)->prev()); |
| 741 | SkASSERT(endNear == end); // is this ever not end? |
| 742 | SkASSERT(endNear); |
| 743 | SkASSERT(start != endNear); |
| 744 | SkASSERT((start->t() < endNear->t()) ^ (step < 0)); |
| 745 | SkOpAngle* angle = this->spanToAngle(end, start); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 746 | if (!angle || angle->unorderable()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 747 | *unsortable = true; |
| 748 | markDone(start->starter(end)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 749 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 750 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 751 | #if DEBUG_SORT |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 752 | SkDebugf("%s\n", __FUNCTION__); |
| 753 | angle->debugLoop(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 754 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 755 | SkOpAngle* nextAngle = angle->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 756 | const SkOpAngle* foundAngle = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 757 | bool foundDone = false; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 758 | // iterate through the angle, and compute everyone's winding |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 759 | SkOpSegment* nextSegment; |
| 760 | int activeCount = 0; |
| 761 | do { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 762 | nextSegment = nextAngle->segment(); |
| 763 | ++activeCount; |
| 764 | if (!foundAngle || (foundDone && activeCount & 1)) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 765 | foundAngle = nextAngle; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 766 | if (!(foundDone = nextSegment->done(nextAngle))) { |
| 767 | break; |
| 768 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 769 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 770 | nextAngle = nextAngle->next(); |
| 771 | } while (nextAngle != angle); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 772 | start->segment()->markDone(start->starter(end)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 773 | if (!foundAngle) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 774 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 775 | } |
| 776 | *nextStart = foundAngle->start(); |
| 777 | *nextEnd = foundAngle->end(); |
| 778 | nextSegment = foundAngle->segment(); |
| 779 | #if DEBUG_WINDING |
| 780 | SkDebugf("%s from:[%d] to:[%d] start=%d end=%d\n", |
| 781 | __FUNCTION__, debugID(), nextSegment->debugID(), *nextStart, *nextEnd); |
| 782 | #endif |
| 783 | return nextSegment; |
| 784 | } |
| 785 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 786 | SkOpGlobalState* SkOpSegment::globalState() const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 787 | return contour()->globalState(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 788 | } |
| 789 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 790 | void SkOpSegment::init(SkPoint pts[], SkScalar weight, SkOpContour* contour, SkPath::Verb verb) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 791 | fContour = contour; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 792 | fNext = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 793 | fPts = pts; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 794 | fWeight = weight; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 795 | fVerb = verb; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 796 | fCount = 0; |
| 797 | fDoneCount = 0; |
| 798 | fVisited = false; |
| 799 | SkOpSpan* zeroSpan = &fHead; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 800 | zeroSpan->init(this, nullptr, 0, fPts[0]); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 801 | SkOpSpanBase* oneSpan = &fTail; |
| 802 | zeroSpan->setNext(oneSpan); |
| 803 | oneSpan->initBase(this, zeroSpan, 1, fPts[SkPathOpsVerbToPoints(fVerb)]); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 804 | SkDEBUGCODE(fID = globalState()->nextSegmentID()); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 805 | } |
| 806 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 807 | bool SkOpSegment::isClose(double t, const SkOpSegment* opp) const { |
| 808 | SkDPoint cPt = this->dPtAtT(t); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 809 | SkDVector dxdy = (*CurveDSlopeAtT[this->verb()])(this->pts(), this->weight(), t); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 810 | SkDLine perp = {{ cPt, {cPt.fX + dxdy.fY, cPt.fY - dxdy.fX} }}; |
| 811 | SkIntersections i; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 812 | (*CurveIntersectRay[opp->verb()])(opp->pts(), opp->weight(), perp, &i); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 813 | int used = i.used(); |
| 814 | for (int index = 0; index < used; ++index) { |
| 815 | if (cPt.roughlyEqual(i.pt(index))) { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 816 | return true; |
| 817 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 818 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 819 | return false; |
| 820 | } |
| 821 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 822 | bool SkOpSegment::isXor() const { |
| 823 | return fContour->isXor(); |
| 824 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 825 | |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 826 | void SkOpSegment::markAllDone() { |
| 827 | SkOpSpan* span = this->head(); |
| 828 | do { |
| 829 | this->markDone(span); |
| 830 | } while ((span = span->next()->upCastable())); |
| 831 | } |
| 832 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 833 | SkOpSpanBase* SkOpSegment::markAndChaseDone(SkOpSpanBase* start, SkOpSpanBase* end) { |
| 834 | int step = start->step(end); |
| 835 | SkOpSpan* minSpan = start->starter(end); |
| 836 | markDone(minSpan); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 837 | SkOpSpanBase* last = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 838 | SkOpSegment* other = this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 839 | while ((other = other->nextChase(&start, &step, &minSpan, &last))) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 840 | if (other->done()) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 841 | SkASSERT(!last); |
| 842 | break; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 843 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 844 | other->markDone(minSpan); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 845 | } |
| 846 | return last; |
| 847 | } |
| 848 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 849 | bool SkOpSegment::markAndChaseWinding(SkOpSpanBase* start, SkOpSpanBase* end, int winding, |
| 850 | SkOpSpanBase** lastPtr) { |
| 851 | SkOpSpan* spanStart = start->starter(end); |
| 852 | int step = start->step(end); |
| 853 | bool success = markWinding(spanStart, winding); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 854 | SkOpSpanBase* last = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 855 | SkOpSegment* other = this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 856 | while ((other = other->nextChase(&start, &step, &spanStart, &last))) { |
| 857 | if (spanStart->windSum() != SK_MinS32) { |
| 858 | SkASSERT(spanStart->windSum() == winding); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 859 | SkASSERT(!last); |
| 860 | break; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 861 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 862 | (void) other->markWinding(spanStart, winding); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 863 | } |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 864 | if (lastPtr) { |
| 865 | *lastPtr = last; |
| 866 | } |
| 867 | return success; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 868 | } |
| 869 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 870 | bool SkOpSegment::markAndChaseWinding(SkOpSpanBase* start, SkOpSpanBase* end, |
| 871 | int winding, int oppWinding, SkOpSpanBase** lastPtr) { |
| 872 | SkOpSpan* spanStart = start->starter(end); |
| 873 | int step = start->step(end); |
| 874 | bool success = markWinding(spanStart, winding, oppWinding); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 875 | SkOpSpanBase* last = nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 876 | SkOpSegment* other = this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 877 | while ((other = other->nextChase(&start, &step, &spanStart, &last))) { |
| 878 | if (spanStart->windSum() != SK_MinS32) { |
| 879 | if (this->operand() == other->operand()) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 880 | if (spanStart->windSum() != winding || spanStart->oppSum() != oppWinding) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 881 | this->globalState()->setWindingFailed(); |
| 882 | return false; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 883 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 884 | } else { |
| 885 | SkASSERT(spanStart->windSum() == oppWinding); |
| 886 | SkASSERT(spanStart->oppSum() == winding); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 887 | } |
| 888 | SkASSERT(!last); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 889 | break; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 890 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 891 | if (this->operand() == other->operand()) { |
| 892 | (void) other->markWinding(spanStart, winding, oppWinding); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 893 | } else { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 894 | (void) other->markWinding(spanStart, oppWinding, winding); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 895 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 896 | } |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 897 | if (lastPtr) { |
| 898 | *lastPtr = last; |
| 899 | } |
| 900 | return success; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 901 | } |
| 902 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 903 | SkOpSpanBase* SkOpSegment::markAngle(int maxWinding, int sumWinding, const SkOpAngle* angle) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 904 | SkASSERT(angle->segment() == this); |
| 905 | if (UseInnerWinding(maxWinding, sumWinding)) { |
| 906 | maxWinding = sumWinding; |
| 907 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 908 | SkOpSpanBase* last; |
| 909 | (void) markAndChaseWinding(angle->start(), angle->end(), maxWinding, &last); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 910 | #if DEBUG_WINDING |
| 911 | if (last) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 912 | SkDebugf("%s last seg=%d span=%d", __FUNCTION__, |
| 913 | last->segment()->debugID(), last->debugID()); |
| 914 | if (!last->final()) { |
| 915 | SkDebugf(" windSum="); |
| 916 | SkPathOpsDebug::WindingPrintf(last->upCast()->windSum()); |
| 917 | } |
| 918 | SkDebugf("\n"); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 919 | } |
| 920 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 921 | return last; |
| 922 | } |
| 923 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 924 | SkOpSpanBase* SkOpSegment::markAngle(int maxWinding, int sumWinding, int oppMaxWinding, |
| 925 | int oppSumWinding, const SkOpAngle* angle) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 926 | SkASSERT(angle->segment() == this); |
| 927 | if (UseInnerWinding(maxWinding, sumWinding)) { |
| 928 | maxWinding = sumWinding; |
| 929 | } |
| 930 | if (oppMaxWinding != oppSumWinding && UseInnerWinding(oppMaxWinding, oppSumWinding)) { |
| 931 | oppMaxWinding = oppSumWinding; |
| 932 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 933 | SkOpSpanBase* last = nullptr; |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 934 | // caller doesn't require that this marks anything |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 935 | (void) markAndChaseWinding(angle->start(), angle->end(), maxWinding, oppMaxWinding, &last); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 936 | #if DEBUG_WINDING |
| 937 | if (last) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 938 | SkDebugf("%s last segment=%d span=%d", __FUNCTION__, |
| 939 | last->segment()->debugID(), last->debugID()); |
| 940 | if (!last->final()) { |
| 941 | SkDebugf(" windSum="); |
| 942 | SkPathOpsDebug::WindingPrintf(last->upCast()->windSum()); |
| 943 | } |
| 944 | SkDebugf(" \n"); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 945 | } |
| 946 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 947 | return last; |
| 948 | } |
| 949 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 950 | void SkOpSegment::markDone(SkOpSpan* span) { |
| 951 | SkASSERT(this == span->segment()); |
| 952 | if (span->done()) { |
| 953 | return; |
| 954 | } |
| 955 | #if DEBUG_MARK_DONE |
| 956 | debugShowNewWinding(__FUNCTION__, span, span->windSum(), span->oppSum()); |
| 957 | #endif |
| 958 | span->setDone(true); |
| 959 | ++fDoneCount; |
| 960 | debugValidate(); |
| 961 | } |
| 962 | |
| 963 | bool SkOpSegment::markWinding(SkOpSpan* span, int winding) { |
| 964 | SkASSERT(this == span->segment()); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 965 | SkASSERT(winding); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 966 | if (span->done()) { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 967 | return false; |
| 968 | } |
| 969 | #if DEBUG_MARK_DONE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 970 | debugShowNewWinding(__FUNCTION__, span, winding); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 971 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 972 | span->setWindSum(winding); |
| 973 | debugValidate(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 974 | return true; |
| 975 | } |
| 976 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 977 | bool SkOpSegment::markWinding(SkOpSpan* span, int winding, int oppWinding) { |
| 978 | SkASSERT(this == span->segment()); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 979 | SkASSERT(winding || oppWinding); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 980 | if (span->done()) { |
| 981 | return false; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 982 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 983 | #if DEBUG_MARK_DONE |
| 984 | debugShowNewWinding(__FUNCTION__, span, winding, oppWinding); |
| 985 | #endif |
| 986 | span->setWindSum(winding); |
| 987 | span->setOppSum(oppWinding); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 988 | debugValidate(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 989 | return true; |
| 990 | } |
| 991 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 992 | bool SkOpSegment::match(const SkOpPtT* base, const SkOpSegment* testParent, double testT, |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 993 | const SkPoint& testPt) const { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 994 | SkASSERT(this == base->segment()); |
| 995 | if (this == testParent) { |
| 996 | if (precisely_equal(base->fT, testT)) { |
| 997 | return true; |
| 998 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 999 | } |
| 1000 | if (!SkDPoint::ApproximatelyEqual(testPt, base->fPt)) { |
| 1001 | return false; |
| 1002 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1003 | return this != testParent || !this->ptsDisjoint(base->fT, base->fPt, testT, testPt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static SkOpSegment* set_last(SkOpSpanBase** last, SkOpSpanBase* endSpan) { |
| 1007 | if (last) { |
| 1008 | *last = endSpan; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1009 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1010 | return nullptr; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1013 | SkOpSegment* SkOpSegment::nextChase(SkOpSpanBase** startPtr, int* stepPtr, SkOpSpan** minPtr, |
| 1014 | SkOpSpanBase** last) const { |
| 1015 | SkOpSpanBase* origStart = *startPtr; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1016 | int step = *stepPtr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1017 | SkOpSpanBase* endSpan = step > 0 ? origStart->upCast()->next() : origStart->prev(); |
| 1018 | SkASSERT(endSpan); |
| 1019 | SkOpAngle* angle = step > 0 ? endSpan->fromAngle() : endSpan->upCast()->toAngle(); |
| 1020 | SkOpSpanBase* foundSpan; |
| 1021 | SkOpSpanBase* otherEnd; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1022 | SkOpSegment* other; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1023 | if (angle == nullptr) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1024 | if (endSpan->t() != 0 && endSpan->t() != 1) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1025 | return nullptr; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1026 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1027 | SkOpPtT* otherPtT = endSpan->ptT()->next(); |
| 1028 | other = otherPtT->segment(); |
| 1029 | foundSpan = otherPtT->span(); |
caryclark | 343382e | 2016-06-29 08:18:38 -0700 | [diff] [blame] | 1030 | otherEnd = step > 0 |
| 1031 | ? foundSpan->upCastable() ? foundSpan->upCast()->next() : nullptr |
| 1032 | : foundSpan->prev(); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1033 | } else { |
| 1034 | int loopCount = angle->loopCount(); |
| 1035 | if (loopCount > 2) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1036 | return set_last(last, endSpan); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1037 | } |
| 1038 | const SkOpAngle* next = angle->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1039 | if (nullptr == next) { |
| 1040 | return nullptr; |
caryclark | 65b427c | 2014-09-18 10:32:57 -0700 | [diff] [blame] | 1041 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1042 | #if DEBUG_WINDING |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1043 | if (angle->debugSign() != next->debugSign() && !angle->segment()->contour()->isXor() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1044 | && !next->segment()->contour()->isXor()) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1045 | SkDebugf("%s mismatched signs\n", __FUNCTION__); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1046 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1047 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1048 | other = next->segment(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1049 | foundSpan = endSpan = next->start(); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1050 | otherEnd = next->end(); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1051 | } |
caryclark | 343382e | 2016-06-29 08:18:38 -0700 | [diff] [blame] | 1052 | if (!otherEnd) { |
| 1053 | return nullptr; |
| 1054 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1055 | int foundStep = foundSpan->step(otherEnd); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1056 | if (*stepPtr != foundStep) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1057 | return set_last(last, endSpan); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1058 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1059 | SkASSERT(*startPtr); |
| 1060 | if (!otherEnd) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1061 | return nullptr; |
caryclark | 65b427c | 2014-09-18 10:32:57 -0700 | [diff] [blame] | 1062 | } |
| 1063 | // SkASSERT(otherEnd >= 0); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1064 | SkOpSpan* origMin = step < 0 ? origStart->prev() : origStart->upCast(); |
| 1065 | SkOpSpan* foundMin = foundSpan->starter(otherEnd); |
| 1066 | if (foundMin->windValue() != origMin->windValue() |
| 1067 | || foundMin->oppValue() != origMin->oppValue()) { |
| 1068 | return set_last(last, endSpan); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1069 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1070 | *startPtr = foundSpan; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1071 | *stepPtr = foundStep; |
| 1072 | if (minPtr) { |
| 1073 | *minPtr = foundMin; |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 1074 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1075 | return other; |
| 1076 | } |
| 1077 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1078 | // Please keep this in sync with DebugClearVisited() |
| 1079 | void SkOpSegment::ClearVisited(SkOpSpanBase* span) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1080 | // reset visited flag back to false |
| 1081 | do { |
| 1082 | SkOpPtT* ptT = span->ptT(), * stopPtT = ptT; |
| 1083 | while ((ptT = ptT->next()) != stopPtT) { |
| 1084 | SkOpSegment* opp = ptT->segment(); |
| 1085 | opp->resetVisited(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1086 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1087 | } while (!span->final() && (span = span->upCast()->next())); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1090 | // Please keep this in sync with debugMissingCoincidence() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1091 | // look for pairs of undetected coincident curves |
| 1092 | // assumes that segments going in have visited flag clear |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1093 | // Even though pairs of curves correct detect coincident runs, a run may be missed |
| 1094 | // if the coincidence is a product of multiple intersections. For instance, given |
| 1095 | // curves A, B, and C: |
| 1096 | // A-B intersect at a point 1; A-C and B-C intersect at point 2, so near |
| 1097 | // the end of C that the intersection is replaced with the end of C. |
| 1098 | // Even though A-B correctly do not detect an intersection at point 2, |
| 1099 | // the resulting run from point 1 to point 2 is coincident on A and B. |
| 1100 | bool SkOpSegment::missingCoincidence() { |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1101 | if (this->done()) { |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1102 | return false; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1103 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1104 | SkOpSpan* prior = nullptr; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1105 | SkOpSpanBase* spanBase = &fHead; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1106 | bool result = false; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1107 | do { |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1108 | SkOpPtT* ptT = spanBase->ptT(), * spanStopPtT = ptT; |
caryclark | c6d855f | 2016-08-11 11:59:48 -0700 | [diff] [blame] | 1109 | SkOPASSERT(ptT->span() == spanBase); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1110 | while ((ptT = ptT->next()) != spanStopPtT) { |
caryclark | 182b499 | 2015-05-14 05:45:54 -0700 | [diff] [blame] | 1111 | if (ptT->deleted()) { |
| 1112 | continue; |
| 1113 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1114 | SkOpSegment* opp = ptT->span()->segment(); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1115 | if (opp->done()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1116 | continue; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1117 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1118 | // when opp is encounted the 1st time, continue; on 2nd encounter, look for coincidence |
| 1119 | if (!opp->visited()) { |
| 1120 | continue; |
| 1121 | } |
| 1122 | if (spanBase == &fHead) { |
| 1123 | continue; |
| 1124 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1125 | if (ptT->segment() == this) { |
| 1126 | continue; |
| 1127 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1128 | SkOpSpan* span = spanBase->upCastable(); |
| 1129 | // FIXME?: this assumes that if the opposite segment is coincident then no more |
| 1130 | // coincidence needs to be detected. This may not be true. |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1131 | if (span && span->containsCoincidence(opp)) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1132 | continue; |
| 1133 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1134 | if (spanBase->containsCoinEnd(opp)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1135 | continue; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1136 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1137 | SkOpPtT* priorPtT = nullptr, * priorStopPtT; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1138 | // find prior span containing opp segment |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1139 | SkOpSegment* priorOpp = nullptr; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1140 | SkOpSpan* priorTest = spanBase->prev(); |
| 1141 | while (!priorOpp && priorTest) { |
| 1142 | priorStopPtT = priorPtT = priorTest->ptT(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1143 | while ((priorPtT = priorPtT->next()) != priorStopPtT) { |
caryclark | 182b499 | 2015-05-14 05:45:54 -0700 | [diff] [blame] | 1144 | if (priorPtT->deleted()) { |
| 1145 | continue; |
| 1146 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1147 | SkOpSegment* segment = priorPtT->span()->segment(); |
| 1148 | if (segment == opp) { |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1149 | prior = priorTest; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1150 | priorOpp = opp; |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1154 | priorTest = priorTest->prev(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1155 | } |
| 1156 | if (!priorOpp) { |
| 1157 | continue; |
| 1158 | } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 1159 | if (priorPtT == ptT) { |
| 1160 | continue; |
| 1161 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1162 | SkOpPtT* oppStart = prior->ptT(); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1163 | SkOpPtT* oppEnd = spanBase->ptT(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1164 | bool swapped = priorPtT->fT > ptT->fT; |
| 1165 | if (swapped) { |
| 1166 | SkTSwap(priorPtT, ptT); |
| 1167 | SkTSwap(oppStart, oppEnd); |
| 1168 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1169 | SkOpCoincidence* coincidences = this->globalState()->coincidence(); |
| 1170 | SkOpPtT* rootPriorPtT = priorPtT->span()->ptT(); |
| 1171 | SkOpPtT* rootPtT = ptT->span()->ptT(); |
| 1172 | SkOpPtT* rootOppStart = oppStart->span()->ptT(); |
| 1173 | SkOpPtT* rootOppEnd = oppEnd->span()->ptT(); |
| 1174 | if (coincidences->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1175 | goto swapBack; |
| 1176 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1177 | if (this->testForCoincidence(rootPriorPtT, rootPtT, prior, spanBase, opp)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1178 | // mark coincidence |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1179 | #if DEBUG_COINCIDENCE_VERBOSE |
| 1180 | SkDebugf("%s coinSpan=%d endSpan=%d oppSpan=%d oppEndSpan=%d\n", __FUNCTION__, |
| 1181 | rootPriorPtT->debugID(), rootPtT->debugID(), rootOppStart->debugID(), |
| 1182 | rootOppEnd->debugID()); |
| 1183 | #endif |
| 1184 | if (!coincidences->extend(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd)) { |
| 1185 | coincidences->add(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1186 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1187 | #if DEBUG_COINCIDENCE |
| 1188 | SkASSERT(coincidences->contains(rootPriorPtT, rootPtT, rootOppStart, rootOppEnd)); |
| 1189 | #endif |
| 1190 | result = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1191 | } |
| 1192 | swapBack: |
| 1193 | if (swapped) { |
| 1194 | SkTSwap(priorPtT, ptT); |
| 1195 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1196 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1197 | } while ((spanBase = spanBase->final() ? nullptr : spanBase->upCast()->next())); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1198 | ClearVisited(&fHead); |
| 1199 | return result; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1202 | // please keep this in sync with debugMoveMultiples() |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1203 | // if a span has more than one intersection, merge the other segments' span as needed |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 1204 | bool SkOpSegment::moveMultiples() { |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1205 | debugValidate(); |
| 1206 | SkOpSpanBase* test = &fHead; |
| 1207 | do { |
| 1208 | int addCount = test->spanAddsCount(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1209 | FAIL_IF(addCount < 1); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1210 | if (addCount == 1) { |
| 1211 | continue; |
| 1212 | } |
| 1213 | SkOpPtT* startPtT = test->ptT(); |
| 1214 | SkOpPtT* testPtT = startPtT; |
| 1215 | do { // iterate through all spans associated with start |
| 1216 | SkOpSpanBase* oppSpan = testPtT->span(); |
| 1217 | if (oppSpan->spanAddsCount() == addCount) { |
| 1218 | continue; |
| 1219 | } |
| 1220 | if (oppSpan->deleted()) { |
| 1221 | continue; |
| 1222 | } |
| 1223 | SkOpSegment* oppSegment = oppSpan->segment(); |
| 1224 | if (oppSegment == this) { |
| 1225 | continue; |
| 1226 | } |
| 1227 | // find range of spans to consider merging |
| 1228 | SkOpSpanBase* oppPrev = oppSpan; |
| 1229 | SkOpSpanBase* oppFirst = oppSpan; |
| 1230 | while ((oppPrev = oppPrev->prev())) { |
| 1231 | if (!roughly_equal(oppPrev->t(), oppSpan->t())) { |
| 1232 | break; |
| 1233 | } |
| 1234 | if (oppPrev->spanAddsCount() == addCount) { |
| 1235 | continue; |
| 1236 | } |
| 1237 | if (oppPrev->deleted()) { |
| 1238 | continue; |
| 1239 | } |
| 1240 | oppFirst = oppPrev; |
| 1241 | } |
| 1242 | SkOpSpanBase* oppNext = oppSpan; |
| 1243 | SkOpSpanBase* oppLast = oppSpan; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1244 | while ((oppNext = oppNext->final() ? nullptr : oppNext->upCast()->next())) { |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1245 | if (!roughly_equal(oppNext->t(), oppSpan->t())) { |
| 1246 | break; |
| 1247 | } |
| 1248 | if (oppNext->spanAddsCount() == addCount) { |
| 1249 | continue; |
| 1250 | } |
| 1251 | if (oppNext->deleted()) { |
| 1252 | continue; |
| 1253 | } |
| 1254 | oppLast = oppNext; |
| 1255 | } |
| 1256 | if (oppFirst == oppLast) { |
| 1257 | continue; |
| 1258 | } |
| 1259 | SkOpSpanBase* oppTest = oppFirst; |
| 1260 | do { |
| 1261 | if (oppTest == oppSpan) { |
| 1262 | continue; |
| 1263 | } |
| 1264 | // check to see if the candidate meets specific criteria: |
| 1265 | // it contains spans of segments in test's loop but not including 'this' |
| 1266 | SkOpPtT* oppStartPtT = oppTest->ptT(); |
| 1267 | SkOpPtT* oppPtT = oppStartPtT; |
| 1268 | while ((oppPtT = oppPtT->next()) != oppStartPtT) { |
| 1269 | SkOpSegment* oppPtTSegment = oppPtT->segment(); |
| 1270 | if (oppPtTSegment == this) { |
| 1271 | goto tryNextSpan; |
| 1272 | } |
| 1273 | SkOpPtT* matchPtT = startPtT; |
| 1274 | do { |
| 1275 | if (matchPtT->segment() == oppPtTSegment) { |
| 1276 | goto foundMatch; |
| 1277 | } |
| 1278 | } while ((matchPtT = matchPtT->next()) != startPtT); |
| 1279 | goto tryNextSpan; |
| 1280 | foundMatch: // merge oppTest and oppSpan |
| 1281 | oppSegment->debugValidate(); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1282 | oppTest->mergeMatches(oppSpan); |
| 1283 | oppTest->addOpp(oppSpan); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1284 | oppSegment->debugValidate(); |
| 1285 | goto checkNextSpan; |
| 1286 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1287 | tryNextSpan: |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1288 | ; |
| 1289 | } while (oppTest != oppLast && (oppTest = oppTest->upCast()->next())); |
| 1290 | } while ((testPtT = testPtT->next()) != startPtT); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1291 | checkNextSpan: |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1292 | ; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1293 | } while ((test = test->final() ? nullptr : test->upCast()->next())); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1294 | debugValidate(); |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 1295 | return true; |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1298 | // adjacent spans may have points close by |
| 1299 | bool SkOpSegment::spansNearby(const SkOpSpanBase* refSpan, const SkOpSpanBase* checkSpan) const { |
| 1300 | const SkOpPtT* refHead = refSpan->ptT(); |
| 1301 | const SkOpPtT* checkHead = checkSpan->ptT(); |
| 1302 | // if the first pt pair from adjacent spans are far apart, assume that all are far enough apart |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1303 | if (!SkDPoint::WayRoughlyEqual(refHead->fPt, checkHead->fPt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1304 | #if DEBUG_COINCIDENCE |
| 1305 | // verify that no combination of points are close |
| 1306 | const SkOpPtT* dBugRef = refHead; |
| 1307 | do { |
| 1308 | const SkOpPtT* dBugCheck = checkHead; |
| 1309 | do { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1310 | SkOPASSERT(!SkDPoint::ApproximatelyEqual(dBugRef->fPt, dBugCheck->fPt)); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1311 | dBugCheck = dBugCheck->next(); |
| 1312 | } while (dBugCheck != checkHead); |
| 1313 | dBugRef = dBugRef->next(); |
| 1314 | } while (dBugRef != refHead); |
| 1315 | #endif |
| 1316 | return false; |
| 1317 | } |
| 1318 | // check only unique points |
| 1319 | SkScalar distSqBest = SK_ScalarMax; |
| 1320 | const SkOpPtT* refBest = nullptr; |
| 1321 | const SkOpPtT* checkBest = nullptr; |
| 1322 | const SkOpPtT* ref = refHead; |
| 1323 | do { |
| 1324 | if (ref->deleted()) { |
| 1325 | continue; |
| 1326 | } |
| 1327 | while (ref->ptAlreadySeen(refHead)) { |
| 1328 | ref = ref->next(); |
| 1329 | if (ref == refHead) { |
| 1330 | goto doneCheckingDistance; |
| 1331 | } |
| 1332 | } |
| 1333 | const SkOpPtT* check = checkHead; |
| 1334 | const SkOpSegment* refSeg = ref->segment(); |
| 1335 | do { |
| 1336 | if (check->deleted()) { |
| 1337 | continue; |
| 1338 | } |
| 1339 | while (check->ptAlreadySeen(checkHead)) { |
| 1340 | check = check->next(); |
| 1341 | if (check == checkHead) { |
| 1342 | goto nextRef; |
| 1343 | } |
| 1344 | } |
| 1345 | SkScalar distSq = ref->fPt.distanceToSqd(check->fPt); |
| 1346 | if (distSqBest > distSq && (refSeg != check->segment() |
| 1347 | || !refSeg->ptsDisjoint(*ref, *check))) { |
| 1348 | distSqBest = distSq; |
| 1349 | refBest = ref; |
| 1350 | checkBest = check; |
| 1351 | } |
| 1352 | } while ((check = check->next()) != checkHead); |
| 1353 | nextRef: |
| 1354 | ; |
| 1355 | } while ((ref = ref->next()) != refHead); |
| 1356 | doneCheckingDistance: |
| 1357 | return checkBest && refBest->segment()->match(refBest, checkBest->segment(), checkBest->fT, |
caryclark | ef4f32a | 2016-08-24 09:24:18 -0700 | [diff] [blame] | 1358 | checkBest->fPt); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | // Please keep this function in sync with debugMoveNearby() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1362 | // Move nearby t values and pts so they all hang off the same span. Alignment happens later. |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 1363 | void SkOpSegment::moveNearby() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1364 | debugValidate(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1365 | // release undeleted spans pointing to this seg that are linked to the primary span |
| 1366 | SkOpSpanBase* spanBase = &fHead; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1367 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1368 | SkOpPtT* ptT = spanBase->ptT(); |
| 1369 | const SkOpPtT* headPtT = ptT; |
| 1370 | while ((ptT = ptT->next()) != headPtT) { |
| 1371 | SkOpSpanBase* test = ptT->span(); |
| 1372 | if (ptT->segment() == this && !ptT->deleted() && test != spanBase |
| 1373 | && test->ptT() == ptT) { |
| 1374 | if (test->final()) { |
| 1375 | if (spanBase == &fHead) { |
| 1376 | this->clearAll(); |
| 1377 | return; |
| 1378 | } |
| 1379 | spanBase->upCast()->release(ptT); |
| 1380 | } else if (test->prev()) { |
| 1381 | test->upCast()->release(headPtT); |
| 1382 | } |
| 1383 | break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1384 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1385 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1386 | spanBase = spanBase->upCast()->next(); |
| 1387 | } while (!spanBase->final()); |
| 1388 | |
| 1389 | // This loop looks for adjacent spans which are near by |
| 1390 | spanBase = &fHead; |
| 1391 | do { // iterate through all spans associated with start |
| 1392 | SkOpSpanBase* test = spanBase->upCast()->next(); |
| 1393 | if (this->spansNearby(spanBase, test)) { |
| 1394 | if (test->final()) { |
| 1395 | if (spanBase->prev()) { |
| 1396 | test->merge(spanBase->upCast()); |
| 1397 | } else { |
| 1398 | this->clearAll(); |
| 1399 | return; |
| 1400 | } |
| 1401 | } else { |
| 1402 | spanBase->merge(test->upCast()); |
| 1403 | } |
| 1404 | } |
| 1405 | spanBase = test; |
| 1406 | } while (!spanBase->final()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1407 | debugValidate(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1410 | bool SkOpSegment::operand() const { |
| 1411 | return fContour->operand(); |
| 1412 | } |
| 1413 | |
| 1414 | bool SkOpSegment::oppXor() const { |
| 1415 | return fContour->oppXor(); |
| 1416 | } |
| 1417 | |
| 1418 | bool SkOpSegment::ptsDisjoint(double t1, const SkPoint& pt1, double t2, const SkPoint& pt2) const { |
| 1419 | if (fVerb == SkPath::kLine_Verb) { |
| 1420 | return false; |
| 1421 | } |
| 1422 | // quads (and cubics) can loop back to nearly a line so that an opposite curve |
| 1423 | // hits in two places with very different t values. |
| 1424 | // OPTIMIZATION: curves could be preflighted so that, for example, something like |
| 1425 | // 'controls contained by ends' could avoid this check for common curves |
| 1426 | // 'ends are extremes in x or y' is cheaper to compute and real-world common |
| 1427 | // on the other hand, the below check is relatively inexpensive |
| 1428 | double midT = (t1 + t2) / 2; |
| 1429 | SkPoint midPt = this->ptAtT(midT); |
| 1430 | double seDistSq = SkTMax(pt1.distanceToSqd(pt2) * 2, FLT_EPSILON * 2); |
| 1431 | return midPt.distanceToSqd(pt1) > seDistSq || midPt.distanceToSqd(pt2) > seDistSq; |
| 1432 | } |
| 1433 | |
| 1434 | void SkOpSegment::setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding, |
| 1435 | int* maxWinding, int* sumWinding) { |
| 1436 | int deltaSum = SpanSign(start, end); |
| 1437 | *maxWinding = *sumMiWinding; |
| 1438 | *sumWinding = *sumMiWinding -= deltaSum; |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 1439 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(*sumWinding) <= DEBUG_LIMIT_WIND_SUM); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | void SkOpSegment::setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding, |
| 1443 | int* sumSuWinding, int* maxWinding, int* sumWinding, int* oppMaxWinding, |
| 1444 | int* oppSumWinding) { |
| 1445 | int deltaSum = SpanSign(start, end); |
| 1446 | int oppDeltaSum = OppSign(start, end); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1447 | if (operand()) { |
| 1448 | *maxWinding = *sumSuWinding; |
| 1449 | *sumWinding = *sumSuWinding -= deltaSum; |
| 1450 | *oppMaxWinding = *sumMiWinding; |
| 1451 | *oppSumWinding = *sumMiWinding -= oppDeltaSum; |
| 1452 | } else { |
| 1453 | *maxWinding = *sumMiWinding; |
| 1454 | *sumWinding = *sumMiWinding -= deltaSum; |
| 1455 | *oppMaxWinding = *sumSuWinding; |
| 1456 | *oppSumWinding = *sumSuWinding -= oppDeltaSum; |
| 1457 | } |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 1458 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(*sumWinding) <= DEBUG_LIMIT_WIND_SUM); |
| 1459 | SkASSERT(!DEBUG_LIMIT_WIND_SUM || SkTAbs(*oppSumWinding) <= DEBUG_LIMIT_WIND_SUM); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1462 | void SkOpSegment::sortAngles() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1463 | SkOpSpanBase* span = &this->fHead; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1464 | do { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1465 | SkOpAngle* fromAngle = span->fromAngle(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1466 | SkOpAngle* toAngle = span->final() ? nullptr : span->upCast()->toAngle(); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1467 | if (!fromAngle && !toAngle) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1468 | continue; |
| 1469 | } |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1470 | #if DEBUG_ANGLE |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1471 | bool wroteAfterHeader = false; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1472 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1473 | SkOpAngle* baseAngle = fromAngle; |
| 1474 | if (fromAngle && toAngle) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1475 | #if DEBUG_ANGLE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1476 | SkDebugf("%s [%d] tStart=%1.9g [%d]\n", __FUNCTION__, debugID(), span->t(), |
| 1477 | span->debugID()); |
| 1478 | wroteAfterHeader = true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1479 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1480 | fromAngle->insert(toAngle); |
| 1481 | } else if (!fromAngle) { |
| 1482 | baseAngle = toAngle; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1483 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1484 | SkOpPtT* ptT = span->ptT(), * stopPtT = ptT; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1485 | do { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1486 | SkOpSpanBase* oSpan = ptT->span(); |
| 1487 | if (oSpan == span) { |
| 1488 | continue; |
| 1489 | } |
| 1490 | SkOpAngle* oAngle = oSpan->fromAngle(); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 1491 | if (oAngle) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1492 | #if DEBUG_ANGLE |
| 1493 | if (!wroteAfterHeader) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1494 | SkDebugf("%s [%d] tStart=%1.9g [%d]\n", __FUNCTION__, debugID(), |
| 1495 | span->t(), span->debugID()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1496 | wroteAfterHeader = true; |
| 1497 | } |
| 1498 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1499 | if (!oAngle->loopContains(baseAngle)) { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1500 | baseAngle->insert(oAngle); |
| 1501 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1502 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1503 | if (!oSpan->final()) { |
| 1504 | oAngle = oSpan->upCast()->toAngle(); |
| 1505 | if (oAngle) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1506 | #if DEBUG_ANGLE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1507 | if (!wroteAfterHeader) { |
| 1508 | SkDebugf("%s [%d] tStart=%1.9g [%d]\n", __FUNCTION__, debugID(), |
| 1509 | span->t(), span->debugID()); |
| 1510 | wroteAfterHeader = true; |
| 1511 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1512 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1513 | if (!oAngle->loopContains(baseAngle)) { |
| 1514 | baseAngle->insert(oAngle); |
| 1515 | } |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1516 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1517 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1518 | } while ((ptT = ptT->next()) != stopPtT); |
| 1519 | if (baseAngle->loopCount() == 1) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1520 | span->setFromAngle(nullptr); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1521 | if (toAngle) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1522 | span->upCast()->setToAngle(nullptr); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1523 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1524 | baseAngle = nullptr; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1525 | } |
| 1526 | #if DEBUG_SORT |
| 1527 | SkASSERT(!baseAngle || baseAngle->loopCount() > 1); |
| 1528 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1529 | } while (!span->final() && (span = span->upCast()->next())); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1532 | bool SkOpSegment::subDivide(const SkOpSpanBase* start, const SkOpSpanBase* end, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1533 | SkDCurve* edge) const { |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1534 | SkASSERT(start != end); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1535 | const SkOpPtT& startPtT = *start->ptT(); |
| 1536 | const SkOpPtT& endPtT = *end->ptT(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1537 | SkDEBUGCODE(edge->fVerb = fVerb); |
| 1538 | edge->fCubic[0].set(startPtT.fPt); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1539 | int points = SkPathOpsVerbToPoints(fVerb); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1540 | edge->fCubic[points].set(endPtT.fPt); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1541 | if (fVerb == SkPath::kLine_Verb) { |
| 1542 | return false; |
| 1543 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1544 | double startT = startPtT.fT; |
| 1545 | double endT = endPtT.fT; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1546 | if ((startT == 0 || endT == 0) && (startT == 1 || endT == 1)) { |
| 1547 | // don't compute midpoints if we already have them |
| 1548 | if (fVerb == SkPath::kQuad_Verb) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1549 | edge->fLine[1].set(fPts[1]); |
| 1550 | return false; |
| 1551 | } |
| 1552 | if (fVerb == SkPath::kConic_Verb) { |
| 1553 | edge->fConic[1].set(fPts[1]); |
| 1554 | edge->fConic.fWeight = fWeight; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
| 1557 | SkASSERT(fVerb == SkPath::kCubic_Verb); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1558 | if (startT == 0) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1559 | edge->fCubic[1].set(fPts[1]); |
| 1560 | edge->fCubic[2].set(fPts[2]); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1561 | return false; |
| 1562 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1563 | edge->fCubic[1].set(fPts[2]); |
| 1564 | edge->fCubic[2].set(fPts[1]); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1565 | return false; |
| 1566 | } |
| 1567 | if (fVerb == SkPath::kQuad_Verb) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1568 | edge->fQuad[1] = SkDQuad::SubDivide(fPts, edge->fQuad[0], edge->fQuad[2], startT, endT); |
| 1569 | } else if (fVerb == SkPath::kConic_Verb) { |
| 1570 | edge->fConic[1] = SkDConic::SubDivide(fPts, fWeight, edge->fQuad[0], edge->fQuad[2], |
| 1571 | startT, endT, &edge->fConic.fWeight); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1572 | } else { |
| 1573 | SkASSERT(fVerb == SkPath::kCubic_Verb); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1574 | SkDCubic::SubDivide(fPts, edge->fCubic[0], edge->fCubic[3], startT, endT, &edge->fCubic[1]); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1575 | } |
| 1576 | return true; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1579 | bool SkOpSegment::testForCoincidence(const SkOpPtT* priorPtT, const SkOpPtT* ptT, |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1580 | const SkOpSpanBase* prior, const SkOpSpanBase* spanBase, const SkOpSegment* opp) const { |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1581 | // average t, find mid pt |
| 1582 | double midT = (prior->t() + spanBase->t()) / 2; |
| 1583 | SkPoint midPt = this->ptAtT(midT); |
| 1584 | bool coincident = true; |
| 1585 | // if the mid pt is not near either end pt, project perpendicular through opp seg |
| 1586 | if (!SkDPoint::ApproximatelyEqual(priorPtT->fPt, midPt) |
| 1587 | && !SkDPoint::ApproximatelyEqual(ptT->fPt, midPt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1588 | if (priorPtT->span() == ptT->span()) { |
| 1589 | return false; |
| 1590 | } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1591 | coincident = false; |
| 1592 | SkIntersections i; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1593 | SkDCurve curvePart; |
| 1594 | this->subDivide(prior, spanBase, &curvePart); |
| 1595 | SkDVector dxdy = (*CurveDDSlopeAtT[fVerb])(curvePart, 0.5f); |
| 1596 | SkDPoint partMidPt = (*CurveDDPointAtT[fVerb])(curvePart, 0.5f); |
| 1597 | SkDLine ray = {{{midPt.fX, midPt.fY}, {partMidPt.fX + dxdy.fY, partMidPt.fY - dxdy.fX}}}; |
| 1598 | SkDCurve oppPart; |
| 1599 | opp->subDivide(priorPtT->span(), ptT->span(), &oppPart); |
| 1600 | (*CurveDIntersectRay[opp->verb()])(oppPart, ray, &i); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1601 | // measure distance and see if it's small enough to denote coincidence |
| 1602 | for (int index = 0; index < i.used(); ++index) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1603 | if (!between(0, i[0][index], 1)) { |
| 1604 | continue; |
| 1605 | } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1606 | SkDPoint oppPt = i.pt(index); |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 1607 | if (oppPt.approximatelyDEqual(midPt)) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1608 | // the coincidence can occur at almost any angle |
| 1609 | coincident = true; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | return coincident; |
| 1614 | } |
| 1615 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1616 | void SkOpSegment::undoneSpan(SkOpSpanBase** start, SkOpSpanBase** end) { |
| 1617 | SkOpSpan* span = this->head(); |
| 1618 | do { |
| 1619 | if (!span->done()) { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1620 | break; |
| 1621 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1622 | } while ((span = span->next()->upCastable())); |
| 1623 | SkASSERT(span); |
| 1624 | *start = span; |
| 1625 | *end = span->next(); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1628 | int SkOpSegment::updateOppWinding(const SkOpSpanBase* start, const SkOpSpanBase* end) const { |
| 1629 | const SkOpSpan* lesser = start->starter(end); |
| 1630 | int oppWinding = lesser->oppSum(); |
| 1631 | int oppSpanWinding = SkOpSegment::OppSign(start, end); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1632 | if (oppSpanWinding && UseInnerWinding(oppWinding - oppSpanWinding, oppWinding) |
| 1633 | && oppWinding != SK_MaxS32) { |
| 1634 | oppWinding -= oppSpanWinding; |
| 1635 | } |
| 1636 | return oppWinding; |
| 1637 | } |
| 1638 | |
| 1639 | int SkOpSegment::updateOppWinding(const SkOpAngle* angle) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1640 | const SkOpSpanBase* startSpan = angle->start(); |
| 1641 | const SkOpSpanBase* endSpan = angle->end(); |
| 1642 | return updateOppWinding(endSpan, startSpan); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | int SkOpSegment::updateOppWindingReverse(const SkOpAngle* angle) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1646 | const SkOpSpanBase* startSpan = angle->start(); |
| 1647 | const SkOpSpanBase* endSpan = angle->end(); |
| 1648 | return updateOppWinding(startSpan, endSpan); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1651 | int SkOpSegment::updateWinding(SkOpSpanBase* start, SkOpSpanBase* end) { |
| 1652 | SkOpSpan* lesser = start->starter(end); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1653 | int winding = lesser->windSum(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1654 | if (winding == SK_MinS32) { |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 1655 | winding = lesser->computeWindSum(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1656 | } |
| 1657 | if (winding == SK_MinS32) { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1658 | return winding; |
| 1659 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1660 | int spanWinding = SkOpSegment::SpanSign(start, end); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1661 | if (winding && UseInnerWinding(winding - spanWinding, winding) |
| 1662 | && winding != SK_MaxS32) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1663 | winding -= spanWinding; |
| 1664 | } |
| 1665 | return winding; |
| 1666 | } |
| 1667 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1668 | int SkOpSegment::updateWinding(SkOpAngle* angle) { |
| 1669 | SkOpSpanBase* startSpan = angle->start(); |
| 1670 | SkOpSpanBase* endSpan = angle->end(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1671 | return updateWinding(endSpan, startSpan); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 1674 | int SkOpSegment::updateWindingReverse(const SkOpAngle* angle) { |
| 1675 | SkOpSpanBase* startSpan = angle->start(); |
| 1676 | SkOpSpanBase* endSpan = angle->end(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1677 | return updateWinding(startSpan, endSpan); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | // OPTIMIZATION: does the following also work, and is it any faster? |
| 1681 | // return outerWinding * innerWinding > 0 |
| 1682 | // || ((outerWinding + innerWinding < 0) ^ ((outerWinding - innerWinding) < 0))) |
| 1683 | bool SkOpSegment::UseInnerWinding(int outerWinding, int innerWinding) { |
| 1684 | SkASSERT(outerWinding != SK_MaxS32); |
| 1685 | SkASSERT(innerWinding != SK_MaxS32); |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 1686 | int absOut = SkTAbs(outerWinding); |
| 1687 | int absIn = SkTAbs(innerWinding); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1688 | bool result = absOut == absIn ? outerWinding < 0 : absOut < absIn; |
| 1689 | return result; |
| 1690 | } |
| 1691 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1692 | int SkOpSegment::windSum(const SkOpAngle* angle) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1693 | const SkOpSpan* minSpan = angle->start()->starter(angle->end()); |
| 1694 | return minSpan->windSum(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1695 | } |