blob: 7b0f19d877cc0e86e705e7262d3fb6ad25e79cc3 [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 */
Hal Canary03a7f5f2017-02-10 09:06:38 -05007#ifndef PathOpsTSectDebug_DEFINED
8#define PathOpsTSectDebug_DEFINED
caryclark45fa4472015-01-16 07:04:10 -08009
10#include "SkPathOpsTSect.h"
11
caryclark1049f122015-04-20 08:31:59 -070012template<typename TCurve, typename OppCurve>
caryclarked0935a2015-10-22 07:23:52 -070013char SkTCoincident<TCurve, OppCurve>::dumpIsCoincidentStr() const {
caryclark6c3b9cd2016-09-26 05:36:58 -070014 if (!!fMatch != fMatch) {
caryclarked0935a2015-10-22 07:23:52 -070015 return '?';
16 }
caryclark6c3b9cd2016-09-26 05:36:58 -070017 return fMatch ? '*' : 0;
caryclarked0935a2015-10-22 07:23:52 -070018}
19
20template<typename TCurve, typename OppCurve>
caryclark1049f122015-04-20 08:31:59 -070021void SkTCoincident<TCurve, OppCurve>::dump() const {
22 SkDebugf("t=%1.9g pt=(%1.9g,%1.9g)%s\n", fPerpT, fPerpPt.fX, fPerpPt.fY,
caryclark6c3b9cd2016-09-26 05:36:58 -070023 fMatch ? " match" : "");
caryclark1049f122015-04-20 08:31:59 -070024}
25
26template<typename TCurve, typename OppCurve>
27const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugSpan(int id) const {
28 const SkTSpan<TCurve, OppCurve>* test = fHead;
caryclark54359292015-03-26 07:52:43 -070029 do {
30 if (test->debugID() == id) {
31 return test;
32 }
33 } while ((test = test->next()));
halcanary96fcdcc2015-08-27 07:41:13 -070034 return nullptr;
caryclark54359292015-03-26 07:52:43 -070035}
36
caryclark1049f122015-04-20 08:31:59 -070037template<typename TCurve, typename OppCurve>
38const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugT(double t) const {
39 const SkTSpan<TCurve, OppCurve>* test = fHead;
halcanary96fcdcc2015-08-27 07:41:13 -070040 const SkTSpan<TCurve, OppCurve>* closest = nullptr;
caryclark54359292015-03-26 07:52:43 -070041 double bestDist = DBL_MAX;
42 do {
43 if (between(test->fStartT, t, test->fEndT)) {
44 return test;
45 }
46 double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
47 if (bestDist > testDist) {
48 bestDist = testDist;
49 closest = test;
50 }
51 } while ((test = test->next()));
52 SkASSERT(closest);
53 return closest;
54}
55
caryclark1049f122015-04-20 08:31:59 -070056template<typename TCurve, typename OppCurve>
57void SkTSect<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -070058 dumpCommon(fHead);
59}
60
61extern int gDumpTSectNum;
62
caryclark1049f122015-04-20 08:31:59 -070063template<typename TCurve, typename OppCurve>
64void SkTSect<TCurve, OppCurve>::dumpBoth(SkTSect<OppCurve, TCurve>* opp) const {
caryclark54359292015-03-26 07:52:43 -070065#if DEBUG_T_SECT_DUMP <= 2
66#if DEBUG_T_SECT_DUMP == 2
67 SkDebugf("%d ", ++gDumpTSectNum);
68#endif
69 this->dump();
Cary Clarkb8421ed2018-03-14 15:55:02 -040070 SkDebugf("\n");
caryclark54359292015-03-26 07:52:43 -070071 opp->dump();
72 SkDebugf("\n");
73#elif DEBUG_T_SECT_DUMP == 3
74 SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
75 if (this->fHead) {
76 this->dumpCurves();
77 }
78 if (opp->fHead) {
caryclark1049f122015-04-20 08:31:59 -070079 opp->dumpCurves();
caryclark54359292015-03-26 07:52:43 -070080 }
81 SkDebugf("</div>\n\n");
82#endif
83}
84
caryclark1049f122015-04-20 08:31:59 -070085template<typename TCurve, typename OppCurve>
86void SkTSect<TCurve, OppCurve>::dumpBounded(int id) const {
87 const SkTSpan<TCurve, OppCurve>* bounded = debugSpan(id);
caryclark54359292015-03-26 07:52:43 -070088 if (!bounded) {
89 SkDebugf("no span matches %d\n", id);
90 return;
91 }
caryclark1049f122015-04-20 08:31:59 -070092 const SkTSpan<OppCurve, TCurve>* test = bounded->debugOpp()->fHead;
caryclark54359292015-03-26 07:52:43 -070093 do {
94 if (test->findOppSpan(bounded)) {
95 test->dump();
caryclark26ad22a2015-10-16 09:03:38 -070096 SkDebugf(" ");
caryclark54359292015-03-26 07:52:43 -070097 }
98 } while ((test = test->next()));
caryclark26ad22a2015-10-16 09:03:38 -070099 SkDebugf("\n");
caryclark54359292015-03-26 07:52:43 -0700100}
101
caryclark1049f122015-04-20 08:31:59 -0700102template<typename TCurve, typename OppCurve>
103void SkTSect<TCurve, OppCurve>::dumpBounds() const {
104 const SkTSpan<TCurve, OppCurve>* test = fHead;
105 do {
106 test->dumpBounds();
107 } while ((test = test->next()));
108}
109
110template<typename TCurve, typename OppCurve>
111void SkTSect<TCurve, OppCurve>::dumpCoin() const {
caryclark54359292015-03-26 07:52:43 -0700112 dumpCommon(fCoincident);
113}
114
caryclark1049f122015-04-20 08:31:59 -0700115template<typename TCurve, typename OppCurve>
116void SkTSect<TCurve, OppCurve>::dumpCoinCurves() const {
caryclark54359292015-03-26 07:52:43 -0700117 dumpCommonCurves(fCoincident);
118}
119
caryclark1049f122015-04-20 08:31:59 -0700120template<typename TCurve, typename OppCurve>
121void SkTSect<TCurve, OppCurve>::dumpCommon(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700122 SkDebugf("id=%d", debugID());
caryclark45fa4472015-01-16 07:04:10 -0800123 if (!test) {
124 SkDebugf(" (empty)");
125 return;
126 }
127 do {
128 SkDebugf(" ");
caryclark54359292015-03-26 07:52:43 -0700129 test->dump();
caryclark45fa4472015-01-16 07:04:10 -0800130 } while ((test = test->next()));
131}
132
caryclark1049f122015-04-20 08:31:59 -0700133template<typename TCurve, typename OppCurve>
134void SkTSect<TCurve, OppCurve>::dumpCommonCurves(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700135 do {
136 test->fPart.dumpID(test->debugID());
137 } while ((test = test->next()));
caryclark45fa4472015-01-16 07:04:10 -0800138}
139
caryclark1049f122015-04-20 08:31:59 -0700140template<typename TCurve, typename OppCurve>
141void SkTSect<TCurve, OppCurve>::dumpCurves() const {
caryclark54359292015-03-26 07:52:43 -0700142 dumpCommonCurves(fHead);
reed0dc4dd62015-03-24 13:55:33 -0700143}
144
caryclark1049f122015-04-20 08:31:59 -0700145template<typename TCurve, typename OppCurve>
146const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugSpan(int id) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700147 return SkDEBUGRELEASE(fDebugSect->debugSpan(id), nullptr);
reed0dc4dd62015-03-24 13:55:33 -0700148}
reed0dc4dd62015-03-24 13:55:33 -0700149
caryclark1049f122015-04-20 08:31:59 -0700150template<typename TCurve, typename OppCurve>
151const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugT(double t) const {
halcanary96fcdcc2015-08-27 07:41:13 -0700152 return SkDEBUGRELEASE(fDebugSect->debugT(t), nullptr);
caryclark54359292015-03-26 07:52:43 -0700153}
154
caryclark1049f122015-04-20 08:31:59 -0700155template<typename TCurve, typename OppCurve>
caryclark26ad22a2015-10-16 09:03:38 -0700156void SkTSpan<TCurve, OppCurve>::dumpAll() const {
157 dumpID();
158 SkDebugf("=(%g,%g) [", fStartT, fEndT);
159 const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
160 while (testBounded) {
161 const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
162 const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
163 span->dumpID();
164 SkDebugf("=(%g,%g)", span->fStartT, span->fEndT);
165 if (next) {
166 SkDebugf(" ");
167 }
168 testBounded = next;
169 }
170 SkDebugf("]\n");
171}
172
173template<typename TCurve, typename OppCurve>
caryclark1049f122015-04-20 08:31:59 -0700174void SkTSpan<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -0700175 dumpID();
176 SkDebugf("=(%g,%g) [", fStartT, fEndT);
caryclark1049f122015-04-20 08:31:59 -0700177 const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
caryclark54359292015-03-26 07:52:43 -0700178 while (testBounded) {
caryclark1049f122015-04-20 08:31:59 -0700179 const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
180 const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
caryclark54359292015-03-26 07:52:43 -0700181 span->dumpID();
182 if (next) {
183 SkDebugf(",");
184 }
185 testBounded = next;
186 }
187 SkDebugf("]");
188}
189
caryclark1049f122015-04-20 08:31:59 -0700190template<typename TCurve, typename OppCurve>
191void SkTSpan<TCurve, OppCurve>::dumpBounded(int id) const {
192 SkDEBUGCODE(fDebugSect->dumpBounded(id));
caryclark54359292015-03-26 07:52:43 -0700193}
194
caryclark1049f122015-04-20 08:31:59 -0700195template<typename TCurve, typename OppCurve>
196void SkTSpan<TCurve, OppCurve>::dumpBounds() const {
197 dumpID();
198 SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n",
199 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax,
halcanary9d524f22016-03-29 09:03:52 -0700200 fCollapsed ? " collapsed" : "");
caryclark1049f122015-04-20 08:31:59 -0700201}
202
203template<typename TCurve, typename OppCurve>
204void SkTSpan<TCurve, OppCurve>::dumpCoin() const {
205 dumpID();
206 SkDebugf(" coinStart ");
207 fCoinStart.dump();
208 SkDebugf(" coinEnd ");
209 fCoinEnd.dump();
210}
211
212template<typename TCurve, typename OppCurve>
213void SkTSpan<TCurve, OppCurve>::dumpID() const {
caryclarked0935a2015-10-22 07:23:52 -0700214 char cS = fCoinStart.dumpIsCoincidentStr();
215 if (cS) {
216 SkDebugf("%c", cS);
reed0dc4dd62015-03-24 13:55:33 -0700217 }
caryclark54359292015-03-26 07:52:43 -0700218 SkDebugf("%d", debugID());
caryclarked0935a2015-10-22 07:23:52 -0700219 char cE = fCoinEnd.dumpIsCoincidentStr();
220 if (cE) {
221 SkDebugf("%c", cE);
reed0dc4dd62015-03-24 13:55:33 -0700222 }
caryclark45fa4472015-01-16 07:04:10 -0800223}
Hal Canary03a7f5f2017-02-10 09:06:38 -0500224#endif // PathOpsTSectDebug_DEFINED