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 void 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 unorderable() const { 91 return fUnorderable; 92 } 93 94 private: 95 bool after(SkOpAngle* test); 96 int allOnOneSide(const SkOpAngle* test); 97 bool checkCrossesZero() const; 98 bool checkParallel(SkOpAngle* ); 99 bool computeSector(); 100 int convexHullOverlaps(const SkOpAngle* ) const; 101 bool endToSide(const SkOpAngle* rh, bool* inside) const; 102 bool endsIntersect(SkOpAngle* ); 103 int findSector(SkPath::Verb verb, double x, double y) const; 104 SkOpGlobalState* globalState() const; 105 bool merge(SkOpAngle* ); 106 double midT() const; 107 bool midToSide(const SkOpAngle* rh, bool* inside) const; 108 bool oppositePlanes(const SkOpAngle* rh) const; 109 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh 110 void setSector(); 111 void setSpans(); 112 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const; 113 114 SkDCurve fOriginalCurvePart; // the curve from start to end 115 SkDCurveSweep fPart; // the curve from start to end offset as needed 116 double fSide; 117 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections 118 SkOpAngle* fNext; 119 SkOpSpanBase* fLastMarked; 120 SkOpSpanBase* fStart; 121 SkOpSpanBase* fEnd; 122 SkOpSpanBase* fComputedEnd; 123 int fSectorMask; 124 int8_t fSectorStart; // in 32nds of a circle 125 int8_t fSectorEnd; 126 bool fUnorderable; 127 bool fComputeSector; 128 bool fComputedSector; 129 bool fCheckCoincidence; 130 SkDEBUGCODE(int fID); 131 132 friend class PathOpsAngleTester; 133 }; 134 135 136 137 #endif 138