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 SkOpAngle_DEFINED 8 #define SkOpAngle_DEFINED 9 10 #include "SkLineParameters.h" 11 #include "SkPathOpsCurve.h" 12 #if DEBUG_ANGLE 13 #include "SkString.h" 14 #endif 15 16 class SkOpContour; 17 class SkOpPtT; 18 class SkOpSegment; 19 class SkOpSpanBase; 20 class SkOpSpan; 21 22 struct SkOpAngle { 23 enum IncludeType { 24 kUnaryWinding, 25 kUnaryXor, 26 kBinarySingle, 27 kBinaryOpp, 28 }; 29 30 bool after(SkOpAngle* test); 31 int allOnOneSide(const SkOpAngle* test); 32 bool checkCrossesZero() const; 33 bool checkParallel(SkOpAngle* ); 34 bool computeSector(); 35 int convexHullOverlaps(const SkOpAngle* ) const; 36 37 const SkOpAngle* debugAngle(int id) const; 38 SkOpContour* debugContour(int id); 39 debugIDSkOpAngle40 int debugID() const { 41 return SkDEBUGRELEASE(fID, -1); 42 } 43 44 #if DEBUG_SORT 45 void debugLoop() const; 46 #endif 47 48 #if DEBUG_ANGLE 49 void debugCheckNearCoincidence() const; 50 SkString debugPart() const; 51 #endif 52 const SkOpPtT* debugPtT(int id) const; 53 const SkOpSegment* debugSegment(int id) const; 54 int debugSign() const; 55 const SkOpSpanBase* debugSpan(int id) const; 56 void debugValidate() const; 57 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted 58 double distEndRatio(double dist) const; 59 // available to testing only 60 void dump() const; 61 void dumpCurves() const; 62 void dumpLoop() const; 63 void dumpOne(bool functionHeader) const; 64 void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const; 65 void dumpTest() const; 66 endSkOpAngle67 SkOpSpanBase* end() const { 68 return fEnd; 69 } 70 71 bool endsIntersect(SkOpAngle* ); 72 bool endToSide(const SkOpAngle* rh, bool* inside) const; 73 int findSector(SkPath::Verb verb, double x, double y) const; 74 SkOpGlobalState* globalState() const; 75 void insert(SkOpAngle* ); 76 SkOpSpanBase* lastMarked() const; 77 bool loopContains(const SkOpAngle* ) const; 78 int loopCount() const; 79 bool merge(SkOpAngle* ); 80 double midT() const; 81 bool midToSide(const SkOpAngle* rh, bool* inside) const; 82 nextSkOpAngle83 SkOpAngle* next() const { 84 return fNext; 85 } 86 87 bool oppositePlanes(const SkOpAngle* rh) const; 88 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh 89 SkOpAngle* previous() const; 90 sectorEndSkOpAngle91 int sectorEnd() const { 92 return fSectorEnd; 93 } 94 sectorStartSkOpAngle95 int sectorStart() const { 96 return fSectorStart; 97 } 98 99 SkOpSegment* segment() const; 100 101 void set(SkOpSpanBase* start, SkOpSpanBase* end); 102 void setCurveHullSweep(); 103 setIDSkOpAngle104 void setID(int id) { 105 SkDEBUGCODE(fID = id); 106 } 107 setLastMarkedSkOpAngle108 void setLastMarked(SkOpSpanBase* marked) { 109 fLastMarked = marked; 110 } 111 112 void setSector(); 113 void setSpans(); 114 startSkOpAngle115 SkOpSpanBase* start() const { 116 return fStart; 117 } 118 119 SkOpSpan* starter(); 120 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const; 121 unorderableSkOpAngle122 bool unorderable() const { 123 return fUnorderable; 124 } 125 126 SkDCurve fCurvePart; // the curve from start to end 127 double fSide; 128 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections 129 SkOpAngle* fNext; 130 SkOpSpanBase* fLastMarked; 131 SkDVector fSweep[2]; 132 SkOpSpanBase* fStart; 133 SkOpSpanBase* fEnd; 134 SkOpSpanBase* fComputedEnd; 135 int fSectorMask; 136 int8_t fSectorStart; // in 32nds of a circle 137 int8_t fSectorEnd; 138 bool fIsCurve; 139 bool fUnorderable; 140 bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors 141 bool fComputeSector; 142 bool fComputedSector; 143 bool fCheckCoincidence; 144 SkDEBUGCODE(int fID); 145 146 }; 147 148 149 150 #endif 151