OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkIntersections.h" | 7 #include "SkIntersections.h" |
8 #include "SkOpContour.h" | 8 #include "SkOpContour.h" |
9 #include "SkPathWriter.h" | 9 #include "SkPathWriter.h" |
10 #include "SkTSort.h" | 10 #include "SkTSort.h" |
11 | 11 |
12 void SkOpContour::addCoincident(int index, SkOpContour* other, int otherIndex, | 12 void SkOpContour::addCoincident(int index, SkOpContour* other, int otherIndex, |
13 const SkIntersections& ts, bool swap) { | 13 const SkIntersections& ts, bool swap) { |
14 SkCoincidence& coincidence = *fCoincidences.append(); | 14 SkCoincidence& coincidence = fCoincidences.push_back(); |
15 coincidence.fContours[0] = this; // FIXME: no need to store | 15 coincidence.fContours[0] = this; // FIXME: no need to store |
16 coincidence.fContours[1] = other; | 16 coincidence.fContours[1] = other; |
17 coincidence.fSegments[0] = index; | 17 coincidence.fSegments[0] = index; |
18 coincidence.fSegments[1] = otherIndex; | 18 coincidence.fSegments[1] = otherIndex; |
19 coincidence.fTs[swap][0] = ts[0][0]; | 19 coincidence.fTs[swap][0] = ts[0][0]; |
20 coincidence.fTs[swap][1] = ts[0][1]; | 20 coincidence.fTs[swap][1] = ts[0][1]; |
21 coincidence.fTs[!swap][0] = ts[1][0]; | 21 coincidence.fTs[!swap][0] = ts[1][0]; |
22 coincidence.fTs[!swap][1] = ts[1][1]; | 22 coincidence.fTs[!swap][1] = ts[1][1]; |
23 coincidence.fPts[0] = ts.pt(0).asSkPoint(); | 23 coincidence.fPts[0] = ts.pt(0).asSkPoint(); |
24 coincidence.fPts[1] = ts.pt(1).asSkPoint(); | 24 coincidence.fPts[1] = ts.pt(1).asSkPoint(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 #if DEBUG_CONCIDENT | 146 #if DEBUG_CONCIDENT |
147 thisOne.debugShowTs(); | 147 thisOne.debugShowTs(); |
148 other.debugShowTs(); | 148 other.debugShowTs(); |
149 #endif | 149 #endif |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 void SkOpContour::sortSegments() { | 153 void SkOpContour::sortSegments() { |
154 int segmentCount = fSegments.count(); | 154 int segmentCount = fSegments.count(); |
155 fSortedSegments.setReserve(segmentCount); | 155 fSortedSegments.push_back_n(segmentCount); |
156 for (int test = 0; test < segmentCount; ++test) { | 156 for (int test = 0; test < segmentCount; ++test) { |
157 *fSortedSegments.append() = &fSegments[test]; | 157 fSortedSegments[test] = &fSegments[test]; |
158 } | 158 } |
159 SkTQSort<SkOpSegment>(fSortedSegments.begin(), fSortedSegments.end() - 1); | 159 SkTQSort<SkOpSegment>(fSortedSegments.begin(), fSortedSegments.end() - 1); |
160 fFirstSorted = 0; | 160 fFirstSorted = 0; |
161 } | 161 } |
162 | 162 |
163 void SkOpContour::toPath(SkPathWriter* path) const { | 163 void SkOpContour::toPath(SkPathWriter* path) const { |
164 int segmentCount = fSegments.count(); | 164 int segmentCount = fSegments.count(); |
165 const SkPoint& pt = fSegments.front().pts()[0]; | 165 const SkPoint& pt = fSegments.front().pts()[0]; |
166 path->deferredMove(pt); | 166 path->deferredMove(pt); |
167 for (int test = 0; test < segmentCount; ++test) { | 167 for (int test = 0; test < segmentCount; ++test) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 int SkOpContour::debugShowWindingValues(int totalSegments, int ofInterest) { | 222 int SkOpContour::debugShowWindingValues(int totalSegments, int ofInterest) { |
223 int count = fSegments.count(); | 223 int count = fSegments.count(); |
224 int sum = 0; | 224 int sum = 0; |
225 for (int index = 0; index < count; ++index) { | 225 for (int index = 0; index < count; ++index) { |
226 sum += fSegments[index].debugShowWindingValues(totalSegments, ofInterest
); | 226 sum += fSegments[index].debugShowWindingValues(totalSegments, ofInterest
); |
227 } | 227 } |
228 // SkDebugf("%s sum=%d\n", __FUNCTION__, sum); | 228 // SkDebugf("%s sum=%d\n", __FUNCTION__, sum); |
229 return sum; | 229 return sum; |
230 } | 230 } |
231 | 231 |
232 static void SkOpContour::debugShowWindingValues(const SkTDArray<SkOpContour*>& c
ontourList) { | 232 static void SkOpContour::debugShowWindingValues(const SkTArray<SkOpContour*, tru
e>& contourList) { |
233 // int ofInterest = 1 << 1 | 1 << 5 | 1 << 9 | 1 << 13; | 233 // int ofInterest = 1 << 1 | 1 << 5 | 1 << 9 | 1 << 13; |
234 // int ofInterest = 1 << 4 | 1 << 8 | 1 << 12 | 1 << 16; | 234 // int ofInterest = 1 << 4 | 1 << 8 | 1 << 12 | 1 << 16; |
235 int ofInterest = 1 << 5 | 1 << 8; | 235 int ofInterest = 1 << 5 | 1 << 8; |
236 int total = 0; | 236 int total = 0; |
237 int index; | 237 int index; |
238 for (index = 0; index < contourList.count(); ++index) { | 238 for (index = 0; index < contourList.count(); ++index) { |
239 total += contourList[index]->segments().count(); | 239 total += contourList[index]->segments().count(); |
240 } | 240 } |
241 int sum = 0; | 241 int sum = 0; |
242 for (index = 0; index < contourList.count(); ++index) { | 242 for (index = 0; index < contourList.count(); ++index) { |
243 sum += contourList[index]->debugShowWindingValues(total, ofInterest); | 243 sum += contourList[index]->debugShowWindingValues(total, ofInterest); |
244 } | 244 } |
245 // SkDebugf("%s total=%d\n", __FUNCTION__, sum); | 245 // SkDebugf("%s total=%d\n", __FUNCTION__, sum); |
246 } | 246 } |
247 #endif | 247 #endif |
248 | 248 |
249 void SkOpContour::setBounds() { | 249 void SkOpContour::setBounds() { |
250 int count = fSegments.count(); | 250 int count = fSegments.count(); |
251 if (count == 0) { | 251 if (count == 0) { |
252 SkDebugf("%s empty contour\n", __FUNCTION__); | 252 SkDebugf("%s empty contour\n", __FUNCTION__); |
253 SkASSERT(0); | 253 SkASSERT(0); |
254 // FIXME: delete empty contour? | 254 // FIXME: delete empty contour? |
255 return; | 255 return; |
256 } | 256 } |
257 fBounds = fSegments.front().bounds(); | 257 fBounds = fSegments.front().bounds(); |
258 for (int index = 1; index < count; ++index) { | 258 for (int index = 1; index < count; ++index) { |
259 fBounds.add(fSegments[index].bounds()); | 259 fBounds.add(fSegments[index].bounds()); |
260 } | 260 } |
261 } | 261 } |
OLD | NEW |