blob: 5780610c9b036c026239b7f90a60a155206f54b3 [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>
11void SkTCoincident<TCurve, OppCurve>::dump() const {
12 SkDebugf("t=%1.9g pt=(%1.9g,%1.9g)%s\n", fPerpT, fPerpPt.fX, fPerpPt.fY,
13 fCoincident ? " coincident" : "");
14}
15
16template<typename TCurve, typename OppCurve>
17const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugSpan(int id) const {
18 const SkTSpan<TCurve, OppCurve>* test = fHead;
caryclark54359292015-03-26 07:52:43 -070019 do {
20 if (test->debugID() == id) {
21 return test;
22 }
23 } while ((test = test->next()));
caryclark54359292015-03-26 07:52:43 -070024 return NULL;
25}
26
caryclark1049f122015-04-20 08:31:59 -070027template<typename TCurve, typename OppCurve>
28const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugT(double t) const {
29 const SkTSpan<TCurve, OppCurve>* test = fHead;
30 const SkTSpan<TCurve, OppCurve>* closest = NULL;
caryclark54359292015-03-26 07:52:43 -070031 double bestDist = DBL_MAX;
32 do {
33 if (between(test->fStartT, t, test->fEndT)) {
34 return test;
35 }
36 double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
37 if (bestDist > testDist) {
38 bestDist = testDist;
39 closest = test;
40 }
41 } while ((test = test->next()));
42 SkASSERT(closest);
43 return closest;
44}
45
caryclark1049f122015-04-20 08:31:59 -070046template<typename TCurve, typename OppCurve>
47void SkTSect<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -070048 dumpCommon(fHead);
49}
50
51extern int gDumpTSectNum;
52
caryclark1049f122015-04-20 08:31:59 -070053template<typename TCurve, typename OppCurve>
54void SkTSect<TCurve, OppCurve>::dumpBoth(SkTSect<OppCurve, TCurve>* opp) const {
caryclark54359292015-03-26 07:52:43 -070055#if DEBUG_T_SECT_DUMP <= 2
56#if DEBUG_T_SECT_DUMP == 2
57 SkDebugf("%d ", ++gDumpTSectNum);
58#endif
59 this->dump();
60 SkDebugf(" ");
61 opp->dump();
62 SkDebugf("\n");
63#elif DEBUG_T_SECT_DUMP == 3
64 SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
65 if (this->fHead) {
66 this->dumpCurves();
67 }
68 if (opp->fHead) {
caryclark1049f122015-04-20 08:31:59 -070069 opp->dumpCurves();
caryclark54359292015-03-26 07:52:43 -070070 }
71 SkDebugf("</div>\n\n");
72#endif
73}
74
caryclark1049f122015-04-20 08:31:59 -070075template<typename TCurve, typename OppCurve>
76void SkTSect<TCurve, OppCurve>::dumpBounded(int id) const {
77 const SkTSpan<TCurve, OppCurve>* bounded = debugSpan(id);
caryclark54359292015-03-26 07:52:43 -070078 if (!bounded) {
79 SkDebugf("no span matches %d\n", id);
80 return;
81 }
caryclark1049f122015-04-20 08:31:59 -070082 const SkTSpan<OppCurve, TCurve>* test = bounded->debugOpp()->fHead;
caryclark54359292015-03-26 07:52:43 -070083 do {
84 if (test->findOppSpan(bounded)) {
85 test->dump();
86 }
87 } while ((test = test->next()));
88}
89
caryclark1049f122015-04-20 08:31:59 -070090template<typename TCurve, typename OppCurve>
91void SkTSect<TCurve, OppCurve>::dumpBounds() const {
92 const SkTSpan<TCurve, OppCurve>* test = fHead;
93 do {
94 test->dumpBounds();
95 } while ((test = test->next()));
96}
97
98template<typename TCurve, typename OppCurve>
99void SkTSect<TCurve, OppCurve>::dumpCoin() const {
caryclark54359292015-03-26 07:52:43 -0700100 dumpCommon(fCoincident);
101}
102
caryclark1049f122015-04-20 08:31:59 -0700103template<typename TCurve, typename OppCurve>
104void SkTSect<TCurve, OppCurve>::dumpCoinCurves() const {
caryclark54359292015-03-26 07:52:43 -0700105 dumpCommonCurves(fCoincident);
106}
107
caryclark1049f122015-04-20 08:31:59 -0700108template<typename TCurve, typename OppCurve>
109void SkTSect<TCurve, OppCurve>::dumpCommon(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700110 SkDebugf("id=%d", debugID());
caryclark45fa4472015-01-16 07:04:10 -0800111 if (!test) {
112 SkDebugf(" (empty)");
113 return;
114 }
115 do {
116 SkDebugf(" ");
caryclark54359292015-03-26 07:52:43 -0700117 test->dump();
caryclark45fa4472015-01-16 07:04:10 -0800118 } while ((test = test->next()));
119}
120
caryclark1049f122015-04-20 08:31:59 -0700121template<typename TCurve, typename OppCurve>
122void SkTSect<TCurve, OppCurve>::dumpCommonCurves(const SkTSpan<TCurve, OppCurve>* test) const {
caryclark54359292015-03-26 07:52:43 -0700123 do {
124 test->fPart.dumpID(test->debugID());
125 } while ((test = test->next()));
caryclark45fa4472015-01-16 07:04:10 -0800126}
127
caryclark1049f122015-04-20 08:31:59 -0700128template<typename TCurve, typename OppCurve>
129void SkTSect<TCurve, OppCurve>::dumpCurves() const {
caryclark54359292015-03-26 07:52:43 -0700130 dumpCommonCurves(fHead);
reed0dc4dd62015-03-24 13:55:33 -0700131}
132
caryclark1049f122015-04-20 08:31:59 -0700133template<typename TCurve, typename OppCurve>
134const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugSpan(int id) const {
135 return SkDEBUGRELEASE(fDebugSect->debugSpan(id), NULL);
reed0dc4dd62015-03-24 13:55:33 -0700136}
reed0dc4dd62015-03-24 13:55:33 -0700137
caryclark1049f122015-04-20 08:31:59 -0700138template<typename TCurve, typename OppCurve>
139const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugT(double t) const {
140 return SkDEBUGRELEASE(fDebugSect->debugT(t), NULL);
caryclark54359292015-03-26 07:52:43 -0700141}
142
caryclark1049f122015-04-20 08:31:59 -0700143template<typename TCurve, typename OppCurve>
144void SkTSpan<TCurve, OppCurve>::dump() const {
caryclark54359292015-03-26 07:52:43 -0700145 dumpID();
146 SkDebugf("=(%g,%g) [", fStartT, fEndT);
caryclark1049f122015-04-20 08:31:59 -0700147 const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded;
caryclark54359292015-03-26 07:52:43 -0700148 while (testBounded) {
caryclark1049f122015-04-20 08:31:59 -0700149 const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded;
150 const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext;
caryclark54359292015-03-26 07:52:43 -0700151 span->dumpID();
152 if (next) {
153 SkDebugf(",");
154 }
155 testBounded = next;
156 }
157 SkDebugf("]");
158}
159
caryclark1049f122015-04-20 08:31:59 -0700160template<typename TCurve, typename OppCurve>
161void SkTSpan<TCurve, OppCurve>::dumpBounded(int id) const {
162 SkDEBUGCODE(fDebugSect->dumpBounded(id));
caryclark54359292015-03-26 07:52:43 -0700163}
164
caryclark1049f122015-04-20 08:31:59 -0700165template<typename TCurve, typename OppCurve>
166void SkTSpan<TCurve, OppCurve>::dumpBounds() const {
167 dumpID();
168 SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n",
169 fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax,
170 fCollapsed ? " collapsed" : "");
171}
172
173template<typename TCurve, typename OppCurve>
174void SkTSpan<TCurve, OppCurve>::dumpCoin() const {
175 dumpID();
176 SkDebugf(" coinStart ");
177 fCoinStart.dump();
178 SkDebugf(" coinEnd ");
179 fCoinEnd.dump();
180}
181
182template<typename TCurve, typename OppCurve>
183void SkTSpan<TCurve, OppCurve>::dumpID() const {
reed0dc4dd62015-03-24 13:55:33 -0700184 if (fCoinStart.isCoincident()) {
185 SkDebugf("%c", '*');
186 }
caryclark54359292015-03-26 07:52:43 -0700187 SkDebugf("%d", debugID());
reed0dc4dd62015-03-24 13:55:33 -0700188 if (fCoinEnd.isCoincident()) {
189 SkDebugf("%c", '*');
190 }
caryclark45fa4472015-01-16 07:04:10 -0800191}