PathOpsTSectDebug.h revision 54359294a7c9dc54802d512a5d891a35c1663392
1/*
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
10template<typename TCurve>
11const SkTSpan<TCurve>* SkTSect<TCurve>::debugSpan(int id) const {
12    const SkTSpan<TCurve>* test = fHead;
13    do {
14        if (test->debugID() == id) {
15            return test;
16        }
17    } while ((test = test->next()));
18#ifndef SK_RELEASE
19    test = fOppSect->fHead;
20    do {
21        if (test->debugID() == id) {
22            return test;
23        }
24    } while ((test = test->next()));
25#endif
26    return NULL;
27}
28
29template<typename TCurve>
30const SkTSpan<TCurve>* SkTSect<TCurve>::debugT(double t) const {
31    const SkTSpan<TCurve>* test = fHead;
32    const SkTSpan<TCurve>* closest = NULL;
33    double bestDist = DBL_MAX;
34    do {
35        if (between(test->fStartT, t, test->fEndT)) {
36            return test;
37        }
38        double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
39        if (bestDist > testDist) {
40            bestDist = testDist;
41            closest = test;
42        }
43    } while ((test = test->next()));
44    SkASSERT(closest);
45    return closest;
46}
47
48template<typename TCurve>
49void SkTSect<TCurve>::dump() const {
50    dumpCommon(fHead);
51}
52
53extern int gDumpTSectNum;
54
55template<typename TCurve>
56void SkTSect<TCurve>::dumpBoth(SkTSect* opp) const {
57#if DEBUG_T_SECT_DUMP <= 2
58#if DEBUG_T_SECT_DUMP == 2
59    SkDebugf("%d ", ++gDumpTSectNum);
60#endif
61    this->dump();
62    SkDebugf(" ");
63    opp->dump();
64    SkDebugf("\n");
65#elif DEBUG_T_SECT_DUMP == 3
66    SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
67    if (this->fHead) {
68        this->dumpCurves();
69    }
70    if (opp->fHead) {
71        PATH_OPS_DEBUG_CODE(opp->dumpCurves());
72    }
73    SkDebugf("</div>\n\n");
74#endif
75}
76
77template<typename TCurve>
78void SkTSect<TCurve>::dumpBounds(int id) const {
79    const SkTSpan<TCurve>* bounded = debugSpan(id);
80    if (!bounded) {
81        SkDebugf("no span matches %d\n", id);
82        return;
83    }
84    const SkTSpan<TCurve>* test = bounded->debugOpp()->fHead;
85    do {
86        if (test->findOppSpan(bounded)) {
87            test->dump();
88        }
89    } while ((test = test->next()));
90}
91
92template<typename TCurve>
93void SkTSect<TCurve>::dumpCoin() const {
94    dumpCommon(fCoincident);
95}
96
97template<typename TCurve>
98void SkTSect<TCurve>::dumpCoinCurves() const {
99    dumpCommonCurves(fCoincident);
100}
101
102template<typename TCurve>
103void SkTSect<TCurve>::dumpCommon(const SkTSpan<TCurve>* test) const {
104    SkDebugf("id=%d", debugID());
105    if (!test) {
106        SkDebugf(" (empty)");
107        return;
108    }
109    do {
110        SkDebugf(" ");
111        test->dump();
112    } while ((test = test->next()));
113}
114
115template<typename TCurve>
116void SkTSect<TCurve>::dumpCommonCurves(const SkTSpan<TCurve>* test) const {
117    do {
118        test->fPart.dumpID(test->debugID());
119    } while ((test = test->next()));
120}
121
122template<typename TCurve>
123void SkTSect<TCurve>::dumpCurves() const {
124    dumpCommonCurves(fHead);
125}
126
127template<typename TCurve>
128const SkTSpan<TCurve>* SkTSpan<TCurve>::debugSpan(int id) const {
129    return PATH_OPS_DEBUG_RELEASE(fDebugSect->debugSpan(id), NULL);
130}
131
132template<typename TCurve>
133const SkTSpan<TCurve>* SkTSpan<TCurve>::debugT(double t) const {
134    return PATH_OPS_DEBUG_RELEASE(fDebugSect->debugT(t), NULL);
135}
136
137template<typename TCurve>
138void SkTSpan<TCurve>::dump() const {
139    dumpID();
140    SkDebugf("=(%g,%g) [", fStartT, fEndT);
141    const SkTSpanBounded<TCurve>* testBounded = fBounded;
142    while (testBounded) {
143        const SkTSpan* span = testBounded->fBounded;
144        const SkTSpanBounded<TCurve>* next = testBounded->fNext;
145        span->dumpID();
146        if (next) {
147            SkDebugf(",");
148        }
149        testBounded = next;
150    }
151    SkDebugf("]");
152}
153
154template<typename TCurve>
155void SkTSpan<TCurve>::dumpBounds(int id) const {
156    PATH_OPS_DEBUG_CODE(fDebugSect->dumpBounds(id));
157}
158
159template<typename TCurve>
160void SkTSpan<TCurve>::dumpID() const {
161    if (fCoinStart.isCoincident()) {
162        SkDebugf("%c", '*');
163    }
164    SkDebugf("%d", debugID());
165    if (fCoinEnd.isCoincident()) {
166        SkDebugf("%c", '*');
167    }
168}
169