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