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