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