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