| 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 { | 11 void SkTSect<TCurve>::dump() const { |
| 12 SkDebugf("id=%d", debugID()); |
| 12 const SkTSpan<TCurve>* test = fHead; | 13 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> | |
| 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 { | |
| 104 SkDebugf("id=%d", debugID()); | |
| 105 if (!test) { | 14 if (!test) { |
| 106 SkDebugf(" (empty)"); | 15 SkDebugf(" (empty)"); |
| 107 return; | 16 return; |
| 108 } | 17 } |
| 109 do { | 18 do { |
| 110 SkDebugf(" "); | 19 SkDebugf(" "); |
| 111 test->dump(); | 20 test->dump(this); |
| 112 } while ((test = test->next())); | 21 } while ((test = test->next())); |
| 113 } | 22 } |
| 114 | 23 |
| 115 template<typename TCurve> | 24 template<typename TCurve> |
| 116 void SkTSect<TCurve>::dumpCommonCurves(const SkTSpan<TCurve>* test) const { | 25 void SkTSect<TCurve>::dumpBoth(const SkTSect& opp) const { |
| 117 do { | 26 dump(); |
| 118 test->fPart.dumpID(test->debugID()); | 27 SkDebugf(" "); |
| 119 } while ((test = test->next())); | 28 opp.dump(); |
| 29 SkDebugf("\n"); |
| 30 } |
| 31 |
| 32 template<typename TCurve> |
| 33 void SkTSect<TCurve>::dumpBoth(const SkTSect* opp) const { |
| 34 dumpBoth(*opp); |
| 120 } | 35 } |
| 121 | 36 |
| 122 template<typename TCurve> | 37 template<typename TCurve> |
| 123 void SkTSect<TCurve>::dumpCurves() const { | 38 void SkTSect<TCurve>::dumpCurves() const { |
| 124 dumpCommonCurves(fHead); | 39 const SkTSpan<TCurve>* test = 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 } |
| 125 } | 70 } |
| 126 | 71 |
| 127 template<typename TCurve> | 72 template<typename TCurve> |
| 128 const SkTSpan<TCurve>* SkTSpan<TCurve>::debugSpan(int id) const { | 73 void SkTSpan<TCurve>::dump(const SkTSect<TCurve>* sect) const { |
| 129 return PATH_OPS_DEBUG_RELEASE(fDebugSect->debugSpan(id), NULL); | 74 dumpID(sect); |
| 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(); | |
| 140 SkDebugf("=(%g,%g) [", fStartT, fEndT); | 75 SkDebugf("=(%g,%g) [", fStartT, fEndT); |
| 141 for (int index = 0; index < fBounded.count(); ++index) { | 76 for (int index = 0; index < fBounded.count(); ++index) { |
| 142 SkTSpan* span = fBounded[index]; | 77 SkTSpan* span = fBounded[index]; |
| 143 span->dumpID(); | 78 span->dumpID(sect); |
| 144 if (index < fBounded.count() - 1) { | 79 if (index < fBounded.count() - 1) { |
| 145 SkDebugf(","); | 80 SkDebugf(","); |
| 146 } | 81 } |
| 147 } | 82 } |
| 148 SkDebugf("]"); | 83 SkDebugf("]"); |
| 149 } | 84 } |
| 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 |