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 | 12 |
13 static SkOpSegment* findChaseOp(SkTDArray<SkOpSpanBase*>& chase, SkOpSpanBase**
startPtr, | 13 static SkOpSegment* findChaseOp(SkTDArray<SkOpSpanBase*>& chase, SkOpSpanBase**
startPtr, |
14 SkOpSpanBase** endPtr) { | 14 SkOpSpanBase** endPtr) { |
15 while (chase.count()) { | 15 while (chase.count()) { |
16 SkOpSpanBase* span; | 16 SkOpSpanBase* span; |
17 chase.pop(&span); | 17 chase.pop(&span); |
18 // OPTIMIZE: prev makes this compatible with old code -- but is it neces
sary? | 18 // OPTIMIZE: prev makes this compatible with old code -- but is it neces
sary? |
19 *startPtr = span->ptT()->prev()->span(); | 19 *startPtr = span->ptT()->prev()->span(); |
20 SkOpSegment* segment = (*startPtr)->segment(); | 20 SkOpSegment* segment = (*startPtr)->segment(); |
21 bool sortable = true; | |
22 bool done = true; | 21 bool done = true; |
23 *endPtr = NULL; | 22 *endPtr = NULL; |
24 if (SkOpAngle* last = segment->activeAngle(*startPtr, startPtr, endPtr,
&done, | 23 if (SkOpAngle* last = segment->activeAngle(*startPtr, startPtr, endPtr,
&done)) { |
25 &sortable)) { | |
26 if (last->unorderable()) { | |
27 continue; | |
28 } | |
29 *startPtr = last->start(); | 24 *startPtr = last->start(); |
30 *endPtr = last->end(); | 25 *endPtr = last->end(); |
31 #if TRY_ROTATE | 26 #if TRY_ROTATE |
32 *chase.insert(0) = span; | 27 *chase.insert(0) = span; |
33 #else | 28 #else |
34 *chase.append() = span; | 29 *chase.append() = span; |
35 #endif | 30 #endif |
36 return last->segment(); | 31 return last->segment(); |
37 } | 32 } |
38 if (done) { | 33 if (done) { |
39 continue; | 34 continue; |
40 } | 35 } |
41 if (!sortable) { | 36 int winding; |
42 continue; | 37 bool sortable; |
43 } | 38 const SkOpAngle* angle = AngleWinding(*startPtr, *endPtr, &winding, &sor
table); |
44 // find first angle, initialize winding to computed fWindSum | |
45 const SkOpAngle* angle = segment->spanToAngle(*startPtr, *endPtr); | |
46 if (!angle) { | |
47 continue; | |
48 } | |
49 const SkOpAngle* firstAngle = angle; | |
50 bool loop = false; | |
51 int winding = SK_MinS32; | |
52 do { | |
53 angle = angle->next(); | |
54 if (angle == firstAngle && loop) { | |
55 break; // if we get here, there's no winding, loop is unorder
able | |
56 } | |
57 loop |= angle == firstAngle; | |
58 segment = angle->segment(); | |
59 winding = segment->windSum(angle); | |
60 } while (winding == SK_MinS32); | |
61 if (winding == SK_MinS32) { | 39 if (winding == SK_MinS32) { |
62 continue; | 40 continue; |
63 } | 41 } |
64 int sumMiWinding = segment->updateWindingReverse(angle); | 42 int sumMiWinding, sumSuWinding; |
65 int sumSuWinding = segment->updateOppWindingReverse(angle); | 43 if (sortable) { |
66 if (segment->operand()) { | 44 segment = angle->segment(); |
67 SkTSwap<int>(sumMiWinding, sumSuWinding); | 45 sumMiWinding = segment->updateWindingReverse(angle); |
| 46 sumSuWinding = segment->updateOppWindingReverse(angle); |
| 47 if (segment->operand()) { |
| 48 SkTSwap<int>(sumMiWinding, sumSuWinding); |
| 49 } |
68 } | 50 } |
69 SkOpSegment* first = NULL; | 51 SkOpSegment* first = NULL; |
70 firstAngle = angle; | 52 const SkOpAngle* firstAngle = angle; |
71 while ((angle = angle->next()) != firstAngle) { | 53 while ((angle = angle->next()) != firstAngle) { |
72 segment = angle->segment(); | 54 segment = angle->segment(); |
73 SkOpSpanBase* start = angle->start(); | 55 SkOpSpanBase* start = angle->start(); |
74 SkOpSpanBase* end = angle->end(); | 56 SkOpSpanBase* end = angle->end(); |
75 int maxWinding, sumWinding, oppMaxWinding, oppSumWinding; | 57 int maxWinding, sumWinding, oppMaxWinding, oppSumWinding; |
76 segment->setUpWindings(start, end, &sumMiWinding, &sumSuWinding, | 58 if (sortable) { |
77 &maxWinding, &sumWinding, &oppMaxWinding, &oppSumWinding); | 59 segment->setUpWindings(start, end, &sumMiWinding, &sumSuWinding, |
| 60 &maxWinding, &sumWinding, &oppMaxWinding, &oppSumWinding
); |
| 61 } |
78 if (!segment->done(angle)) { | 62 if (!segment->done(angle)) { |
79 if (!first) { | 63 if (!first && (sortable || start->starter(end)->windSum() != SK_
MinS32)) { |
80 first = segment; | 64 first = segment; |
81 *startPtr = start; | 65 *startPtr = start; |
82 *endPtr = end; | 66 *endPtr = end; |
83 } | 67 } |
84 // OPTIMIZATION: should this also add to the chase? | 68 // OPTIMIZATION: should this also add to the chase? |
85 (void) segment->markAngle(maxWinding, sumWinding, oppMaxWinding, | 69 if (sortable) { |
86 oppSumWinding, angle); | 70 (void) segment->markAngle(maxWinding, sumWinding, oppMaxWind
ing, |
| 71 oppSumWinding, angle); |
| 72 } |
87 } | 73 } |
88 } | 74 } |
89 if (first) { | 75 if (first) { |
90 #if TRY_ROTATE | 76 #if TRY_ROTATE |
91 *chase.insert(0) = span; | 77 *chase.insert(0) = span; |
92 #else | 78 #else |
93 *chase.append() = span; | 79 *chase.append() = span; |
94 #endif | 80 #endif |
95 return first; | 81 return first; |
96 } | 82 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 Assemble(wrapper, &assembled); | 299 Assemble(wrapper, &assembled); |
314 *result = *assembled.nativePath(); | 300 *result = *assembled.nativePath(); |
315 result->setFillType(fillType); | 301 result->setFillType(fillType); |
316 } | 302 } |
317 return true; | 303 return true; |
318 } | 304 } |
319 | 305 |
320 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { | 306 bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) { |
321 return OpDebug(one, two, op, result, true); | 307 return OpDebug(one, two, op, result, true); |
322 } | 308 } |
OLD | NEW |