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