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