aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PathOpsTSectDebug.h
blob: b4715e63e07f07087f6988877d5956e22c2e2eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkPathOpsTSect.h"

template<typename TCurve>
const SkTSpan<TCurve>* SkTSect<TCurve>::debugSpan(int id) const {
    const SkTSpan<TCurve>* test = fHead;
    do {
        if (test->debugID() == id) {
            return test;
        }
    } while ((test = test->next()));
#ifndef SK_RELEASE
    test = fOppSect->fHead;
    do {
        if (test->debugID() == id) {
            return test;
        }
    } while ((test = test->next()));
#endif
    return NULL;
}

template<typename TCurve>
const SkTSpan<TCurve>* SkTSect<TCurve>::debugT(double t) const {
    const SkTSpan<TCurve>* test = fHead;
    const SkTSpan<TCurve>* closest = NULL;
    double bestDist = DBL_MAX;
    do {
        if (between(test->fStartT, t, test->fEndT)) {
            return test;
        }
        double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t));
        if (bestDist > testDist) {
            bestDist = testDist;
            closest = test;
        }
    } while ((test = test->next()));
    SkASSERT(closest);
    return closest;
}

template<typename TCurve>
void SkTSect<TCurve>::dump() const {
    dumpCommon(fHead);
}

extern int gDumpTSectNum;

template<typename TCurve>
void SkTSect<TCurve>::dumpBoth(SkTSect* opp) const {
#if DEBUG_T_SECT_DUMP <= 2
#if DEBUG_T_SECT_DUMP == 2
    SkDebugf("%d ", ++gDumpTSectNum);
#endif
    this->dump();
    SkDebugf(" ");
    opp->dump();
    SkDebugf("\n");
#elif DEBUG_T_SECT_DUMP == 3
    SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum);
    if (this->fHead) {
        this->dumpCurves();
    }
    if (opp->fHead) {
        PATH_OPS_DEBUG_CODE(opp->dumpCurves());
    }
    SkDebugf("</div>\n\n");
#endif
}

template<typename TCurve>
void SkTSect<TCurve>::dumpBounds(int id) const {
    const SkTSpan<TCurve>* bounded = debugSpan(id);
    if (!bounded) {
        SkDebugf("no span matches %d\n", id);
        return;
    }
    const SkTSpan<TCurve>* test = bounded->debugOpp()->fHead;
    do {
        if (test->findOppSpan(bounded)) {
            test->dump();
        }
    } while ((test = test->next()));
}

template<typename TCurve>
void SkTSect<TCurve>::dumpCoin() const {
    dumpCommon(fCoincident);
}

template<typename TCurve>
void SkTSect<TCurve>::dumpCoinCurves() const {
    dumpCommonCurves(fCoincident);
}

template<typename TCurve>
void SkTSect<TCurve>::dumpCommon(const SkTSpan<TCurve>* test) const {
    SkDebugf("id=%d", debugID());
    if (!test) {
        SkDebugf(" (empty)");
        return;
    }
    do {
        SkDebugf(" ");
        test->dump();
    } while ((test = test->next()));
}

template<typename TCurve>
void SkTSect<TCurve>::dumpCommonCurves(const SkTSpan<TCurve>* test) const {
    do {
        test->fPart.dumpID(test->debugID());
    } while ((test = test->next()));
}

template<typename TCurve>
void SkTSect<TCurve>::dumpCurves() const {
    dumpCommonCurves(fHead);
}

template<typename TCurve>
const SkTSpan<TCurve>* SkTSpan<TCurve>::debugSpan(int id) const {
    return PATH_OPS_DEBUG_RELEASE(fDebugSect->debugSpan(id), NULL);
}

template<typename TCurve>
const SkTSpan<TCurve>* SkTSpan<TCurve>::debugT(double t) const {
    return PATH_OPS_DEBUG_RELEASE(fDebugSect->debugT(t), NULL);
}

template<typename TCurve>
void SkTSpan<TCurve>::dump() const {
    dumpID();
    SkDebugf("=(%g,%g) [", fStartT, fEndT);
    for (int index = 0; index < fBounded.count(); ++index) {
        SkTSpan* span = fBounded[index];
        span->dumpID();
        if (index < fBounded.count() - 1) {
            SkDebugf(",");
        }
    }
    SkDebugf("]");
}

template<typename TCurve>
void SkTSpan<TCurve>::dumpBounds(int id) const {
    PATH_OPS_DEBUG_CODE(fDebugSect->dumpBounds(id));
}

template<typename TCurve>
void SkTSpan<TCurve>::dumpID() const {
    if (fCoinStart.isCoincident()) {
        SkDebugf("%c", '*');
    }
    SkDebugf("%d", debugID());
    if (fCoinEnd.isCoincident()) {
        SkDebugf("%c", '*');
    }
}