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