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