OLD | NEW |
(Empty) | |
| 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 #ifndef SkQuadSpan_DEFINE |
| 8 #define SkQuadSpan_DEFINE |
| 9 |
| 10 #include "SkChunkAlloc.h" |
| 11 #include "SkPathOpsRect.h" |
| 12 #include "SkPathOpsQuad.h" |
| 13 #include "SkTArray.h" |
| 14 |
| 15 class SkIntersections; |
| 16 |
| 17 class SkQuadCoincident { |
| 18 public: |
| 19 bool isCoincident() const { |
| 20 return fCoincident; |
| 21 } |
| 22 |
| 23 void init() { |
| 24 fCoincident = false; |
| 25 SkDEBUGCODE(fPerpPt.fX = fPerpPt.fY = SK_ScalarNaN); |
| 26 SkDEBUGCODE(fPerpT = SK_ScalarNaN); |
| 27 } |
| 28 |
| 29 void markCoincident() { |
| 30 if (!fCoincident) { |
| 31 fPerpT = -1; |
| 32 } |
| 33 fCoincident = true; |
| 34 } |
| 35 |
| 36 const SkDPoint& perpPt() const { |
| 37 return fPerpPt; |
| 38 } |
| 39 |
| 40 double perpT() const { |
| 41 return fPerpT; |
| 42 } |
| 43 |
| 44 void setPerp(const SkDQuad& quad1, double t, const SkDPoint& qPt, const SkDQ
uad& quad2); |
| 45 |
| 46 private: |
| 47 SkDPoint fPerpPt; |
| 48 double fPerpT; // perpendicular intersection on opposite quad |
| 49 bool fCoincident; |
| 50 }; |
| 51 |
| 52 class SkQuadSect; // used only by debug id |
| 53 |
| 54 class SkQuadSpan { |
| 55 public: |
| 56 void init(const SkDQuad& quad); |
| 57 void initBounds(const SkDQuad& quad); |
| 58 |
| 59 bool contains(double t) const { |
| 60 return !! const_cast<SkQuadSpan*>(this)->innerFind(t); |
| 61 } |
| 62 |
| 63 bool contains(const SkQuadSpan* span) const; |
| 64 |
| 65 SkQuadSpan* find(double t) { |
| 66 SkQuadSpan* result = innerFind(t); |
| 67 SkASSERT(result); |
| 68 return result; |
| 69 } |
| 70 |
| 71 bool intersects(const SkQuadSpan* span) const; |
| 72 |
| 73 const SkQuadSpan* next() const { |
| 74 return fNext; |
| 75 } |
| 76 |
| 77 void reset() { |
| 78 fBounded.reset(); |
| 79 } |
| 80 |
| 81 bool split(SkQuadSpan* work) { |
| 82 return splitAt(work, (work->fStartT + work->fEndT) * 0.5); |
| 83 } |
| 84 |
| 85 bool splitAt(SkQuadSpan* work, double t); |
| 86 bool tightBoundsIntersects(const SkQuadSpan* span) const; |
| 87 |
| 88 // implementation is for testing only |
| 89 void dump() const; |
| 90 |
| 91 private: |
| 92 bool hullIntersects(const SkDQuad& q2) const; |
| 93 SkQuadSpan* innerFind(double t); |
| 94 bool linearIntersects(const SkDQuad& q2) const; |
| 95 |
| 96 // implementation is for testing only |
| 97 #if DEBUG_BINARY_QUAD |
| 98 int debugID(const SkQuadSect* ) const { return fDebugID; } |
| 99 #else |
| 100 int debugID(const SkQuadSect* ) const; |
| 101 #endif |
| 102 void dump(const SkQuadSect* ) const; |
| 103 void dumpID(const SkQuadSect* ) const; |
| 104 |
| 105 #if DEBUG_BINARY_QUAD |
| 106 void validate() const; |
| 107 #endif |
| 108 |
| 109 SkDQuad fPart; |
| 110 SkQuadCoincident fCoinStart; |
| 111 SkQuadCoincident fCoinEnd; |
| 112 SkSTArray<4, SkQuadSpan*, true> fBounded; |
| 113 SkQuadSpan* fPrev; |
| 114 SkQuadSpan* fNext; |
| 115 SkDRect fBounds; |
| 116 double fStartT; |
| 117 double fEndT; |
| 118 double fBoundsMax; |
| 119 bool fCollapsed; |
| 120 bool fHasPerp; |
| 121 mutable bool fIsLinear; |
| 122 #if DEBUG_BINARY_QUAD |
| 123 int fDebugID; |
| 124 bool fDebugDeleted; |
| 125 #endif |
| 126 friend class SkQuadSect; |
| 127 }; |
| 128 |
| 129 class SkQuadSect { |
| 130 public: |
| 131 SkQuadSect(const SkDQuad& quad PATH_OPS_DEBUG_PARAMS(int id)); |
| 132 static void BinarySearch(SkQuadSect* sect1, SkQuadSect* sect2, SkIntersectio
ns* intersections); |
| 133 |
| 134 // for testing only |
| 135 void dumpQuads() const; |
| 136 private: |
| 137 SkQuadSpan* addOne(); |
| 138 bool binarySearchCoin(const SkQuadSect& , double tStart, double tStep, doubl
e* t, double* oppT); |
| 139 SkQuadSpan* boundsMax() const; |
| 140 void coincidentCheck(SkQuadSect* sect2); |
| 141 bool intersects(const SkQuadSpan* span, const SkQuadSect* opp, const SkQuadS
pan* oppSpan) const; |
| 142 void onCurveCheck(SkQuadSect* sect2, SkQuadSpan* first, SkQuadSpan* last); |
| 143 void recoverCollapsed(); |
| 144 void removeSpan(SkQuadSpan* span); |
| 145 void removeOne(const SkQuadSpan* test, SkQuadSpan* span); |
| 146 void removeSpans(SkQuadSpan* span, SkQuadSect* opp); |
| 147 void setPerp(const SkDQuad& opp, SkQuadSpan* first, SkQuadSpan* last); |
| 148 const SkQuadSpan* tail() const; |
| 149 void trim(SkQuadSpan* span, SkQuadSect* opp); |
| 150 |
| 151 // for testing only |
| 152 void dump() const; |
| 153 void dumpBoth(const SkQuadSect& opp) const; |
| 154 void dumpBoth(const SkQuadSect* opp) const; |
| 155 |
| 156 #if DEBUG_BINARY_QUAD |
| 157 int debugID() const { return fDebugID; } |
| 158 void validate() const; |
| 159 #else |
| 160 int debugID() const { return 0; } |
| 161 #endif |
| 162 const SkDQuad& fQuad; |
| 163 SkChunkAlloc fHeap; |
| 164 SkQuadSpan* fHead; |
| 165 SkQuadSpan* fDeleted; |
| 166 int fActiveCount; |
| 167 #if DEBUG_BINARY_QUAD |
| 168 int fDebugID; |
| 169 int fDebugCount; |
| 170 int fDebugAllocatedCount; |
| 171 #endif |
| 172 friend class SkQuadSpan; // only used by debug id |
| 173 }; |
| 174 |
| 175 #endif |
OLD | NEW |