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 | */ |
Hal Canary | 50dbc09 | 2018-06-12 14:50:37 -0400 | [diff] [blame] | 7 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 8 | #include "SkAddIntersections.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 9 | #include "SkOpCoincidence.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 10 | #include "SkOpEdgeBuilder.h" |
Hal Canary | 50dbc09 | 2018-06-12 14:50:37 -0400 | [diff] [blame] | 11 | #include "SkMacros.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | #include "SkPathOpsCommon.h" |
| 13 | #include "SkPathWriter.h" |
commit-bot@chromium.org | b76d3b6 | 2013-04-22 19:55:19 +0000 | [diff] [blame] | 14 | #include "SkTSort.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 15 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 16 | SkScalar ScaleFactor(const SkPath& path) { |
| 17 | static const SkScalar twoTo10 = 1024.f; |
| 18 | SkScalar largest = 0; |
| 19 | const SkScalar* oneBounds = &path.getBounds().fLeft; |
| 20 | for (int index = 0; index < 4; ++index) { |
| 21 | largest = SkTMax(largest, SkScalarAbs(oneBounds[index])); |
| 22 | } |
| 23 | SkScalar scale = twoTo10; |
| 24 | SkScalar next; |
| 25 | while ((next = scale * twoTo10) < largest) { |
| 26 | scale = next; |
| 27 | } |
| 28 | return scale == twoTo10 ? SK_Scalar1 : scale; |
| 29 | } |
| 30 | |
| 31 | void ScalePath(const SkPath& path, SkScalar scale, SkPath* scaled) { |
| 32 | SkMatrix matrix; |
| 33 | matrix.setScale(scale, scale); |
| 34 | *scaled = path; |
| 35 | scaled->transform(matrix); |
| 36 | } |
| 37 | |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 38 | const SkOpAngle* AngleWinding(SkOpSpanBase* start, SkOpSpanBase* end, int* windingPtr, |
| 39 | bool* sortablePtr) { |
| 40 | // find first angle, initialize winding to computed fWindSum |
| 41 | SkOpSegment* segment = start->segment(); |
| 42 | const SkOpAngle* angle = segment->spanToAngle(start, end); |
| 43 | if (!angle) { |
| 44 | *windingPtr = SK_MinS32; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 45 | return nullptr; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 46 | } |
| 47 | bool computeWinding = false; |
| 48 | const SkOpAngle* firstAngle = angle; |
| 49 | bool loop = false; |
| 50 | bool unorderable = false; |
| 51 | int winding = SK_MinS32; |
| 52 | do { |
| 53 | angle = angle->next(); |
caryclark | aa7ceb6 | 2016-06-29 10:46:08 -0700 | [diff] [blame] | 54 | if (!angle) { |
| 55 | return nullptr; |
| 56 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 57 | unorderable |= angle->unorderable(); |
| 58 | if ((computeWinding = unorderable || (angle == firstAngle && loop))) { |
| 59 | break; // if we get here, there's no winding, loop is unorderable |
| 60 | } |
| 61 | loop |= angle == firstAngle; |
| 62 | segment = angle->segment(); |
| 63 | winding = segment->windSum(angle); |
| 64 | } while (winding == SK_MinS32); |
| 65 | // if the angle loop contains an unorderable span, the angle order may be useless |
| 66 | // directly compute the winding in this case for each span |
| 67 | if (computeWinding) { |
| 68 | firstAngle = angle; |
| 69 | winding = SK_MinS32; |
| 70 | do { |
| 71 | SkOpSpanBase* startSpan = angle->start(); |
| 72 | SkOpSpanBase* endSpan = angle->end(); |
| 73 | SkOpSpan* lesser = startSpan->starter(endSpan); |
| 74 | int testWinding = lesser->windSum(); |
| 75 | if (testWinding == SK_MinS32) { |
| 76 | testWinding = lesser->computeWindSum(); |
| 77 | } |
| 78 | if (testWinding != SK_MinS32) { |
| 79 | segment = angle->segment(); |
| 80 | winding = testWinding; |
| 81 | } |
| 82 | angle = angle->next(); |
| 83 | } while (angle != firstAngle); |
| 84 | } |
| 85 | *sortablePtr = !unorderable; |
| 86 | *windingPtr = winding; |
| 87 | return angle; |
| 88 | } |
| 89 | |
Cary Clark | ab2d73b | 2016-12-16 17:17:25 -0500 | [diff] [blame] | 90 | SkOpSpan* FindUndone(SkOpContourHead* contourHead) { |
| 91 | SkOpContour* contour = contourHead; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 92 | do { |
Cary Clark | ab2d73b | 2016-12-16 17:17:25 -0500 | [diff] [blame] | 93 | if (contour->done()) { |
| 94 | continue; |
| 95 | } |
| 96 | SkOpSpan* result = contour->undoneSpan(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 97 | if (result) { |
| 98 | return result; |
| 99 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 100 | } while ((contour = contour->next())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 101 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 102 | } |
| 103 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 104 | SkOpSegment* FindChase(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** startPtr, |
| 105 | SkOpSpanBase** endPtr) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 106 | while (chase->count()) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 107 | SkOpSpanBase* span; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 108 | chase->pop(&span); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 109 | SkOpSegment* segment = span->segment(); |
| 110 | *startPtr = span->ptT()->next()->span(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 111 | bool done = true; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 112 | *endPtr = nullptr; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 113 | if (SkOpAngle* last = segment->activeAngle(*startPtr, startPtr, endPtr, &done)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 114 | *startPtr = last->start(); |
| 115 | *endPtr = last->end(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 116 | #if TRY_ROTATE |
| 117 | *chase->insert(0) = span; |
| 118 | #else |
| 119 | *chase->append() = span; |
| 120 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 121 | return last->segment(); |
| 122 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 123 | if (done) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 124 | continue; |
| 125 | } |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 126 | // find first angle, initialize winding to computed wind sum |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 127 | int winding; |
| 128 | bool sortable; |
| 129 | const SkOpAngle* angle = AngleWinding(*startPtr, *endPtr, &winding, &sortable); |
caryclark | 8ccc075 | 2016-08-17 06:14:06 -0700 | [diff] [blame] | 130 | if (!angle) { |
| 131 | return nullptr; |
| 132 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 133 | if (winding == SK_MinS32) { |
| 134 | continue; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 135 | } |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 136 | int sumWinding SK_INIT_TO_AVOID_WARNING; |
| 137 | if (sortable) { |
| 138 | segment = angle->segment(); |
| 139 | sumWinding = segment->updateWindingReverse(angle); |
| 140 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 141 | SkOpSegment* first = nullptr; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 142 | const SkOpAngle* firstAngle = angle; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 143 | while ((angle = angle->next()) != firstAngle) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 144 | segment = angle->segment(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 145 | SkOpSpanBase* start = angle->start(); |
| 146 | SkOpSpanBase* end = angle->end(); |
djsollen | 2f12463 | 2016-04-29 13:53:05 -0700 | [diff] [blame] | 147 | int maxWinding SK_INIT_TO_AVOID_WARNING; |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 148 | if (sortable) { |
| 149 | segment->setUpWinding(start, end, &maxWinding, &sumWinding); |
| 150 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 151 | if (!segment->done(angle)) { |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 152 | if (!first && (sortable || start->starter(end)->windSum() != SK_MinS32)) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 153 | first = segment; |
| 154 | *startPtr = start; |
| 155 | *endPtr = end; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 156 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 157 | // OPTIMIZATION: should this also add to the chase? |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 158 | if (sortable) { |
| 159 | (void) segment->markAngle(maxWinding, sumWinding, angle); |
| 160 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 161 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 162 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 163 | if (first) { |
| 164 | #if TRY_ROTATE |
| 165 | *chase->insert(0) = span; |
| 166 | #else |
| 167 | *chase->append() = span; |
| 168 | #endif |
| 169 | return first; |
| 170 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 171 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 172 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 173 | } |
| 174 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 175 | bool SortContourList(SkOpContourHead** contourList, bool evenOdd, bool oppEvenOdd) { |
| 176 | SkTDArray<SkOpContour* > list; |
| 177 | SkOpContour* contour = *contourList; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 178 | do { |
| 179 | if (contour->count()) { |
| 180 | contour->setOppXor(contour->operand() ? evenOdd : oppEvenOdd); |
| 181 | *list.append() = contour; |
| 182 | } |
| 183 | } while ((contour = contour->next())); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 184 | int count = list.count(); |
| 185 | if (!count) { |
| 186 | return false; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 187 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 188 | if (count > 1) { |
| 189 | SkTQSort<SkOpContour>(list.begin(), list.end() - 1); |
| 190 | } |
| 191 | contour = list[0]; |
| 192 | SkOpContourHead* contourHead = static_cast<SkOpContourHead*>(contour); |
| 193 | contour->globalState()->setContourHead(contourHead); |
| 194 | *contourList = contourHead; |
| 195 | for (int index = 1; index < count; ++index) { |
| 196 | SkOpContour* next = list[index]; |
| 197 | contour->setNext(next); |
| 198 | contour = next; |
| 199 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 200 | contour->setNext(nullptr); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 201 | return true; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 204 | static void calc_angles(SkOpContourHead* contourList DEBUG_COIN_DECLARE_PARAMS()) { |
| 205 | DEBUG_STATIC_SET_PHASE(contourList); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 206 | SkOpContour* contour = contourList; |
| 207 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 208 | contour->calcAngles(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 209 | } while ((contour = contour->next())); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 212 | static bool missing_coincidence(SkOpContourHead* contourList DEBUG_COIN_DECLARE_PARAMS()) { |
| 213 | DEBUG_STATIC_SET_PHASE(contourList); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 214 | SkOpContour* contour = contourList; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 215 | bool result = false; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 216 | do { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 217 | result |= contour->missingCoincidence(); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 218 | } while ((contour = contour->next())); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 219 | return result; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 222 | static bool move_multiples(SkOpContourHead* contourList DEBUG_COIN_DECLARE_PARAMS()) { |
| 223 | DEBUG_STATIC_SET_PHASE(contourList); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 224 | SkOpContour* contour = contourList; |
| 225 | do { |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 226 | if (!contour->moveMultiples()) { |
| 227 | return false; |
| 228 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 229 | } while ((contour = contour->next())); |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 230 | return true; |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Cary Clark | 28da283 | 2017-03-21 10:30:50 -0400 | [diff] [blame] | 233 | static bool move_nearby(SkOpContourHead* contourList DEBUG_COIN_DECLARE_PARAMS()) { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 234 | DEBUG_STATIC_SET_PHASE(contourList); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 235 | SkOpContour* contour = contourList; |
| 236 | do { |
Cary Clark | 28da283 | 2017-03-21 10:30:50 -0400 | [diff] [blame] | 237 | if (!contour->moveNearby()) { |
| 238 | return false; |
| 239 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 240 | } while ((contour = contour->next())); |
Cary Clark | 28da283 | 2017-03-21 10:30:50 -0400 | [diff] [blame] | 241 | return true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 242 | } |
| 243 | |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 244 | static bool sort_angles(SkOpContourHead* contourList) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 245 | SkOpContour* contour = contourList; |
| 246 | do { |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 247 | if (!contour->sortAngles()) { |
| 248 | return false; |
| 249 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 250 | } while ((contour = contour->next())); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 251 | return true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 252 | } |
| 253 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 254 | bool HandleCoincidence(SkOpContourHead* contourList, SkOpCoincidence* coincidence) { |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 255 | SkOpGlobalState* globalState = contourList->globalState(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 256 | // match up points within the coincident runs |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 257 | if (!coincidence->addExpanded(DEBUG_PHASE_ONLY_PARAMS(kIntersecting))) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 258 | return false; |
| 259 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 260 | // combine t values when multiple intersections occur on some segments but not others |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 261 | if (!move_multiples(contourList DEBUG_PHASE_PARAMS(kWalking))) { |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 262 | return false; |
| 263 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 264 | // move t values and points together to eliminate small/tiny gaps |
Cary Clark | 28da283 | 2017-03-21 10:30:50 -0400 | [diff] [blame] | 265 | if (!move_nearby(contourList DEBUG_COIN_PARAMS())) { |
| 266 | return false; |
| 267 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 268 | // add coincidence formed by pairing on curve points and endpoints |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 269 | coincidence->correctEnds(DEBUG_PHASE_ONLY_PARAMS(kIntersecting)); |
| 270 | if (!coincidence->addEndMovedSpans(DEBUG_COIN_ONLY_PARAMS())) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 271 | return false; |
| 272 | } |
Cary Clark | e47ae29 | 2016-10-05 08:51:39 -0400 | [diff] [blame] | 273 | const int SAFETY_COUNT = 3; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 274 | int safetyHatch = SAFETY_COUNT; |
| 275 | // look for coincidence present in A-B and A-C but missing in B-C |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 276 | do { |
| 277 | bool added; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 278 | if (!coincidence->addMissing(&added DEBUG_ITER_PARAMS(SAFETY_COUNT - safetyHatch))) { |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 279 | return false; |
| 280 | } |
| 281 | if (!added) { |
| 282 | break; |
| 283 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 284 | if (!--safetyHatch) { |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 285 | SkASSERT(globalState->debugSkipAssert()); |
caryclark | 3f0753d | 2016-06-28 09:23:57 -0700 | [diff] [blame] | 286 | return false; |
| 287 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 288 | move_nearby(contourList DEBUG_ITER_PARAMS(SAFETY_COUNT - safetyHatch - 1)); |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 289 | } while (true); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 290 | // check to see if, loosely, coincident ranges may be expanded |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 291 | if (coincidence->expand(DEBUG_COIN_ONLY_PARAMS())) { |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 292 | bool added; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 293 | if (!coincidence->addMissing(&added DEBUG_COIN_PARAMS())) { |
caryclark | 81a478c | 2016-09-09 09:37:57 -0700 | [diff] [blame] | 294 | return false; |
| 295 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 296 | if (!coincidence->addExpanded(DEBUG_COIN_ONLY_PARAMS())) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 297 | return false; |
| 298 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 299 | if (!move_multiples(contourList DEBUG_COIN_PARAMS())) { |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 300 | return false; |
| 301 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 302 | move_nearby(contourList DEBUG_COIN_PARAMS()); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 303 | } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 304 | // the expanded ranges may not align -- add the missing spans |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 305 | if (!coincidence->addExpanded(DEBUG_PHASE_ONLY_PARAMS(kWalking))) { |
caryclark | 8bc90e2 | 2016-07-25 06:05:08 -0700 | [diff] [blame] | 306 | return false; |
| 307 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 308 | // mark spans of coincident segments as coincident |
Cary Clark | e47ae29 | 2016-10-05 08:51:39 -0400 | [diff] [blame] | 309 | coincidence->mark(DEBUG_COIN_ONLY_PARAMS()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 310 | // look for coincidence lines and curves undetected by intersection |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 311 | if (missing_coincidence(contourList DEBUG_COIN_PARAMS())) { |
| 312 | (void) coincidence->expand(DEBUG_PHASE_ONLY_PARAMS(kIntersecting)); |
| 313 | if (!coincidence->addExpanded(DEBUG_COIN_ONLY_PARAMS())) { |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 314 | return false; |
| 315 | } |
caryclark | e6522ea | 2016-10-17 07:54:33 -0700 | [diff] [blame] | 316 | if (!coincidence->mark(DEBUG_PHASE_ONLY_PARAMS(kWalking))) { |
| 317 | return false; |
| 318 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 319 | } else { |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 320 | (void) coincidence->expand(DEBUG_COIN_ONLY_PARAMS()); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 321 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 322 | (void) coincidence->expand(DEBUG_COIN_ONLY_PARAMS()); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 323 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 324 | SkOpCoincidence overlaps(globalState); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 325 | safetyHatch = SAFETY_COUNT; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 326 | do { |
| 327 | SkOpCoincidence* pairs = overlaps.isEmpty() ? coincidence : &overlaps; |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 328 | // adjust the winding value to account for coincident edges |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 329 | if (!pairs->apply(DEBUG_ITER_ONLY_PARAMS(SAFETY_COUNT - safetyHatch))) { |
| 330 | return false; |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 331 | } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 332 | // For each coincident pair that overlaps another, when the receivers (the 1st of the pair) |
| 333 | // are different, construct a new pair to resolve their mutual span |
Cary Clark | 40f2378 | 2016-10-06 12:04:16 -0400 | [diff] [blame] | 334 | if (!pairs->findOverlaps(&overlaps DEBUG_ITER_PARAMS(SAFETY_COUNT - safetyHatch))) { |
| 335 | return false; |
| 336 | } |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 337 | if (!--safetyHatch) { |
| 338 | SkASSERT(globalState->debugSkipAssert()); |
| 339 | return false; |
| 340 | } |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 341 | } while (!overlaps.isEmpty()); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 342 | calc_angles(contourList DEBUG_COIN_PARAMS()); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 343 | if (!sort_angles(contourList)) { |
| 344 | return false; |
| 345 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 346 | #if DEBUG_COINCIDENCE_VERBOSE |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 347 | coincidence->debugShowCoincidence(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 348 | #endif |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 349 | #if DEBUG_COINCIDENCE |
| 350 | coincidence->debugValidate(); |
| 351 | #endif |
| 352 | SkPathOpsDebug::ShowActiveSpans(contourList); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 353 | return true; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 354 | } |