OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #ifndef SkOpAngle_DEFINED | 7 #ifndef SkOpAngle_DEFINED |
8 #define SkOpAngle_DEFINED | 8 #define SkOpAngle_DEFINED |
9 | 9 |
10 #include "SkLineParameters.h" | 10 #include "SkLineParameters.h" |
11 #include "SkPath.h" | |
12 #include "SkPathOpsCubic.h" | |
13 | 11 |
14 class SkOpSegment; | 12 class SkOpSegment; |
15 struct SkOpSpan; | 13 struct SkOpSpan; |
16 | 14 |
17 // sorting angles | 15 // sorting angles |
18 // given angles of {dx dy ddx ddy dddx dddy} sort them | 16 // given angles of {dx dy ddx ddy dddx dddy} sort them |
19 class SkOpAngle { | 17 class SkOpAngle { |
20 public: | 18 public: |
21 enum { kStackBasedCount = 8 }; // FIXME: determine what this should be | 19 enum { kStackBasedCount = 8 }; // FIXME: determine what this should be |
22 enum IncludeType { | 20 enum IncludeType { |
23 kUnaryWinding, | 21 kUnaryWinding, |
24 kUnaryXor, | 22 kUnaryXor, |
25 kBinarySingle, | 23 kBinarySingle, |
26 kBinaryOpp, | 24 kBinaryOpp, |
27 }; | 25 }; |
28 | 26 |
29 bool operator<(const SkOpAngle& rh) const; | |
30 | |
31 bool calcSlop(double x, double y, double rx, double ry, bool* result) const; | |
32 | |
33 double dx() const { | |
34 return fTangentPart.dx(); | |
35 } | |
36 | |
37 double dy() const { | |
38 return fTangentPart.dy(); | |
39 } | |
40 | |
41 int end() const { | 27 int end() const { |
42 return fEnd; | 28 return fEnd; |
43 } | 29 } |
44 | 30 |
| 31 const SkOpAngle* findFirst() const; |
| 32 |
| 33 bool inLoop() const { |
| 34 return !!fNext; |
| 35 } |
| 36 |
| 37 void insert(SkOpAngle* ); |
45 bool isHorizontal() const; | 38 bool isHorizontal() const; |
| 39 SkOpSpan* lastMarked() const; |
| 40 int loopCount() const; |
| 41 void markStops(); |
| 42 bool merge(SkOpAngle* ); |
46 | 43 |
47 SkOpSpan* lastMarked() const { | 44 SkOpAngle* next() const { |
48 return fLastMarked; | 45 return fNext; |
49 } | 46 } |
50 | 47 |
| 48 SkOpAngle* previous() const; |
| 49 |
51 void set(const SkOpSegment* segment, int start, int end); | 50 void set(const SkOpSegment* segment, int start, int end); |
52 | 51 |
53 void setLastMarked(SkOpSpan* marked) { | 52 void setLastMarked(SkOpSpan* marked) { |
54 fLastMarked = marked; | 53 fLastMarked = marked; |
55 } | 54 } |
56 | 55 |
57 SkOpSegment* segment() const { | 56 SkOpSegment* segment() const { |
58 return const_cast<SkOpSegment*>(fSegment); | 57 return const_cast<SkOpSegment*>(fSegment); |
59 } | 58 } |
60 | 59 |
61 int sign() const { | 60 int sign() const { |
62 return SkSign32(fStart - fEnd); | 61 return SkSign32(fStart - fEnd); |
63 } | 62 } |
64 | 63 |
| 64 bool small() const; |
| 65 |
65 int start() const { | 66 int start() const { |
66 return fStart; | 67 return fStart; |
67 } | 68 } |
68 | 69 |
69 bool unorderable() const { | 70 bool unorderable() const { |
70 return fUnorderable; | 71 return fUnorderable; |
71 } | 72 } |
72 | 73 |
73 bool unsortable() const { | 74 // available to testing only |
74 return fUnsortable; | 75 #if DEBUG_SORT |
75 } | 76 void debugLoop() const; // called by code during run |
76 | 77 #endif |
77 #ifdef SK_DEBUG | 78 #if DEBUG_ANGLE |
| 79 void debugSameAs(const SkOpAngle* compare) const; |
| 80 #endif |
78 void dump() const; | 81 void dump() const; |
79 #endif | 82 void dumpFromTo(const SkOpSegment* fromSeg, int from, int to) const; |
80 | 83 |
81 #if DEBUG_ANGLE | 84 #if DEBUG_ANGLE |
82 void setID(int id) { | 85 void setID(int id) { |
83 fID = id; | 86 fID = id; |
84 } | 87 } |
85 #endif | 88 #endif |
| 89 #if DEBUG_VALIDATE |
| 90 void debugValidateLoop() const; |
| 91 #endif |
86 | 92 |
87 private: | 93 private: |
88 bool lengthen(const SkOpAngle& ); | 94 bool after(const SkOpAngle* test) const; |
| 95 int allOnOneSide(const SkOpAngle& test) const; |
| 96 bool calcSlop(double x, double y, double rx, double ry, bool* result) const; |
| 97 bool checkCrossesZero() const; |
| 98 bool checkParallel(const SkOpAngle& ) const; |
| 99 bool computeSector(); |
| 100 int convexHullOverlaps(const SkOpAngle& ) const; |
| 101 double distEndRatio(double dist) const; |
| 102 int findSector(SkPath::Verb verb, double x, double y) const; |
| 103 bool endsIntersect(const SkOpAngle& ) const; |
| 104 double midT() const; |
| 105 bool oppositePlanes(const SkOpAngle& rh) const; |
| 106 bool orderable(const SkOpAngle& rh) const; // false == this < rh ; true ==
this > rh |
| 107 void setCurveHullSweep(); |
| 108 void setSector(); |
89 void setSpans(); | 109 void setSpans(); |
| 110 bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const; |
90 | 111 |
91 SkDCubic fCurvePart; // the curve from start to end | 112 SkDCubic fCurvePart; // the curve from start to end |
92 SkDCubic fCurveHalf; // the curve from start to 1 or 0 | |
93 double fSide; | 113 double fSide; |
94 double fSide2; | 114 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line
-like sections |
95 SkLineParameters fTangentPart; | |
96 SkLineParameters fTangentHalf; | |
97 const SkOpSegment* fSegment; | 115 const SkOpSegment* fSegment; |
| 116 SkOpAngle* fNext; |
98 SkOpSpan* fLastMarked; | 117 SkOpSpan* fLastMarked; |
| 118 SkDVector fSweep[2]; |
99 int fStart; | 119 int fStart; |
100 int fEnd; | 120 int fEnd; |
101 bool fComputed; // tangent is computed, may contain some error | 121 int fSectorMask; |
102 // if subdividing a quad or cubic causes the tangent to go from the maximum
angle to the | 122 char fSectorStart; // in 32nds of a circle |
103 // minimum, mark it unorderable. It still can be sorted, which is good enoug
h for find-top | 123 char fSectorEnd; |
104 // but can't be ordered, and therefore can't be used to compute winding | 124 bool fIsCurve; |
105 bool fUnorderable; | 125 bool fStop; // set if ordered angle is greater than the previous |
106 mutable bool fUnsortable; // this alone is editable by the less than operat
or | 126 mutable bool fUnorderable; // this is editable by orderable() |
| 127 bool fUnorderedSweep; // set when a cubic's first control point between the
sweep vectors |
| 128 bool fComputeSector; |
| 129 bool fComputedSector; |
| 130 |
| 131 #if DEBUG_SORT |
| 132 void debugOne(bool showFunc) const; // available to testing only |
| 133 #endif |
107 #if DEBUG_ANGLE | 134 #if DEBUG_ANGLE |
| 135 int debugID() const { return fID; } |
108 int fID; | 136 int fID; |
109 #endif | 137 #endif |
| 138 #if DEBUG_VALIDATE |
| 139 void debugValidateNext() const; // in debug builds, verify that angle loop
is uncorrupted |
| 140 #else |
| 141 void debugValidateNext() const {} |
| 142 #endif |
| 143 void dumpLoop() const; // utility to be called by user from debugger |
| 144 void dumpPartials() const; // utility to be called by user from debugger |
| 145 friend class PathOpsAngleTester; |
110 }; | 146 }; |
111 | 147 |
112 #endif | 148 #endif |
OLD | NEW |