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 class SkOpAngle { 23 public: 24 enum IncludeType { 25 kUnaryWinding, 26 kUnaryXor, 27 kBinarySingle, 28 kBinaryOpp, 29 }; 30 31 const SkOpAngle* debugAngle(int id) const; 32 const SkOpCoincidence* debugCoincidence() const; 33 SkOpContour* debugContour(int id) const; 34 35 int debugID() const { 36 return SkDEBUGRELEASE(fID, -1); 37 } 38 39 #if DEBUG_SORT 40 void debugLoop() const; 41 #endif 42 43 #if DEBUG_ANGLE 44 bool debugCheckCoincidence() const { return fCheckCoincidence; } 45 void debugCheckNearCoincidence() const; 46 SkString debugPart() const; 47 #endif 48 const SkOpPtT* debugPtT(int id) const; 49 const SkOpSegment* debugSegment(int id) const; 50 int debugSign() const; 51 const SkOpSpanBase* debugSpan(int id) const; 52 void debugValidate() const; 53 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted 54 double distEndRatio(double dist) const; 55 // available to testing only 56 void dump() const; 57 void dumpCurves() const; 58 void dumpLoop() const; 59 void dumpOne(bool functionHeader) const; 60 void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const; 61 void dumpTest() const; 62 63 SkOpSpanBase* end() const { 64 return fEnd; 65 } 66 67 bool insert(SkOpAngle* ); 68 SkOpSpanBase* lastMarked() const; 69 bool loopContains(const SkOpAngle* ) const; 70 int loopCount() const; 71 72 SkOpAngle* next() const { 73 return fNext; 74 } 75 76 SkOpAngle* previous() const; 77 SkOpSegment* segment() const; 78 void set(SkOpSpanBase* start, SkOpSpanBase* end); 79 80 void setLastMarked(SkOpSpanBase* marked) { 81 fLastMarked = marked; 82 } 83 84 SkOpSpanBase* start() const { 85 return fStart; 86 } 87 88 SkOpSpan* starter(); 89 90 bool tangentsAmbiguous() const { 91 return fTangentsAmbiguous; 92 } 93 94 bool unorderable() const { 95 return fUnorderable; 96 } 97 98 private: 99 bool after(SkOpAngle* test); 100 void alignmentSameSide(const SkOpAngle* test, int* order) const; 101 int allOnOneSide(const SkOpAngle* test); 102 bool checkCrossesZero() const; 103 bool checkParallel(SkOpAngle* ); 104 bool computeSector(); 105 int convexHullOverlaps(const SkOpAngle* ); 106 bool endToSide(const SkOpAngle* rh, bool* inside) const; 107 bool endsIntersect(SkOpAngle* ); 108 int findSector(SkPath::Verb verb, double x, double y) const; 109 SkOpGlobalState* globalState() const; 110 bool merge(SkOpAngle* ); 111 double midT() const; 112 bool midToSide(const SkOpAngle* rh, bool* inside) const; 113 bool oppositePlanes(const SkOpAngle* rh) const; 114 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh 115 void setSector(); 116 void setSpans(); 117 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0); 118 119 SkDCurve fOriginalCurvePart; // the curve from start to end 120 SkDCurveSweep fPart; // the curve from start to end offset as needed 121 double fSide; 122 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections 123 SkOpAngle* fNext; 124 SkOpSpanBase* fLastMarked; 125 SkOpSpanBase* fStart; 126 SkOpSpanBase* fEnd; 127 SkOpSpanBase* fComputedEnd; 128 int fSectorMask; 129 int8_t fSectorStart; // in 32nds of a circle 130 int8_t fSectorEnd; 131 bool fUnorderable; 132 bool fComputeSector; 133 bool fComputedSector; 134 bool fCheckCoincidence; 135 bool fTangentsAmbiguous; 136 SkDEBUGCODE(int fID); 137 138 friend class PathOpsAngleTester; 139 }; 140 141 142 143 #endif 144