blob: 4e04db794b8f0a315e6e4a838b5f52393f50b8a4 [file] [log] [blame]
caryclark45fa4472015-01-16 07:04:10 -08001/*
2 * Copyright 2014 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
8#include "SkPathOpsTSect.h"
9
caryclark1049f122015-04-20 08:31:59 -070010template<typename TCurve, typename OppCurve>
caryclarked0935a2015-10-22 07:23:52 -070011char SkTCoincident<TCurve, OppCurve>::dumpIsCoincidentStr() const {
12 if (!!fCoincident != fCoincident) {
13 return '?';
14 }
15 return fCoincident ? '*' : 0;
16}
17
18template<typename TCurve, typename OppCurve>
caryclark1049f122015-04-20 08:31:59 -070019void SkTCoincident<TCurve, OppCurve>::dump() const {
20 SkDebugf("t=%1.9g pt=(%1.9g,%1.9g)%s\n", fPerpT, fPerpPt.fX, fPerpPt.fY,
21 fCoincident ? " coincident" : "");
22}
23
24template<typename TCurve, typename OppCurve>
25const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugSpan(int id) const {
26 const SkTSpan<TCurve, OppCurve>* test = fHead;
caryclark54359292015-03-26 07:52:43 -070027 do {
28 if (test->debugID() == id) {
29 return test;
30 }
31 } while ((test = test->next()));
halcanary96fcdcc2015-08-27 07:41:13 -070032 return nullptr;
caryclark54359292015-03-26 07:52:43 -070033}
34
caryclark1049f122015-04-20 08:31:59 -070035template<typename TCurve, typename OppCurve>
36const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugT(double t) const {
37 const SkTSpan<TCurve, OppCurve>* test = fHead;
halcanary96fcdcc2015-08-27 07:41:13 -070038 const SkTSpan<TCurve, OppCurve>* closest = nullptr;
caryclark54359292015-03-26 07:52:43 -070039 double bestDist = DBL_MAX;
40 do {
41 if (between(test->fStartT, t, test->fEndT)) {
42 return test;
43 }
44 double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
45 if (bestDist > testDist) {
46 bestDist = testDist;
47 closest = test;
48 }
49 } while ((test = test->next()));
50 SkASSERT(closest);
51 return closest;
52}
53
caryclark1049f122015-04-20 08:31:59 -070054template<typename TCurve, typename OppCurve>
55void SkTSect<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -070056 dumpCommon(fHead);
57}
58
59extern int gDumpTSectNum;
60
caryclark1049f122015-04-20 08:31:59 -070061template<typename TCurve, typename OppCurve>
62void SkTSect<TCurve, OppCurve>::dumpBoth(SkTSect<OppCurve, TCurve>* opp) const {
caryclark54359292015-03-26 07:52:43 -070063#if DEBUG_T_SECT_DUMP <= 2
64#if DEBUG_T_SECT_DUMP == 2
65 SkDebugf("%d ", ++gDumpTSectNum);
66#endif
67 this->dump();
68 SkDebugf(" ");
69 opp->dump();
70 SkDebugf("\n");
71#elif DEBUG_T_SECT_DUMP == 3
72 SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
73 if (this->fHead) {
74 this->dumpCurves();
75 }
76 if (opp->fHead) {
caryclark1049f122015-04-20 08:31:59 -070077 opp->dumpCurves();
caryclark54359292015-03-26 07:52:43 -070078 }
79 SkDebugf("</div>\n\n");
80#endif
81}
82
caryclark1049f122015-04-20 08:31:59 -070083template<typename TCurve, typename OppCurve>
84void SkTSect<TCurve, OppCurve>::dumpBounded(int id) const {
85 const SkTSpan<TCurve, OppCurve>* bounded = debugSpan(id);
caryclark54359292015-03-26 07:52:43 -070086 if (!bounded) {
87 SkDebugf("no span matches %d\n", id);
88 return;
89 }
caryclark1049f122015-04-20 08:31:59 -070090 const SkTSpan<OppCurve, TCurve>* test = bounded->debugOpp()->fHead;
caryclark54359292015-03-26 07:52:43 -070091 do {
92 if (test->findOppSpan(bounded)) {
93 test->dump();
caryclark26ad22a2015-10-16 09:03:38 -070094 SkDebugf(" ");
caryclark54359292015-03-26 07:52:43 -070095 }
96 } while ((test = test->next()));
caryclark26ad22a2015-10-16 09:03:38 -070097 SkDebugf("\n");
caryclark54359292015-03-26 07:52:43 -070098}
99
caryclark1049f122015-04-20 08:31:59 -0700100template<typename TCurve, typename OppCurve>
101void SkTSect<TCurve, OppCurve>::dumpBounds() const {
102 const SkTSpan<TCurve, OppCurve>* test = fHead;
103 do {
104 test->dumpBounds();
105 } while ((test = test->next()));
106}
107
108template<typename TCurve, typename OppCurve>
109void SkTSect<TCurve, OppCurve>::dumpCoin() const {
caryclark54359292015-03-26 07:52:43 -0700110 dumpCommon(fCoincident);
111}
112
caryclark1049f122015-04-20 08:31:59 -0700113template<typename TCurve, typename OppCurve>
114void SkTSect<TCurve, OppCurve>::dumpCoinCurves() const {
caryclark54359292015-03-26 07:52:43 -0700115 dumpCommonCurves(fCoincident);
116}
117
caryclark1049f122015-04-20 08:31:59 -0700118template<typename TCurve, typename OppCurve>
119void SkTSect<TCurve, OppCurve>::dumpCommon(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700120 SkDebugf("id=%d", debugID());
caryclark45fa4472015-01-16 07:04:10 -0800121 if (!test) {
122 SkDebugf(" (empty)");
123 return;
124 }
125 do {
126 SkDebugf(" ");
caryclark54359292015-03-26 07:52:43 -0700127 test->dump();
caryclark45fa4472015-01-16 07:04:10 -0800128 } while ((test = test->next()));
129}
130
caryclark1049f122015-04-20 08:31:59 -0700131template<typename TCurve, typename OppCurve>
132void SkTSect<TCurve, OppCurve>::dumpCommonCurves(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700133 do {
134 test->fPart.dumpID(test->debugID());
135 } while ((test = test->next()));
caryclark45fa4472015-01-16 07:04:10 -0800136}
137
caryclark1049f122015-04-20 08:31:59 -0700138template<typename TCurve, typename OppCurve>
139void SkTSect<TCurve, OppCurve>::dumpCurves() const {
caryclark54359292015-03-26 07:52:43 -0700140 dumpCommonCurves(fHead);
reed0dc4dd62015-03-24 13:55:33 -0700141}
142
caryclark1049f122015-04-20 08:31:59 -0700143template<typename TCurve, typename OppCurve>
144const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugSpan(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700145 return SkDEBUGRELEASE(fDebugSect->debugSpan(id), nullptr);
reed0dc4dd62015-03-24 13:55:33 -0700146}
reed0dc4dd62015-03-24 13:55:33 -0700147
caryclark1049f122015-04-20 08:31:59 -0700148template<typename TCurve, typename OppCurve>
149const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugT(double t) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700150 return SkDEBUGRELEASE(fDebugSect->debugT(t), nullptr);
caryclark54359292015-03-26 07:52:43 -0700151}
152
caryclark1049f122015-04-20 08:31:59 -0700153template<typename TCurve, typename OppCurve>
caryclark26ad22a2015-10-16 09:03:38 -0700154void SkTSpan<TCurve, OppCurve>::dumpAll() const {
155 dumpID();
156 SkDebugf("=(%g,%g) [", fStartT, fEndT);
157 const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
158 while (testBounded) {
159 const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
160 const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
161 span->dumpID();
162 SkDebugf("=(%g,%g)", span->fStartT, span->fEndT);
163 if (next) {
164 SkDebugf(" ");
165 }
166 testBounded = next;
167 }
168 SkDebugf("]\n");
169}
170
171template<typename TCurve, typename OppCurve>
caryclark1049f122015-04-20 08:31:59 -0700172void SkTSpan<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -0700173 dumpID();
174 SkDebugf("=(%g,%g) [", fStartT, fEndT);
caryclark1049f122015-04-20 08:31:59 -0700175 const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
caryclark54359292015-03-26 07:52:43 -0700176 while (testBounded) {
caryclark1049f122015-04-20 08:31:59 -0700177 const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
178 const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
caryclark54359292015-03-26 07:52:43 -0700179 span->dumpID();
180 if (next) {
181 SkDebugf(",");
182 }
183 testBounded = next;
184 }
185 SkDebugf("]");
186}
187
caryclark1049f122015-04-20 08:31:59 -0700188template<typename TCurve, typename OppCurve>
189void SkTSpan<TCurve, OppCurve>::dumpBounded(int id) const {
190 SkDEBUGCODE(fDebugSect->dumpBounded(id));
caryclark54359292015-03-26 07:52:43 -0700191}
192
caryclark1049f122015-04-20 08:31:59 -0700193template<typename TCurve, typename OppCurve>
194void SkTSpan<TCurve, OppCurve>::dumpBounds() const {
195 dumpID();
196 SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n",
197 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax,
halcanary9d524f22016-03-29 09:03:52 -0700198 fCollapsed ? " collapsed" : "");
caryclark1049f122015-04-20 08:31:59 -0700199}
200
201template<typename TCurve, typename OppCurve>
202void SkTSpan<TCurve, OppCurve>::dumpCoin() const {
203 dumpID();
204 SkDebugf(" coinStart ");
205 fCoinStart.dump();
206 SkDebugf(" coinEnd ");
207 fCoinEnd.dump();
208}
209
210template<typename TCurve, typename OppCurve>
211void SkTSpan<TCurve, OppCurve>::dumpID() const {
caryclarked0935a2015-10-22 07:23:52 -0700212 char cS = fCoinStart.dumpIsCoincidentStr();
213 if (cS) {
214 SkDebugf("%c", cS);
reed0dc4dd62015-03-24 13:55:33 -0700215 }
caryclark54359292015-03-26 07:52:43 -0700216 SkDebugf("%d", debugID());
caryclarked0935a2015-10-22 07:23:52 -0700217 char cE = fCoinEnd.dumpIsCoincidentStr();
218 if (cE) {
219 SkDebugf("%c", cE);
reed0dc4dd62015-03-24 13:55:33 -0700220 }
caryclark45fa4472015-01-16 07:04:10 -0800221}