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 "src/pathops/SkLineParameters.h"
11 #include "src/pathops/SkPathOpsCurve.h"
12 #if DEBUG_ANGLE
13 #include "include/core/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 
debugID()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
debugCheckCoincidence()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 
end()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 
next()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 
setLastMarked(SkOpSpanBase * marked)80     void setLastMarked(SkOpSpanBase* marked) {
81         fLastMarked = marked;
82     }
83 
start()84     SkOpSpanBase* start() const {
85         return fStart;
86     }
87 
88     SkOpSpan* starter();
89 
tangentsAmbiguous()90     bool tangentsAmbiguous() const {
91         return fTangentsAmbiguous;
92     }
93 
unorderable()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     bool checkCrossesZero() const;
102     bool checkParallel(SkOpAngle* );
103     bool computeSector();
104     int convexHullOverlaps(const SkOpAngle* );
105     bool endToSide(const SkOpAngle* rh, bool* inside) const;
106     bool endsIntersect(SkOpAngle* );
107     int findSector(SkPath::Verb verb, double x, double y) const;
108     SkOpGlobalState* globalState() const;
109     int lineOnOneSide(const SkDPoint& origin, const SkDVector& line, const SkOpAngle* test,
110                       bool useOriginal) const;
111     int lineOnOneSide(const SkOpAngle* test, bool useOriginal);
112     int linesOnOriginalSide(const SkOpAngle* test);
113     bool merge(SkOpAngle* );
114     double midT() const;
115     bool midToSide(const SkOpAngle* rh, bool* inside) const;
116     bool oppositePlanes(const SkOpAngle* rh) const;
117     int orderable(SkOpAngle* rh);  // false == this < rh ; true == this > rh; -1 == unorderable
118     void setSector();
119     void setSpans();
120     bool tangentsDiverge(const SkOpAngle* rh, double s0xt0);
121 
122     SkDCurve fOriginalCurvePart;  // the curve from start to end
123     SkDCurveSweep fPart;  // the curve from start to end offset as needed
124     double fSide;
125     SkLineParameters fTangentHalf;  // used only to sort a pair of lines or line-like sections
126     SkOpAngle* fNext;
127     SkOpSpanBase* fLastMarked;
128     SkOpSpanBase* fStart;
129     SkOpSpanBase* fEnd;
130     SkOpSpanBase* fComputedEnd;
131     int fSectorMask;
132     int8_t fSectorStart;  // in 32nds of a circle
133     int8_t fSectorEnd;
134     bool fUnorderable;
135     bool fComputeSector;
136     bool fComputedSector;
137     bool fCheckCoincidence;
138     bool fTangentsAmbiguous;
139     SkDEBUGCODE(int fID);
140 
141     friend class PathOpsAngleTester;
142 };
143 
144 
145 
146 #endif
147