caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 SkOpSegment_DEFINE |
| 8 | #define SkOpSegment_DEFINE |
| 9 | |
| 10 | #include "SkOpAngle.h" |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 11 | #include "SkOpSpan.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 12 | #include "SkOpTAllocator.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 13 | #include "SkPathOpsBounds.h" |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 14 | #include "SkPathOpsCubic.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 15 | #include "SkPathOpsCurve.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 16 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 17 | struct SkDCurve; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 18 | class SkOpCoincidence; |
| 19 | class SkOpContour; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 20 | enum class SkOpRayDir; |
| 21 | struct SkOpRayHit; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | class SkPathWriter; |
| 23 | |
| 24 | class SkOpSegment { |
| 25 | public: |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 26 | enum AllowAlias { |
| 27 | kAllowAlias, |
| 28 | kNoAlias |
| 29 | }; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | |
| 31 | bool operator<(const SkOpSegment& rh) const { |
| 32 | return fBounds.fTop < rh.fBounds.fTop; |
| 33 | } |
| 34 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 35 | SkOpAngle* activeAngle(SkOpSpanBase* start, SkOpSpanBase** startPtr, SkOpSpanBase** endPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 36 | bool* done); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 37 | SkOpAngle* activeAngleInner(SkOpSpanBase* start, SkOpSpanBase** startPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 38 | SkOpSpanBase** endPtr, bool* done); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 39 | SkOpAngle* activeAngleOther(SkOpSpanBase* start, SkOpSpanBase** startPtr, |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 40 | SkOpSpanBase** endPtr, bool* done); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 41 | bool activeOp(SkOpSpanBase* start, SkOpSpanBase* end, int xorMiMask, int xorSuMask, |
| 42 | SkPathOp op); |
| 43 | bool activeOp(int xorMiMask, int xorSuMask, SkOpSpanBase* start, SkOpSpanBase* end, SkPathOp op, |
| 44 | int* sumMiWinding, int* sumSuWinding); |
| 45 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 46 | bool activeWinding(SkOpSpanBase* start, SkOpSpanBase* end); |
| 47 | bool activeWinding(SkOpSpanBase* start, SkOpSpanBase* end, int* sumWinding); |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 48 | void addAlignIntersection(SkOpPtT& endPtT, SkPoint& oldPt, |
| 49 | SkOpContourHead* contourList, SkChunkAlloc* allocator); |
| 50 | |
| 51 | void addAlignIntersections(SkOpContourHead* contourList, SkChunkAlloc* allocator) { |
| 52 | this->addAlignIntersection(*fHead.ptT(), fOriginal[0], contourList, allocator); |
| 53 | this->addAlignIntersection(*fTail.ptT(), fOriginal[1], contourList, allocator); |
| 54 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 55 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 56 | SkOpSegment* addConic(SkPoint pts[3], SkScalar weight, SkOpContour* parent) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 57 | init(pts, weight, parent, SkPath::kConic_Verb); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 58 | SkDCurve curve; |
| 59 | curve.fConic.set(pts, weight); |
| 60 | curve.setConicBounds(pts, weight, 0, 1, &fBounds); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 61 | return this; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 62 | } |
| 63 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 64 | SkOpSegment* addCubic(SkPoint pts[4], SkOpContour* parent) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 65 | init(pts, 1, parent, SkPath::kCubic_Verb); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 66 | SkDCurve curve; |
| 67 | curve.fCubic.set(pts); |
| 68 | curve.setCubicBounds(pts, 1, 0, 1, &fBounds); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 69 | return this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 70 | } |
| 71 | |
caryclark | ef784fb | 2015-10-30 12:03:06 -0700 | [diff] [blame] | 72 | bool addCurveTo(const SkOpSpanBase* start, const SkOpSpanBase* end, SkPathWriter* path) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 73 | |
| 74 | SkOpAngle* addEndSpan(SkChunkAlloc* allocator) { |
| 75 | SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(allocator); |
| 76 | angle->set(&fTail, fTail.prev()); |
| 77 | fTail.setFromAngle(angle); |
| 78 | return angle; |
| 79 | } |
| 80 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 81 | SkOpSegment* addLine(SkPoint pts[2], SkOpContour* parent) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 82 | init(pts, 1, parent, SkPath::kLine_Verb); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 83 | fBounds.set(pts, 2); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 84 | return this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | SkOpPtT* addMissing(double t, SkOpSegment* opp, SkChunkAlloc* ); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 88 | |
| 89 | SkOpAngle* addStartSpan(SkChunkAlloc* allocator) { |
| 90 | SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(allocator); |
| 91 | angle->set(&fHead, fHead.next()); |
| 92 | fHead.setToAngle(angle); |
| 93 | return angle; |
| 94 | } |
| 95 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 96 | SkOpSegment* addQuad(SkPoint pts[3], SkOpContour* parent) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 97 | init(pts, 1, parent, SkPath::kQuad_Verb); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 98 | SkDCurve curve; |
| 99 | curve.fQuad.set(pts); |
| 100 | curve.setQuadBounds(pts, 1, 0, 1, &fBounds); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 101 | return this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | SkOpPtT* addT(double t, AllowAlias , SkChunkAlloc* ); |
| 105 | |
| 106 | void align(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 107 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 108 | const SkPathOpsBounds& bounds() const { |
| 109 | return fBounds; |
| 110 | } |
| 111 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 112 | void bumpCount() { |
| 113 | ++fCount; |
| 114 | } |
| 115 | |
| 116 | void calcAngles(SkChunkAlloc*); |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 117 | bool collapsed() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 118 | static void ComputeOneSum(const SkOpAngle* baseAngle, SkOpAngle* nextAngle, |
| 119 | SkOpAngle::IncludeType ); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 120 | static void ComputeOneSumReverse(SkOpAngle* baseAngle, SkOpAngle* nextAngle, |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 121 | SkOpAngle::IncludeType ); |
| 122 | int computeSum(SkOpSpanBase* start, SkOpSpanBase* end, SkOpAngle::IncludeType includeType); |
| 123 | |
| 124 | SkOpContour* contour() const { |
| 125 | return fContour; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 126 | } |
| 127 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 128 | int count() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 129 | return fCount; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 130 | } |
| 131 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 132 | void debugAddAngle(double startT, double endT, SkChunkAlloc*); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 133 | void debugAddAlignIntersection(const char* id, SkPathOpsDebug::GlitchLog* glitches, |
| 134 | const SkOpPtT& endPtT, const SkPoint& oldPt, |
| 135 | const SkOpContourHead* ) const; |
| 136 | |
| 137 | void debugAddAlignIntersections(const char* id, SkPathOpsDebug::GlitchLog* glitches, |
| 138 | SkOpContourHead* contourList) const { |
| 139 | this->debugAddAlignIntersection(id, glitches, *fHead.ptT(), fOriginal[0], contourList); |
| 140 | this->debugAddAlignIntersection(id, glitches, *fTail.ptT(), fOriginal[1], contourList); |
| 141 | } |
| 142 | |
| 143 | bool debugAddMissing(double t, const SkOpSegment* opp) const; |
| 144 | void debugAlign(const char* id, SkPathOpsDebug::GlitchLog* glitches) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 145 | const SkOpAngle* debugAngle(int id) const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 146 | #if DEBUG_ANGLE |
| 147 | void debugCheckAngleCoin() const; |
| 148 | #endif |
| 149 | void debugCheckHealth(const char* id, SkPathOpsDebug::GlitchLog* ) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 150 | SkOpContour* debugContour(int id); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 151 | void debugFindCollapsed(const char* id, SkPathOpsDebug::GlitchLog* glitches) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 152 | |
| 153 | int debugID() const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 154 | return SkDEBUGRELEASE(fID, -1); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 155 | } |
| 156 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 157 | SkOpAngle* debugLastAngle(); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 158 | void debugMissingCoincidence(const char* id, SkPathOpsDebug::GlitchLog* glitches, |
| 159 | const SkOpCoincidence* coincidences) const; |
| 160 | void debugMoveMultiples(const char* id, SkPathOpsDebug::GlitchLog* glitches) const; |
| 161 | void debugMoveNearby(const char* id, SkPathOpsDebug::GlitchLog* glitches) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 162 | const SkOpPtT* debugPtT(int id) const; |
| 163 | void debugReset(); |
| 164 | const SkOpSegment* debugSegment(int id) const; |
| 165 | |
| 166 | #if DEBUG_ACTIVE_SPANS |
| 167 | void debugShowActiveSpans() const; |
| 168 | #endif |
| 169 | #if DEBUG_MARK_DONE |
| 170 | void debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding); |
| 171 | void debugShowNewWinding(const char* fun, const SkOpSpan* span, int winding, int oppWinding); |
| 172 | #endif |
| 173 | |
| 174 | const SkOpSpanBase* debugSpan(int id) const; |
| 175 | void debugValidate() const; |
| 176 | void detach(const SkOpSpan* ); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 177 | double distSq(double t, const SkOpAngle* opp) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 178 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 179 | bool done() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 180 | SkASSERT(fDoneCount <= fCount); |
| 181 | return fDoneCount == fCount; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | bool done(const SkOpAngle* angle) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 185 | return angle->start()->starter(angle->end())->done(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 186 | } |
| 187 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 188 | SkDPoint dPtAtT(double mid) const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 189 | return (*CurveDPointAtT[fVerb])(fPts, fWeight, mid); |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 190 | } |
| 191 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 192 | SkDVector dSlopeAtT(double mid) const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 193 | return (*CurveDSlopeAtT[fVerb])(fPts, fWeight, mid); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 194 | } |
| 195 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 196 | void dump() const; |
| 197 | void dumpAll() const; |
| 198 | void dumpAngles() const; |
| 199 | void dumpCoin() const; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 200 | void dumpPts(const char* prefix = "seg") const; |
| 201 | void dumpPtsInner(const char* prefix = "seg") const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 202 | |
caryclark | d434972 | 2015-07-23 12:40:22 -0700 | [diff] [blame] | 203 | void findCollapsed(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 204 | SkOpSegment* findNextOp(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** nextStart, |
| 205 | SkOpSpanBase** nextEnd, bool* unsortable, SkPathOp op, |
| 206 | int xorMiMask, int xorSuMask); |
| 207 | SkOpSegment* findNextWinding(SkTDArray<SkOpSpanBase*>* chase, SkOpSpanBase** nextStart, |
| 208 | SkOpSpanBase** nextEnd, bool* unsortable); |
| 209 | SkOpSegment* findNextXor(SkOpSpanBase** nextStart, SkOpSpanBase** nextEnd, bool* unsortable); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 210 | SkOpSpan* findSortableTop(SkOpContour* ); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 211 | SkOpGlobalState* globalState() const; |
| 212 | |
| 213 | const SkOpSpan* head() const { |
| 214 | return &fHead; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 215 | } |
| 216 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 217 | SkOpSpan* head() { |
| 218 | return &fHead; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 219 | } |
| 220 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 221 | void init(SkPoint pts[], SkScalar weight, SkOpContour* parent, SkPath::Verb verb); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 222 | |
| 223 | SkOpSpan* insert(SkOpSpan* prev, SkChunkAlloc* allocator) { |
| 224 | SkOpSpan* result = SkOpTAllocator<SkOpSpan>::Allocate(allocator); |
| 225 | SkOpSpanBase* next = prev->next(); |
| 226 | result->setPrev(prev); |
| 227 | prev->setNext(result); |
| 228 | SkDEBUGCODE(result->ptT()->fT = 0); |
| 229 | result->setNext(next); |
| 230 | if (next) { |
| 231 | next->setPrev(result); |
| 232 | } |
| 233 | return result; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 234 | } |
| 235 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 236 | bool isClose(double t, const SkOpSegment* opp) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 237 | |
| 238 | bool isHorizontal() const { |
| 239 | return fBounds.fTop == fBounds.fBottom; |
| 240 | } |
| 241 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 242 | SkOpSegment* isSimple(SkOpSpanBase** end, int* step) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 243 | return nextChase(end, step, nullptr, nullptr); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 244 | } |
| 245 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 246 | bool isVertical() const { |
| 247 | return fBounds.fLeft == fBounds.fRight; |
| 248 | } |
| 249 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 250 | bool isVertical(SkOpSpanBase* start, SkOpSpanBase* end) const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 251 | return (*CurveIsVertical[fVerb])(fPts, fWeight, start->t(), end->t()); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 252 | } |
| 253 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 254 | bool isXor() const; |
| 255 | |
| 256 | const SkPoint& lastPt() const { |
| 257 | return fPts[SkPathOpsVerbToPoints(fVerb)]; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 258 | } |
| 259 | |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 260 | void markAllDone(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 261 | SkOpSpanBase* markAndChaseDone(SkOpSpanBase* start, SkOpSpanBase* end); |
| 262 | bool markAndChaseWinding(SkOpSpanBase* start, SkOpSpanBase* end, int winding, |
| 263 | SkOpSpanBase** lastPtr); |
| 264 | bool markAndChaseWinding(SkOpSpanBase* start, SkOpSpanBase* end, int winding, |
| 265 | int oppWinding, SkOpSpanBase** lastPtr); |
| 266 | SkOpSpanBase* markAngle(int maxWinding, int sumWinding, const SkOpAngle* angle); |
| 267 | SkOpSpanBase* markAngle(int maxWinding, int sumWinding, int oppMaxWinding, int oppSumWinding, |
| 268 | const SkOpAngle* angle); |
| 269 | void markDone(SkOpSpan* ); |
| 270 | bool markWinding(SkOpSpan* , int winding); |
| 271 | bool markWinding(SkOpSpan* , int winding, int oppWinding); |
| 272 | bool match(const SkOpPtT* span, const SkOpSegment* parent, double t, const SkPoint& pt) const; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 273 | bool missingCoincidence(SkOpCoincidence* coincidences, SkChunkAlloc* allocator); |
caryclark | d78c088 | 2016-02-24 09:03:07 -0800 | [diff] [blame] | 274 | bool moveMultiples(); |
caryclark | 08bc848 | 2015-04-24 09:08:57 -0700 | [diff] [blame] | 275 | void moveNearby(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 276 | |
| 277 | SkOpSegment* next() const { |
| 278 | return fNext; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 279 | } |
| 280 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 281 | SkOpSegment* nextChase(SkOpSpanBase** , int* step, SkOpSpan** , SkOpSpanBase** last) const; |
| 282 | bool operand() const; |
| 283 | |
| 284 | static int OppSign(const SkOpSpanBase* start, const SkOpSpanBase* end) { |
| 285 | int result = start->t() < end->t() ? -start->upCast()->oppValue() |
| 286 | : end->upCast()->oppValue(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 287 | return result; |
| 288 | } |
| 289 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 290 | bool oppXor() const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 291 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 292 | const SkOpSegment* prev() const { |
| 293 | return fPrev; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 294 | } |
| 295 | |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 296 | SkPoint ptAtT(double mid) const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 297 | return (*CurvePointAtT[fVerb])(fPts, fWeight, mid); |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 298 | } |
| 299 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 300 | const SkPoint* pts() const { |
| 301 | return fPts; |
| 302 | } |
| 303 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 304 | bool ptsDisjoint(const SkOpPtT& span, const SkOpPtT& test) const { |
| 305 | return ptsDisjoint(span.fT, span.fPt, test.fT, test.fPt); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 306 | } |
| 307 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 308 | bool ptsDisjoint(const SkOpPtT& span, double t, const SkPoint& pt) const { |
| 309 | return ptsDisjoint(span.fT, span.fPt, t, pt); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 310 | } |
| 311 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 312 | bool ptsDisjoint(double t1, const SkPoint& pt1, double t2, const SkPoint& pt2) const; |
| 313 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 314 | void rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits, |
| 315 | SkChunkAlloc* allocator); |
| 316 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 317 | void resetVisited() { |
| 318 | fVisited = false; |
| 319 | } |
| 320 | |
| 321 | void setContour(SkOpContour* contour) { |
| 322 | fContour = contour; |
| 323 | } |
| 324 | |
| 325 | void setNext(SkOpSegment* next) { |
| 326 | fNext = next; |
| 327 | } |
| 328 | |
| 329 | void setPrev(SkOpSegment* prev) { |
| 330 | fPrev = prev; |
| 331 | } |
| 332 | |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 333 | void setVisited() { |
| 334 | fVisited = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void setUpWinding(SkOpSpanBase* start, SkOpSpanBase* end, int* maxWinding, int* sumWinding) { |
| 338 | int deltaSum = SpanSign(start, end); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 339 | *maxWinding = *sumWinding; |
| 340 | *sumWinding -= deltaSum; |
| 341 | } |
| 342 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 343 | void setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding, |
| 344 | int* maxWinding, int* sumWinding); |
| 345 | void setUpWindings(SkOpSpanBase* start, SkOpSpanBase* end, int* sumMiWinding, int* sumSuWinding, |
| 346 | int* maxWinding, int* sumWinding, int* oppMaxWinding, int* oppSumWinding); |
| 347 | void sortAngles(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 348 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 349 | static int SpanSign(const SkOpSpanBase* start, const SkOpSpanBase* end) { |
| 350 | int result = start->t() < end->t() ? -start->upCast()->windValue() |
| 351 | : end->upCast()->windValue(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 352 | return result; |
| 353 | } |
| 354 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 355 | SkOpAngle* spanToAngle(SkOpSpanBase* start, SkOpSpanBase* end) { |
| 356 | SkASSERT(start != end); |
| 357 | return start->t() < end->t() ? start->upCast()->toAngle() : start->fromAngle(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 358 | } |
| 359 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 360 | bool subDivide(const SkOpSpanBase* start, const SkOpSpanBase* end, SkDCurve* result) const; |
| 361 | bool subDivide(const SkOpSpanBase* start, const SkOpSpanBase* end, SkOpCurve* result) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 362 | |
| 363 | const SkOpSpanBase* tail() const { |
| 364 | return &fTail; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 365 | } |
| 366 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 367 | SkOpSpanBase* tail() { |
| 368 | return &fTail; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 369 | } |
skia.committer@gmail.com | 3284017 | 2013-04-09 07:01:27 +0000 | [diff] [blame] | 370 | |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 371 | bool testForCoincidence(const SkOpPtT* priorPtT, const SkOpPtT* ptT, const SkOpSpanBase* prior, |
| 372 | const SkOpSpanBase* spanBase, const SkOpSegment* opp, SkScalar flatnessLimit) const; |
| 373 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 374 | void undoneSpan(SkOpSpanBase** start, SkOpSpanBase** end); |
| 375 | int updateOppWinding(const SkOpSpanBase* start, const SkOpSpanBase* end) const; |
| 376 | int updateOppWinding(const SkOpAngle* angle) const; |
| 377 | int updateOppWindingReverse(const SkOpAngle* angle) const; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 378 | int updateWinding(SkOpSpanBase* start, SkOpSpanBase* end); |
| 379 | int updateWinding(SkOpAngle* angle); |
| 380 | int updateWindingReverse(const SkOpAngle* angle); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 381 | |
| 382 | static bool UseInnerWinding(int outerWinding, int innerWinding); |
| 383 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 384 | SkPath::Verb verb() const { |
| 385 | return fVerb; |
| 386 | } |
| 387 | |
caryclark | bca19f7 | 2015-05-13 08:23:48 -0700 | [diff] [blame] | 388 | // look for two different spans that point to the same opposite segment |
| 389 | bool visited() { |
| 390 | if (!fVisited) { |
| 391 | fVisited = true; |
| 392 | return false; |
| 393 | } |
| 394 | return true; |
| 395 | } |
| 396 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 397 | SkScalar weight() const { |
| 398 | return fWeight; |
| 399 | } |
| 400 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 401 | SkOpSpan* windingSpanAtT(double tHit); |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 402 | int windSum(const SkOpAngle* angle) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 403 | |
| 404 | SkPoint* writablePt(bool end) { |
| 405 | return &fPts[end ? SkPathOpsVerbToPoints(fVerb) : 0]; |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 406 | } |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 407 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 408 | private: |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 409 | SkOpSpan fHead; // the head span always has its t set to zero |
| 410 | SkOpSpanBase fTail; // the tail span always has its t set to one |
| 411 | SkOpContour* fContour; |
| 412 | SkOpSegment* fNext; // forward-only linked list used by contour to walk the segments |
| 413 | const SkOpSegment* fPrev; |
caryclark | 27c8eb8 | 2015-07-06 11:38:33 -0700 | [diff] [blame] | 414 | SkPoint fOriginal[2]; // if aligned, the original unaligned points are here |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 415 | SkPoint* fPts; // pointer into array of points owned by edge builder that may be tweaked |
| 416 | SkPathOpsBounds fBounds; // tight bounds |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 417 | SkScalar fWeight; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 418 | int fCount; // number of spans (one for a non-intersecting segment) |
| 419 | int fDoneCount; // number of processed spans (zero initially) |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 420 | SkPath::Verb fVerb; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 421 | bool fVisited; // used by missing coincidence check |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 422 | SkDEBUGCODE(int fID); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | #endif |