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