blob: df87d058b679570042bed8da6b20458a5fba0277 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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 */
7#ifndef SkOpSegment_DEFINE
8#define SkOpSegment_DEFINE
9
10#include "SkOpAngle.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000011#include "SkOpSpan.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000012#include "SkPathOpsBounds.h"
13#include "SkPathOpsCurve.h"
caryclark@google.comd892bd82013-06-17 14:10:36 +000014#include "SkTArray.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000015#include "SkTDArray.h"
16
commit-bot@chromium.org0bcb8ca2014-04-25 13:42:21 +000017#if defined(SK_DEBUG) || !FORCE_RELEASE
18#include "SkThread.h"
19#endif
20
caryclarkdac1d172014-06-17 05:15:38 -070021struct SkCoincidence;
caryclark@google.com07393ca2013-04-08 11:47:37 +000022class SkPathWriter;
23
24class SkOpSegment {
25public:
26 SkOpSegment() {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000027#if defined(SK_DEBUG) || !FORCE_RELEASE
commit-bot@chromium.org0bcb8ca2014-04-25 13:42:21 +000028 fID = sk_atomic_inc(&SkPathOpsDebug::gSegmentID);
caryclark@google.com07393ca2013-04-08 11:47:37 +000029#endif
30 }
31
32 bool operator<(const SkOpSegment& rh) const {
33 return fBounds.fTop < rh.fBounds.fTop;
34 }
35
caryclarkdac1d172014-06-17 05:15:38 -070036 struct AlignedSpan {
37 double fOldT;
38 double fT;
39 SkPoint fOldPt;
40 SkPoint fPt;
41 const SkOpSegment* fSegment;
42 const SkOpSegment* fOther1;
43 const SkOpSegment* fOther2;
44 };
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000045
caryclark@google.com07393ca2013-04-08 11:47:37 +000046 const SkPathOpsBounds& bounds() const {
47 return fBounds;
48 }
49
50 // OPTIMIZE
51 // when the edges are initially walked, they don't automatically get the prior and next
52 // edges assigned to positions t=0 and t=1. Doing that would remove the need for this check,
53 // and would additionally remove the need for similar checks in condition edges. It would
54 // also allow intersection code to assume end of segment intersections (maybe?)
55 bool complete() const {
56 int count = fTs.count();
57 return count > 1 && fTs[0].fT == 0 && fTs[--count].fT == 1;
58 }
59
caryclark@google.comcffbcc32013-06-04 17:59:42 +000060 int count() const {
61 return fTs.count();
62 }
63
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 bool done() const {
65 SkASSERT(fDoneSpans <= fTs.count());
66 return fDoneSpans == fTs.count();
67 }
68
69 bool done(int min) const {
70 return fTs[min].fDone;
71 }
72
73 bool done(const SkOpAngle* angle) const {
74 return done(SkMin32(angle->start(), angle->end()));
75 }
76
caryclark@google.com570863f2013-09-16 15:55:01 +000077 SkDPoint dPtAtT(double mid) const {
78 return (*CurveDPointAtT[SkPathOpsVerbToPoints(fVerb)])(fPts, mid);
79 }
80
caryclark@google.com07393ca2013-04-08 11:47:37 +000081 SkVector dxdy(int index) const {
reed@google.com277c3f82013-05-31 15:17:50 +000082 return (*CurveSlopeAtT[SkPathOpsVerbToPoints(fVerb)])(fPts, fTs[index].fT);
caryclark@google.com07393ca2013-04-08 11:47:37 +000083 }
84
85 SkScalar dy(int index) const {
86 return dxdy(index).fY;
87 }
88
caryclarkdac1d172014-06-17 05:15:38 -070089 bool hasMultiples() const {
90 return fMultiples;
91 }
92
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000093 bool hasSmall() const {
94 return fSmall;
95 }
96
97 bool hasTiny() const {
98 return fTiny;
99 }
100
caryclark@google.com07393ca2013-04-08 11:47:37 +0000101 bool intersected() const {
102 return fTs.count() > 0;
103 }
104
105 bool isCanceled(int tIndex) const {
106 return fTs[tIndex].fWindValue == 0 && fTs[tIndex].fOppValue == 0;
107 }
108
109 bool isConnected(int startIndex, int endIndex) const {
110 return fTs[startIndex].fWindSum != SK_MinS32 || fTs[endIndex].fWindSum != SK_MinS32;
111 }
112
113 bool isHorizontal() const {
114 return fBounds.fTop == fBounds.fBottom;
115 }
116
117 bool isVertical() const {
118 return fBounds.fLeft == fBounds.fRight;
119 }
120
121 bool isVertical(int start, int end) const {
reed@google.com277c3f82013-05-31 15:17:50 +0000122 return (*CurveIsVertical[SkPathOpsVerbToPoints(fVerb)])(fPts, start, end);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000123 }
124
125 bool operand() const {
126 return fOperand;
127 }
128
129 int oppSign(const SkOpAngle* angle) const {
130 SkASSERT(angle->segment() == this);
131 return oppSign(angle->start(), angle->end());
132 }
133
134 int oppSign(int startIndex, int endIndex) const {
135 int result = startIndex < endIndex ? -fTs[startIndex].fOppValue : fTs[endIndex].fOppValue;
136#if DEBUG_WIND_BUMP
137 SkDebugf("%s oppSign=%d\n", __FUNCTION__, result);
138#endif
139 return result;
140 }
141
142 int oppSum(int tIndex) const {
143 return fTs[tIndex].fOppSum;
144 }
145
146 int oppSum(const SkOpAngle* angle) const {
147 int lesser = SkMin32(angle->start(), angle->end());
148 return fTs[lesser].fOppSum;
149 }
150
151 int oppValue(int tIndex) const {
152 return fTs[tIndex].fOppValue;
153 }
154
155 int oppValue(const SkOpAngle* angle) const {
156 int lesser = SkMin32(angle->start(), angle->end());
157 return fTs[lesser].fOppValue;
158 }
159
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000160#if DEBUG_VALIDATE
161 bool oppXor() const {
162 return fOppXor;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000163 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000164#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000165
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000166 SkPoint ptAtT(double mid) const {
167 return (*CurvePointAtT[SkPathOpsVerbToPoints(fVerb)])(fPts, mid);
168 }
169
caryclark@google.com07393ca2013-04-08 11:47:37 +0000170 const SkPoint* pts() const {
171 return fPts;
172 }
173
174 void reset() {
175 init(NULL, (SkPath::Verb) -1, false, false);
176 fBounds.set(SK_ScalarMax, SK_ScalarMax, SK_ScalarMax, SK_ScalarMax);
177 fTs.reset();
178 }
179
caryclark5e27e0e2014-08-12 07:46:33 -0700180 bool reversePoints(const SkPoint& p1, const SkPoint& p2) const;
181
caryclark@google.com07393ca2013-04-08 11:47:37 +0000182 void setOppXor(bool isOppXor) {
183 fOppXor = isOppXor;
184 }
185
caryclark@google.com07393ca2013-04-08 11:47:37 +0000186 void setUpWinding(int index, int endIndex, int* maxWinding, int* sumWinding) {
187 int deltaSum = spanSign(index, endIndex);
188 *maxWinding = *sumWinding;
189 *sumWinding -= deltaSum;
190 }
191
caryclark@google.com07393ca2013-04-08 11:47:37 +0000192 const SkOpSpan& span(int tIndex) const {
193 return fTs[tIndex];
194 }
195
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000196 const SkOpAngle* spanToAngle(int tStart, int tEnd) const {
197 SkASSERT(tStart != tEnd);
198 const SkOpSpan& span = fTs[tStart];
caryclarkdac1d172014-06-17 05:15:38 -0700199 return tStart < tEnd ? span.fToAngle : span.fFromAngle;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000200 }
201
202 // FIXME: create some sort of macro or template that avoids casting
203 SkOpAngle* spanToAngle(int tStart, int tEnd) {
204 const SkOpAngle* cAngle = (const_cast<const SkOpSegment*>(this))->spanToAngle(tStart, tEnd);
205 return const_cast<SkOpAngle*>(cAngle);
206 }
207
caryclark@google.com07393ca2013-04-08 11:47:37 +0000208 int spanSign(const SkOpAngle* angle) const {
209 SkASSERT(angle->segment() == this);
210 return spanSign(angle->start(), angle->end());
211 }
212
213 int spanSign(int startIndex, int endIndex) const {
214 int result = startIndex < endIndex ? -fTs[startIndex].fWindValue : fTs[endIndex].fWindValue;
215#if DEBUG_WIND_BUMP
216 SkDebugf("%s spanSign=%d\n", __FUNCTION__, result);
217#endif
218 return result;
219 }
220
caryclark@google.com07393ca2013-04-08 11:47:37 +0000221 double t(int tIndex) const {
222 return fTs[tIndex].fT;
223 }
224
225 double tAtMid(int start, int end, double mid) const {
226 return fTs[start].fT * (1 - mid) + fTs[end].fT * mid;
227 }
228
caryclark@google.com07393ca2013-04-08 11:47:37 +0000229 void updatePts(const SkPoint pts[]) {
230 fPts = pts;
231 }
skia.committer@gmail.com32840172013-04-09 07:01:27 +0000232
caryclark@google.com07393ca2013-04-08 11:47:37 +0000233 SkPath::Verb verb() const {
234 return fVerb;
235 }
236
237 int windSum(int tIndex) const {
238 return fTs[tIndex].fWindSum;
239 }
240
241 int windValue(int tIndex) const {
242 return fTs[tIndex].fWindValue;
243 }
244
caryclark@google.com927b7022013-11-25 14:18:21 +0000245#if defined(SK_DEBUG) || DEBUG_WINDING
caryclark@google.com07393ca2013-04-08 11:47:37 +0000246 SkScalar xAtT(int index) const {
247 return xAtT(&fTs[index]);
248 }
caryclark@google.com927b7022013-11-25 14:18:21 +0000249#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +0000250
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000251#if DEBUG_VALIDATE
252 bool _xor() const { // FIXME: used only by SkOpAngle::debugValidateLoop()
253 return fXor;
254 }
255#endif
256
caryclark@google.com07393ca2013-04-08 11:47:37 +0000257 const SkPoint& xyAtT(const SkOpSpan* span) const {
258 return span->fPt;
259 }
260
caryclark@google.com07393ca2013-04-08 11:47:37 +0000261 const SkPoint& xyAtT(int index) const {
262 return xyAtT(&fTs[index]);
263 }
skia.committer@gmail.com32840172013-04-09 07:01:27 +0000264
caryclark@google.com927b7022013-11-25 14:18:21 +0000265#if defined(SK_DEBUG) || DEBUG_WINDING
caryclark@google.com07393ca2013-04-08 11:47:37 +0000266 SkScalar yAtT(int index) const {
267 return yAtT(&fTs[index]);
268 }
caryclark@google.com927b7022013-11-25 14:18:21 +0000269#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +0000270
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000271 const SkOpAngle* activeAngle(int index, int* start, int* end, bool* done,
272 bool* sortable) const;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000273 SkPoint activeLeftTop(int* firstT) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000274 bool activeOp(int index, int endIndex, int xorMiMask, int xorSuMask, SkPathOp op);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000275 bool activeWinding(int index, int endIndex);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000276 void addCubic(const SkPoint pts[4], bool operand, bool evenOdd);
277 void addCurveTo(int start, int end, SkPathWriter* path, bool active) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000278 void addEndSpan(int endIndex);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000279 void addLine(const SkPoint pts[2], bool operand, bool evenOdd);
280 void addOtherT(int index, double otherT, int otherIndex);
281 void addQuad(const SkPoint pts[3], bool operand, bool evenOdd);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000282 void addSimpleAngle(int endIndex);
283 int addSelfT(const SkPoint& pt, double newT);
284 void addStartSpan(int endIndex);
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000285 int addT(SkOpSegment* other, const SkPoint& pt, double newT);
caryclark@google.com570863f2013-09-16 15:55:01 +0000286 void addTCancel(const SkPoint& startPt, const SkPoint& endPt, SkOpSegment* other);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000287 void addTCoincident(const SkPoint& startPt, const SkPoint& endPt, double endT,
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000288 SkOpSegment* other);
289 const SkOpSpan* addTPair(double t, SkOpSegment* other, double otherT, bool borrowWind,
290 const SkPoint& pt);
caryclarkdac1d172014-06-17 05:15:38 -0700291 const SkOpSpan* addTPair(double t, SkOpSegment* other, double otherT, bool borrowWind,
292 const SkPoint& pt, const SkPoint& oPt);
293 void alignMultiples(SkTDArray<AlignedSpan>* aligned);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000294 bool alignSpan(int index, double thisT, const SkPoint& thisPt);
295 void alignSpanState(int start, int end);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000296 bool betweenTs(int lesser, double testT, int greater) const;
caryclarkdac1d172014-06-17 05:15:38 -0700297 void blindCancel(const SkCoincidence& coincidence, SkOpSegment* other);
298 void blindCoincident(const SkCoincidence& coincidence, SkOpSegment* other);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000299 bool calcAngles();
caryclarkdac1d172014-06-17 05:15:38 -0700300 double calcMissingTEnd(const SkOpSegment* ref, double loEnd, double min, double max,
301 double hiEnd, const SkOpSegment* other, int thisEnd);
302 double calcMissingTStart(const SkOpSegment* ref, double loEnd, double min, double max,
303 double hiEnd, const SkOpSegment* other, int thisEnd);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000304 void checkDuplicates();
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000305 void checkEnds();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000306 void checkMultiples();
307 void checkSmall();
caryclark@google.com570863f2013-09-16 15:55:01 +0000308 bool checkSmall(int index) const;
309 void checkTiny();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000310 int computeSum(int startIndex, int endIndex, SkOpAngle::IncludeType includeType);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000311 bool containsPt(const SkPoint& , int index, int endIndex) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000312 int crossedSpanY(const SkPoint& basePt, SkScalar* bestY, double* hitT, bool* hitSomething,
313 double mid, bool opp, bool current) const;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000314 bool findCoincidentMatch(const SkOpSpan* span, const SkOpSegment* other, int oStart, int oEnd,
315 int step, SkPoint* startPt, SkPoint* endPt, double* endT) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000316 SkOpSegment* findNextOp(SkTDArray<SkOpSpan*>* chase, int* nextStart, int* nextEnd,
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000317 bool* unsortable, SkPathOp op, int xorMiMask, int xorSuMask);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000318 SkOpSegment* findNextWinding(SkTDArray<SkOpSpan*>* chase, int* nextStart, int* nextEnd,
319 bool* unsortable);
320 SkOpSegment* findNextXor(int* nextStart, int* nextEnd, bool* unsortable);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000321 int findExactT(double t, const SkOpSegment* ) const;
caryclarkdac1d172014-06-17 05:15:38 -0700322 int findOtherT(double t, const SkOpSegment* ) const;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000323 int findT(double t, const SkPoint& , const SkOpSegment* ) const;
324 SkOpSegment* findTop(int* tIndex, int* endIndex, bool* unsortable, bool firstPass);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000325 void fixOtherTIndex();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000326 void initWinding(int start, int end, SkOpAngle::IncludeType angleIncludeType);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000327 void initWinding(int start, int end, double tHit, int winding, SkScalar hitDx, int oppWind,
caryclark@google.com570863f2013-09-16 15:55:01 +0000328 SkScalar hitOppDx);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000329 bool isMissing(double startT, const SkPoint& pt) const;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000330 bool isTiny(const SkOpAngle* angle) const;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000331 bool joinCoincidence(SkOpSegment* other, double otherT, const SkPoint& otherPt, int step,
332 bool cancel);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000333 SkOpSpan* markAndChaseDoneBinary(int index, int endIndex);
334 SkOpSpan* markAndChaseDoneUnary(int index, int endIndex);
335 SkOpSpan* markAndChaseWinding(const SkOpAngle* angle, int winding, int oppWinding);
336 SkOpSpan* markAngle(int maxWinding, int sumWinding, int oppMaxWinding, int oppSumWinding,
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000337 const SkOpAngle* angle);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000338 void markDone(int index, int winding);
339 void markDoneBinary(int index);
340 void markDoneUnary(int index);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000341 bool nextCandidate(int* start, int* end) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000342 int nextSpan(int from, int step) const;
caryclarkdac1d172014-06-17 05:15:38 -0700343 void pinT(const SkPoint& pt, double* t);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000344 void setUpWindings(int index, int endIndex, int* sumMiWinding, int* sumSuWinding,
345 int* maxWinding, int* sumWinding, int* oppMaxWinding, int* oppSumWinding);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000346 void sortAngles();
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000347 bool subDivide(int start, int end, SkPoint edge[4]) const;
348 bool subDivide(int start, int end, SkDCubic* result) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000349 void undoneSpan(int* start, int* end);
350 int updateOppWindingReverse(const SkOpAngle* angle) const;
351 int updateWindingReverse(const SkOpAngle* angle) const;
352 static bool UseInnerWinding(int outerWinding, int innerWinding);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000353 static bool UseInnerWindingReverse(int outerWinding, int innerWinding);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000354 int windingAtT(double tHit, int tIndex, bool crossOpp, SkScalar* dx) const;
355 int windSum(const SkOpAngle* angle) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000356// available for testing only
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000357#if defined(SK_DEBUG) || !FORCE_RELEASE
caryclark@google.com07393ca2013-04-08 11:47:37 +0000358 int debugID() const {
359 return fID;
360 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000361#else
362 int debugID() const {
363 return -1;
364 }
caryclark@google.com07393ca2013-04-08 11:47:37 +0000365#endif
caryclark@google.coma5e55922013-05-07 18:51:31 +0000366#if DEBUG_ACTIVE_SPANS || DEBUG_ACTIVE_SPANS_FIRST_ONLY
caryclark@google.com07393ca2013-04-08 11:47:37 +0000367 void debugShowActiveSpans() const;
368#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +0000369#if DEBUG_CONCIDENT
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000370 void debugShowTs(const char* prefix) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000371#endif
372#if DEBUG_SHOW_WINDING
373 int debugShowWindingValues(int slotCount, int ofInterest) const;
374#endif
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000375 const SkTDArray<SkOpSpan>& debugSpans() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000376 void debugValidate() const;
377 // available to testing only
caryclarkdac1d172014-06-17 05:15:38 -0700378 const SkOpAngle* debugLastAngle() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000379 void dumpAngles() const;
380 void dumpContour(int firstID, int lastID) const;
381 void dumpPts() const;
382 void dumpSpans() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000383
384private:
caryclark@google.com570863f2013-09-16 15:55:01 +0000385 struct MissingSpan {
caryclark@google.com570863f2013-09-16 15:55:01 +0000386 double fT;
387 double fEndT;
388 SkOpSegment* fSegment;
389 SkOpSegment* fOther;
390 double fOtherT;
391 SkPoint fPt;
392 };
393
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000394 const SkOpAngle* activeAngleInner(int index, int* start, int* end, bool* done,
395 bool* sortable) const;
396 const SkOpAngle* activeAngleOther(int index, int* start, int* end, bool* done,
397 bool* sortable) const;
caryclark@google.com570863f2013-09-16 15:55:01 +0000398 bool activeOp(int xorMiMask, int xorSuMask, int index, int endIndex, SkPathOp op,
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000399 int* sumMiWinding, int* sumSuWinding);
400 bool activeWinding(int index, int endIndex, int* sumWinding);
caryclark@google.com570863f2013-09-16 15:55:01 +0000401 void addCancelOutsides(const SkPoint& startPt, const SkPoint& endPt, SkOpSegment* other);
402 void addCoinOutsides(const SkPoint& startPt, const SkPoint& endPt, SkOpSegment* other);
caryclarkdac1d172014-06-17 05:15:38 -0700403 SkOpAngle* addSingletonAngleDown(SkOpSegment** otherPtr, SkOpAngle** );
404 SkOpAngle* addSingletonAngleUp(SkOpSegment** otherPtr, SkOpAngle** );
405 SkOpAngle* addSingletonAngles(int step);
406 void alignSpan(const SkPoint& newPt, double newT, const SkOpSegment* other, double otherT,
407 const SkOpSegment* other2, SkOpSpan* oSpan, SkTDArray<AlignedSpan>* );
caryclark@google.com570863f2013-09-16 15:55:01 +0000408 bool betweenPoints(double midT, const SkPoint& pt1, const SkPoint& pt2) const;
caryclarkdac1d172014-06-17 05:15:38 -0700409 void bumpCoincidentBlind(bool binary, int index, int last);
caryclark@google.com570863f2013-09-16 15:55:01 +0000410 void bumpCoincidentThis(const SkOpSpan& oTest, bool binary, int* index,
411 SkTArray<SkPoint, true>* outsideTs);
caryclarkdac1d172014-06-17 05:15:38 -0700412 void bumpCoincidentOBlind(int index, int last);
caryclark@google.com570863f2013-09-16 15:55:01 +0000413 void bumpCoincidentOther(const SkOpSpan& oTest, int* index,
414 SkTArray<SkPoint, true>* outsideTs);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000415 bool bumpSpan(SkOpSpan* span, int windDelta, int oppDelta);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000416 bool calcLoopSpanCount(const SkOpSpan& thisSpan, int* smallCounts);
caryclarkdac1d172014-06-17 05:15:38 -0700417 bool checkForSmall(const SkOpSpan* span, const SkPoint& pt, double newT,
418 int* less, int* more) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000419 void checkLinks(const SkOpSpan* ,
420 SkTArray<MissingSpan, true>* missingSpans) const;
421 static void CheckOneLink(const SkOpSpan* test, const SkOpSpan* oSpan,
422 const SkOpSpan* oFirst, const SkOpSpan* oLast,
423 const SkOpSpan** missingPtr,
424 SkTArray<MissingSpan, true>* missingSpans);
425 int checkSetAngle(int tIndex) const;
426 void checkSmallCoincidence(const SkOpSpan& span, SkTArray<MissingSpan, true>* );
caryclarkdac1d172014-06-17 05:15:38 -0700427 bool coincidentSmall(const SkPoint& pt, double t, const SkOpSegment* other) const;
caryclarke4097e32014-06-18 07:24:19 -0700428 bool clockwise(int tStart, int tEnd, bool* swap) const;
caryclark@google.com570863f2013-09-16 15:55:01 +0000429 static void ComputeOneSum(const SkOpAngle* baseAngle, SkOpAngle* nextAngle,
430 SkOpAngle::IncludeType );
431 static void ComputeOneSumReverse(const SkOpAngle* baseAngle, SkOpAngle* nextAngle,
432 SkOpAngle::IncludeType );
caryclarkdac1d172014-06-17 05:15:38 -0700433 bool containsT(double t, const SkOpSegment* other, double otherT) const;
caryclark@google.com570863f2013-09-16 15:55:01 +0000434 bool decrementSpan(SkOpSpan* span);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000435 int findEndSpan(int endIndex) const;
436 int findStartSpan(int startIndex) const;
437 int firstActive(int tIndex) const;
438 const SkOpSpan& firstSpan(const SkOpSpan& thisSpan) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000439 void init(const SkPoint pts[], SkPath::Verb verb, bool operand, bool evenOdd);
caryclarkdac1d172014-06-17 05:15:38 -0700440 bool inCoincidentSpan(double t, const SkOpSegment* other) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000441 bool inLoop(const SkOpAngle* baseAngle, int spanCount, int* indexPtr) const;
caryclarkdac1d172014-06-17 05:15:38 -0700442#if OLD_CHASE
caryclark@google.com570863f2013-09-16 15:55:01 +0000443 bool isSimple(int end) const;
caryclarkdac1d172014-06-17 05:15:38 -0700444#else
445 SkOpSegment* isSimple(int* end, int* step);
446#endif
caryclark@google.com570863f2013-09-16 15:55:01 +0000447 bool isTiny(int index) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000448 const SkOpSpan& lastSpan(const SkOpSpan& thisSpan) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000449 void matchWindingValue(int tIndex, double t, bool borrowWind);
450 SkOpSpan* markAndChaseDone(int index, int endIndex, int winding);
451 SkOpSpan* markAndChaseDoneBinary(const SkOpAngle* angle, int winding, int oppWinding);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000452 SkOpSpan* markAndChaseWinding(const SkOpAngle* angle, int winding);
453 SkOpSpan* markAndChaseWinding(int index, int endIndex, int winding);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000454 SkOpSpan* markAndChaseWinding(int index, int endIndex, int winding, int oppWinding);
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000455 SkOpSpan* markAngle(int maxWinding, int sumWinding, const SkOpAngle* angle);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000456 void markDoneBinary(int index, int winding, int oppWinding);
457 SkOpSpan* markAndChaseDoneUnary(const SkOpAngle* angle, int winding);
458 void markOneDone(const char* funName, int tIndex, int winding);
459 void markOneDoneBinary(const char* funName, int tIndex);
460 void markOneDoneBinary(const char* funName, int tIndex, int winding, int oppWinding);
461 void markOneDoneUnary(const char* funName, int tIndex);
caryclark@google.com570863f2013-09-16 15:55:01 +0000462 SkOpSpan* markOneWinding(const char* funName, int tIndex, int winding);
463 SkOpSpan* markOneWinding(const char* funName, int tIndex, int winding, int oppWinding);
464 void markWinding(int index, int winding);
465 void markWinding(int index, int winding, int oppWinding);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000466 bool monotonicInY(int tStart, int tEnd) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000467
caryclarkdac1d172014-06-17 05:15:38 -0700468 bool multipleEnds() const { return fTs[count() - 2].fT == 1; }
469 bool multipleStarts() const { return fTs[1].fT == 0; }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000470
caryclarkdac1d172014-06-17 05:15:38 -0700471 SkOpSegment* nextChase(int* index, int* step, int* min, SkOpSpan** last);
caryclark@google.com570863f2013-09-16 15:55:01 +0000472 int nextExactSpan(int from, int step) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000473 bool serpentine(int tStart, int tEnd) const;
caryclarkdac1d172014-06-17 05:15:38 -0700474 void setCoincidentRange(const SkPoint& startPt, const SkPoint& endPt, SkOpSegment* other);
475 void setFromAngle(int endIndex, SkOpAngle* );
476 void setToAngle(int endIndex, SkOpAngle* );
caryclark@google.com570863f2013-09-16 15:55:01 +0000477 void setUpWindings(int index, int endIndex, int* sumMiWinding,
478 int* maxWinding, int* sumWinding);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000479 void subDivideBounds(int start, int end, SkPathOpsBounds* bounds) const;
caryclark@google.com570863f2013-09-16 15:55:01 +0000480 static void TrackOutsidePair(SkTArray<SkPoint, true>* outsideTs, const SkPoint& endPt,
481 const SkPoint& startPt);
482 static void TrackOutside(SkTArray<SkPoint, true>* outsideTs, const SkPoint& startPt);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000483 int updateOppWinding(int index, int endIndex) const;
484 int updateOppWinding(const SkOpAngle* angle) const;
485 int updateWinding(int index, int endIndex) const;
486 int updateWinding(const SkOpAngle* angle) const;
caryclark@google.com570863f2013-09-16 15:55:01 +0000487 int updateWindingReverse(int index, int endIndex) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000488 SkOpSpan* verifyOneWinding(const char* funName, int tIndex);
489 SkOpSpan* verifyOneWindingU(const char* funName, int tIndex);
caryclark@google.com927b7022013-11-25 14:18:21 +0000490
491 SkScalar xAtT(const SkOpSpan* span) const {
492 return xyAtT(span).fX;
493 }
494
495 SkScalar yAtT(const SkOpSpan* span) const {
496 return xyAtT(span).fY;
497 }
498
caryclark@google.com07393ca2013-04-08 11:47:37 +0000499 void zeroSpan(SkOpSpan* span);
500
501#if DEBUG_SWAP_TOP
502 bool controlsContainedByEnds(int tStart, int tEnd) const;
503#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000504 void debugAddAngle(int start, int end);
caryclark@google.com07393ca2013-04-08 11:47:37 +0000505#if DEBUG_CONCIDENT
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000506 void debugAddTPair(double t, const SkOpSegment& other, double otherT) const;
507#endif
508#if DEBUG_ANGLE
509 void debugCheckPointsEqualish(int tStart, int tEnd) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000510#endif
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000511#if DEBUG_SWAP_TOP
512 int debugInflections(int index, int endIndex) const;
513#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +0000514#if DEBUG_MARK_DONE || DEBUG_UNSORTABLE
515 void debugShowNewWinding(const char* fun, const SkOpSpan& span, int winding);
516 void debugShowNewWinding(const char* fun, const SkOpSpan& span, int winding, int oppWinding);
517#endif
518#if DEBUG_WINDING
519 static char as_digit(int value) {
520 return value < 0 ? '?' : value <= 9 ? '0' + value : '+';
521 }
522#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000523 // available to testing only
524 void debugConstruct();
525 void debugConstructCubic(SkPoint shortQuad[4]);
526 void debugConstructLine(SkPoint shortQuad[2]);
527 void debugConstructQuad(SkPoint shortQuad[3]);
528 void debugReset();
caryclark@google.com570863f2013-09-16 15:55:01 +0000529 void dumpDPts() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000530 void dumpSpan(int index) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000531
532 const SkPoint* fPts;
533 SkPathOpsBounds fBounds;
caryclark@google.comd892bd82013-06-17 14:10:36 +0000534 // FIXME: can't convert to SkTArray because it uses insert
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000535 SkTDArray<SkOpSpan> fTs; // 2+ (always includes t=0 t=1) -- at least (number of spans) + 1
caryclarkdac1d172014-06-17 05:15:38 -0700536 SkOpAngleSet fAngles; // empty or 2+ -- (number of non-zero spans) * 2
caryclark@google.com07393ca2013-04-08 11:47:37 +0000537 // OPTIMIZATION: could pack donespans, verb, operand, xor into 1 int-sized value
538 int fDoneSpans; // quick check that segment is finished
539 // OPTIMIZATION: force the following to be byte-sized
540 SkPath::Verb fVerb;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000541 bool fLoop; // set if cubic intersects itself
caryclarkdac1d172014-06-17 05:15:38 -0700542 bool fMultiples; // set if curve intersects multiple other curves at one interior point
caryclark@google.com07393ca2013-04-08 11:47:37 +0000543 bool fOperand;
544 bool fXor; // set if original contour had even-odd fill
545 bool fOppXor; // set if opposite operand had even-odd fill
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000546 bool fSmall; // set if some span is small
547 bool fTiny; // set if some span is tiny
548#if defined(SK_DEBUG) || !FORCE_RELEASE
caryclark@google.com07393ca2013-04-08 11:47:37 +0000549 int fID;
550#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000551
552 friend class PathOpsSegmentTester;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000553};
554
555#endif