OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "SkAddIntersections.h" | 7 #include "SkAddIntersections.h" |
8 #include "SkOpCoincidence.h" | 8 #include "SkOpCoincidence.h" |
9 #include "SkOpEdgeBuilder.h" | 9 #include "SkOpEdgeBuilder.h" |
10 #include "SkPathOpsCommon.h" | 10 #include "SkPathOpsCommon.h" |
11 #include "SkPathWriter.h" | 11 #include "SkPathWriter.h" |
12 #include "SkTSort.h" | 12 #include "SkTSort.h" |
13 | 13 |
| 14 const SkOpAngle* AngleWinding(SkOpSpanBase* start, SkOpSpanBase* end, int* windi
ngPtr, |
| 15 bool* sortablePtr) { |
| 16 // find first angle, initialize winding to computed fWindSum |
| 17 SkOpSegment* segment = start->segment(); |
| 18 const SkOpAngle* angle = segment->spanToAngle(start, end); |
| 19 if (!angle) { |
| 20 *windingPtr = SK_MinS32; |
| 21 return NULL; |
| 22 } |
| 23 bool computeWinding = false; |
| 24 const SkOpAngle* firstAngle = angle; |
| 25 bool loop = false; |
| 26 bool unorderable = false; |
| 27 int winding = SK_MinS32; |
| 28 do { |
| 29 angle = angle->next(); |
| 30 unorderable |= angle->unorderable(); |
| 31 if ((computeWinding = unorderable || (angle == firstAngle && loop))) { |
| 32 break; // if we get here, there's no winding, loop is unorderable |
| 33 } |
| 34 loop |= angle == firstAngle; |
| 35 segment = angle->segment(); |
| 36 winding = segment->windSum(angle); |
| 37 } while (winding == SK_MinS32); |
| 38 // if the angle loop contains an unorderable span, the angle order may be us
eless |
| 39 // directly compute the winding in this case for each span |
| 40 if (computeWinding) { |
| 41 firstAngle = angle; |
| 42 winding = SK_MinS32; |
| 43 do { |
| 44 SkOpSpanBase* startSpan = angle->start(); |
| 45 SkOpSpanBase* endSpan = angle->end(); |
| 46 SkOpSpan* lesser = startSpan->starter(endSpan); |
| 47 int testWinding = lesser->windSum(); |
| 48 if (testWinding == SK_MinS32) { |
| 49 testWinding = lesser->computeWindSum(); |
| 50 } |
| 51 if (testWinding != SK_MinS32) { |
| 52 segment = angle->segment(); |
| 53 winding = testWinding; |
| 54 } |
| 55 angle = angle->next(); |
| 56 } while (angle != firstAngle); |
| 57 } |
| 58 *sortablePtr = !unorderable; |
| 59 *windingPtr = winding; |
| 60 return angle; |
| 61 } |
| 62 |
14 SkOpSegment* FindUndone(SkOpContourHead* contourList, SkOpSpanBase** startPtr, | 63 SkOpSegment* FindUndone(SkOpContourHead* contourList, SkOpSpanBase** startPtr, |
15 SkOpSpanBase** endPtr) { | 64 SkOpSpanBase** endPtr) { |
16 SkOpSegment* result; | 65 SkOpSegment* result; |
17 SkOpContour* contour = contourList; | 66 SkOpContour* contour = contourList; |
18 do { | 67 do { |
19 result = contour->undoneSegment(startPtr, endPtr); | 68 result = contour->undoneSegment(startPtr, endPtr); |
20 if (result) { | 69 if (result) { |
21 return result; | 70 return result; |
22 } | 71 } |
23 } while ((contour = contour->next())); | 72 } while ((contour = contour->next())); |
24 return NULL; | 73 return NULL; |
25 } | 74 } |
26 | 75 |
27 SkOpSegment* FindChase(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** startPtr, | 76 SkOpSegment* FindChase(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** startPtr, |
28 SkOpSpanBase** endPtr) { | 77 SkOpSpanBase** endPtr) { |
29 while (chase->count()) { | 78 while (chase->count()) { |
30 SkOpSpanBase* span; | 79 SkOpSpanBase* span; |
31 chase->pop(&span); | 80 chase->pop(&span); |
32 SkOpSegment* segment = span->segment(); | 81 SkOpSegment* segment = span->segment(); |
33 *startPtr = span->ptT()->next()->span(); | 82 *startPtr = span->ptT()->next()->span(); |
34 bool sortable = true; | |
35 bool done = true; | 83 bool done = true; |
36 *endPtr = NULL; | 84 *endPtr = NULL; |
37 if (SkOpAngle* last = segment->activeAngle(*startPtr, startPtr, endPtr,
&done, | 85 if (SkOpAngle* last = segment->activeAngle(*startPtr, startPtr, endPtr,
&done)) { |
38 &sortable)) { | |
39 if (last->unorderable()) { | |
40 continue; | |
41 } | |
42 *startPtr = last->start(); | 86 *startPtr = last->start(); |
43 *endPtr = last->end(); | 87 *endPtr = last->end(); |
44 #if TRY_ROTATE | 88 #if TRY_ROTATE |
45 *chase->insert(0) = span; | 89 *chase->insert(0) = span; |
46 #else | 90 #else |
47 *chase->append() = span; | 91 *chase->append() = span; |
48 #endif | 92 #endif |
49 return last->segment(); | 93 return last->segment(); |
50 } | 94 } |
51 if (done) { | 95 if (done) { |
52 continue; | 96 continue; |
53 } | 97 } |
54 if (!sortable) { | |
55 continue; | |
56 } | |
57 // find first angle, initialize winding to computed wind sum | 98 // find first angle, initialize winding to computed wind sum |
58 const SkOpAngle* angle = segment->spanToAngle(*startPtr, *endPtr); | 99 int winding; |
59 if (!angle) { | 100 bool sortable; |
60 continue; | 101 const SkOpAngle* angle = AngleWinding(*startPtr, *endPtr, &winding, &sor
table); |
61 } | |
62 const SkOpAngle* firstAngle = angle; | |
63 bool loop = false; | |
64 int winding = SK_MinS32; | |
65 do { | |
66 angle = angle->next(); | |
67 if (angle == firstAngle && loop) { | |
68 break; // if we get here, there's no winding, loop is unorder
able | |
69 } | |
70 loop |= angle == firstAngle; | |
71 segment = angle->segment(); | |
72 winding = segment->windSum(angle); | |
73 } while (winding == SK_MinS32); | |
74 if (winding == SK_MinS32) { | 102 if (winding == SK_MinS32) { |
75 continue; | 103 continue; |
76 } | 104 } |
77 int sumWinding = segment->updateWindingReverse(angle); | 105 int sumWinding SK_INIT_TO_AVOID_WARNING; |
| 106 if (sortable) { |
| 107 segment = angle->segment(); |
| 108 sumWinding = segment->updateWindingReverse(angle); |
| 109 } |
78 SkOpSegment* first = NULL; | 110 SkOpSegment* first = NULL; |
79 firstAngle = angle; | 111 const SkOpAngle* firstAngle = angle; |
80 while ((angle = angle->next()) != firstAngle) { | 112 while ((angle = angle->next()) != firstAngle) { |
81 segment = angle->segment(); | 113 segment = angle->segment(); |
82 SkOpSpanBase* start = angle->start(); | 114 SkOpSpanBase* start = angle->start(); |
83 SkOpSpanBase* end = angle->end(); | 115 SkOpSpanBase* end = angle->end(); |
84 int maxWinding; | 116 int maxWinding; |
85 segment->setUpWinding(start, end, &maxWinding, &sumWinding); | 117 if (sortable) { |
| 118 segment->setUpWinding(start, end, &maxWinding, &sumWinding); |
| 119 } |
86 if (!segment->done(angle)) { | 120 if (!segment->done(angle)) { |
87 if (!first) { | 121 if (!first && (sortable || start->starter(end)->windSum() != SK_
MinS32)) { |
88 first = segment; | 122 first = segment; |
89 *startPtr = start; | 123 *startPtr = start; |
90 *endPtr = end; | 124 *endPtr = end; |
91 } | 125 } |
92 // OPTIMIZATION: should this also add to the chase? | 126 // OPTIMIZATION: should this also add to the chase? |
93 (void) segment->markAngle(maxWinding, sumWinding, angle); | 127 if (sortable) { |
| 128 (void) segment->markAngle(maxWinding, sumWinding, angle); |
| 129 } |
94 } | 130 } |
95 } | 131 } |
96 if (first) { | 132 if (first) { |
97 #if TRY_ROTATE | 133 #if TRY_ROTATE |
98 *chase->insert(0) = span; | 134 *chase->insert(0) = span; |
99 #else | 135 #else |
100 *chase->append() = span; | 136 *chase->append() = span; |
101 #endif | 137 #endif |
102 return first; | 138 return first; |
103 } | 139 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (!coincidence->apply()) { | 458 if (!coincidence->apply()) { |
423 return false; | 459 return false; |
424 } | 460 } |
425 } | 461 } |
426 #if DEBUG_ACTIVE_SPANS | 462 #if DEBUG_ACTIVE_SPANS |
427 coincidence->debugShowCoincidence(); | 463 coincidence->debugShowCoincidence(); |
428 DebugShowActiveSpans(contourList); | 464 DebugShowActiveSpans(contourList); |
429 #endif | 465 #endif |
430 return true; | 466 return true; |
431 } | 467 } |
OLD | NEW |