caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 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 | */ |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 7 | #ifndef PathOpsTSectDebug_DEFINED |
| 8 | #define PathOpsTSectDebug_DEFINED |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 9 | |
| 10 | #include "SkPathOpsTSect.h" |
| 11 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 12 | template<typename TCurve, typename OppCurve> |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 13 | char SkTCoincident<TCurve, OppCurve>::dumpIsCoincidentStr() const { |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 14 | if (!!fMatch != fMatch) { |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 15 | return '?'; |
| 16 | } |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 17 | return fMatch ? '*' : 0; |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | template<typename TCurve, typename OppCurve> |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 21 | void SkTCoincident<TCurve, OppCurve>::dump() const { |
| 22 | SkDebugf("t=%1.9g pt=(%1.9g,%1.9g)%s\n", fPerpT, fPerpPt.fX, fPerpPt.fY, |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 23 | fMatch ? " match" : ""); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | template<typename TCurve, typename OppCurve> |
| 27 | const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugSpan(int id) const { |
| 28 | const SkTSpan<TCurve, OppCurve>* test = fHead; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 29 | do { |
| 30 | if (test->debugID() == id) { |
| 31 | return test; |
| 32 | } |
| 33 | } while ((test = test->next())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 34 | return nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 35 | } |
| 36 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 37 | template<typename TCurve, typename OppCurve> |
| 38 | const SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::debugT(double t) const { |
| 39 | const SkTSpan<TCurve, OppCurve>* test = fHead; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 40 | const SkTSpan<TCurve, OppCurve>* closest = nullptr; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 41 | double bestDist = DBL_MAX; |
| 42 | do { |
| 43 | if (between(test->fStartT, t, test->fEndT)) { |
| 44 | return test; |
| 45 | } |
| 46 | double testDist = SkTMin(fabs(test->fStartT - t), fabs(test->fEndT - t)); |
| 47 | if (bestDist > testDist) { |
| 48 | bestDist = testDist; |
| 49 | closest = test; |
| 50 | } |
| 51 | } while ((test = test->next())); |
| 52 | SkASSERT(closest); |
| 53 | return closest; |
| 54 | } |
| 55 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 56 | template<typename TCurve, typename OppCurve> |
| 57 | void SkTSect<TCurve, OppCurve>::dump() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 58 | dumpCommon(fHead); |
| 59 | } |
| 60 | |
| 61 | extern int gDumpTSectNum; |
| 62 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 63 | template<typename TCurve, typename OppCurve> |
| 64 | void SkTSect<TCurve, OppCurve>::dumpBoth(SkTSect<OppCurve, TCurve>* opp) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 65 | #if DEBUG_T_SECT_DUMP <= 2 |
| 66 | #if DEBUG_T_SECT_DUMP == 2 |
| 67 | SkDebugf("%d ", ++gDumpTSectNum); |
| 68 | #endif |
| 69 | this->dump(); |
| 70 | SkDebugf(" "); |
| 71 | opp->dump(); |
| 72 | SkDebugf("\n"); |
| 73 | #elif DEBUG_T_SECT_DUMP == 3 |
| 74 | SkDebugf("<div id=\"sect%d\">\n", ++gDumpTSectNum); |
| 75 | if (this->fHead) { |
| 76 | this->dumpCurves(); |
| 77 | } |
| 78 | if (opp->fHead) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 79 | opp->dumpCurves(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 80 | } |
| 81 | SkDebugf("</div>\n\n"); |
| 82 | #endif |
| 83 | } |
| 84 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 85 | template<typename TCurve, typename OppCurve> |
| 86 | void SkTSect<TCurve, OppCurve>::dumpBounded(int id) const { |
| 87 | const SkTSpan<TCurve, OppCurve>* bounded = debugSpan(id); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 88 | if (!bounded) { |
| 89 | SkDebugf("no span matches %d\n", id); |
| 90 | return; |
| 91 | } |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 92 | const SkTSpan<OppCurve, TCurve>* test = bounded->debugOpp()->fHead; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 93 | do { |
| 94 | if (test->findOppSpan(bounded)) { |
| 95 | test->dump(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 96 | SkDebugf(" "); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 97 | } |
| 98 | } while ((test = test->next())); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 99 | SkDebugf("\n"); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 100 | } |
| 101 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 102 | template<typename TCurve, typename OppCurve> |
| 103 | void SkTSect<TCurve, OppCurve>::dumpBounds() const { |
| 104 | const SkTSpan<TCurve, OppCurve>* test = fHead; |
| 105 | do { |
| 106 | test->dumpBounds(); |
| 107 | } while ((test = test->next())); |
| 108 | } |
| 109 | |
| 110 | template<typename TCurve, typename OppCurve> |
| 111 | void SkTSect<TCurve, OppCurve>::dumpCoin() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 112 | dumpCommon(fCoincident); |
| 113 | } |
| 114 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 115 | template<typename TCurve, typename OppCurve> |
| 116 | void SkTSect<TCurve, OppCurve>::dumpCoinCurves() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 117 | dumpCommonCurves(fCoincident); |
| 118 | } |
| 119 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 120 | template<typename TCurve, typename OppCurve> |
| 121 | void SkTSect<TCurve, OppCurve>::dumpCommon(const SkTSpan<TCurve, OppCurve>* test) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 122 | SkDebugf("id=%d", debugID()); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 123 | if (!test) { |
| 124 | SkDebugf(" (empty)"); |
| 125 | return; |
| 126 | } |
| 127 | do { |
| 128 | SkDebugf(" "); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 129 | test->dump(); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 130 | } while ((test = test->next())); |
| 131 | } |
| 132 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 133 | template<typename TCurve, typename OppCurve> |
| 134 | void SkTSect<TCurve, OppCurve>::dumpCommonCurves(const SkTSpan<TCurve, OppCurve>* test) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 135 | do { |
| 136 | test->fPart.dumpID(test->debugID()); |
| 137 | } while ((test = test->next())); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 138 | } |
| 139 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 140 | template<typename TCurve, typename OppCurve> |
| 141 | void SkTSect<TCurve, OppCurve>::dumpCurves() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 142 | dumpCommonCurves(fHead); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 143 | } |
| 144 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 145 | template<typename TCurve, typename OppCurve> |
| 146 | const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugSpan(int id) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 147 | return SkDEBUGRELEASE(fDebugSect->debugSpan(id), nullptr); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 148 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 149 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 150 | template<typename TCurve, typename OppCurve> |
| 151 | const SkTSpan<TCurve, OppCurve>* SkTSpan<TCurve, OppCurve>::debugT(double t) const { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 152 | return SkDEBUGRELEASE(fDebugSect->debugT(t), nullptr); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 153 | } |
| 154 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 155 | template<typename TCurve, typename OppCurve> |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 156 | void SkTSpan<TCurve, OppCurve>::dumpAll() const { |
| 157 | dumpID(); |
| 158 | SkDebugf("=(%g,%g) [", fStartT, fEndT); |
| 159 | const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded; |
| 160 | while (testBounded) { |
| 161 | const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded; |
| 162 | const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext; |
| 163 | span->dumpID(); |
| 164 | SkDebugf("=(%g,%g)", span->fStartT, span->fEndT); |
| 165 | if (next) { |
| 166 | SkDebugf(" "); |
| 167 | } |
| 168 | testBounded = next; |
| 169 | } |
| 170 | SkDebugf("]\n"); |
| 171 | } |
| 172 | |
| 173 | template<typename TCurve, typename OppCurve> |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 174 | void SkTSpan<TCurve, OppCurve>::dump() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 175 | dumpID(); |
| 176 | SkDebugf("=(%g,%g) [", fStartT, fEndT); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 177 | const SkTSpanBounded<OppCurve, TCurve>* testBounded = fBounded; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 178 | while (testBounded) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 179 | const SkTSpan<OppCurve, TCurve>* span = testBounded->fBounded; |
| 180 | const SkTSpanBounded<OppCurve, TCurve>* next = testBounded->fNext; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 181 | span->dumpID(); |
| 182 | if (next) { |
| 183 | SkDebugf(","); |
| 184 | } |
| 185 | testBounded = next; |
| 186 | } |
| 187 | SkDebugf("]"); |
| 188 | } |
| 189 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 190 | template<typename TCurve, typename OppCurve> |
| 191 | void SkTSpan<TCurve, OppCurve>::dumpBounded(int id) const { |
| 192 | SkDEBUGCODE(fDebugSect->dumpBounded(id)); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 193 | } |
| 194 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 195 | template<typename TCurve, typename OppCurve> |
| 196 | void SkTSpan<TCurve, OppCurve>::dumpBounds() const { |
| 197 | dumpID(); |
| 198 | SkDebugf(" bounds=(%1.9g,%1.9g, %1.9g,%1.9g) boundsMax=%1.9g%s\n", |
| 199 | fBounds.fLeft, fBounds.fTop, fBounds.fRight, fBounds.fBottom, fBoundsMax, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 200 | fCollapsed ? " collapsed" : ""); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | template<typename TCurve, typename OppCurve> |
| 204 | void SkTSpan<TCurve, OppCurve>::dumpCoin() const { |
| 205 | dumpID(); |
| 206 | SkDebugf(" coinStart "); |
| 207 | fCoinStart.dump(); |
| 208 | SkDebugf(" coinEnd "); |
| 209 | fCoinEnd.dump(); |
| 210 | } |
| 211 | |
| 212 | template<typename TCurve, typename OppCurve> |
| 213 | void SkTSpan<TCurve, OppCurve>::dumpID() const { |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 214 | char cS = fCoinStart.dumpIsCoincidentStr(); |
| 215 | if (cS) { |
| 216 | SkDebugf("%c", cS); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 217 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 218 | SkDebugf("%d", debugID()); |
caryclark | ed0935a | 2015-10-22 07:23:52 -0700 | [diff] [blame] | 219 | char cE = fCoinEnd.dumpIsCoincidentStr(); |
| 220 | if (cE) { |
| 221 | SkDebugf("%c", cE); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 222 | } |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 223 | } |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 224 | #endif // PathOpsTSectDebug_DEFINED |