Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / pathops / SkOpAngle.h
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
12 class SkOpSegment;
13 struct SkOpSpan;
14
15 // sorting angles
16 // given angles of {dx dy ddx ddy dddx dddy} sort them
17 class SkOpAngle {
18 public:
19     enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
20     enum IncludeType {
21         kUnaryWinding,
22         kUnaryXor,
23         kBinarySingle,
24         kBinaryOpp,
25     };
26
27
28     int end() const {
29         return fEnd;
30     }
31
32     const SkOpAngle* findFirst() const;
33
34     bool inLoop() const {
35         return !!fNext;
36     }
37
38     void insert(SkOpAngle* );
39     bool isHorizontal() const;
40     SkOpSpan* lastMarked() const;
41     bool loopContains(const SkOpAngle& ) const;
42     int loopCount() const;
43     void markStops();
44     bool merge(SkOpAngle* );
45
46     SkOpAngle* next() const {
47         return fNext;
48     }
49
50     SkOpAngle* previous() const;
51
52     void set(const SkOpSegment* segment, int start, int end);
53
54     void setLastMarked(SkOpSpan* marked) {
55         fLastMarked = marked;
56     }
57
58     SkOpSegment* segment() const {
59         return const_cast<SkOpSegment*>(fSegment);
60     }
61
62     int sign() const {
63         return SkSign32(fStart - fEnd);
64     }
65
66     bool small() const;
67
68     int start() const {
69         return fStart;
70     }
71
72     bool unorderable() const {
73         return fUnorderable;
74     }
75
76     // available to testing only
77 #if DEBUG_SORT
78     void debugLoop() const;  // called by code during run
79 #endif
80 #if DEBUG_ANGLE
81     void debugSameAs(const SkOpAngle* compare) const;
82 #endif
83     void dump() const;
84     void dumpFromTo(const SkOpSegment* fromSeg, int from, int to) const;
85
86 #if DEBUG_ANGLE
87     void setID(int id) {
88         fID = id;
89     }
90 #endif
91 #if DEBUG_VALIDATE
92     void debugValidateLoop() const;
93 #endif
94
95 private:
96     bool after(const SkOpAngle* test) const;
97     int allOnOneSide(const SkOpAngle& test) const;
98     bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
99     bool checkCrossesZero() const;
100     bool checkParallel(const SkOpAngle& ) const;
101     bool computeSector();
102     int convexHullOverlaps(const SkOpAngle& ) const;
103     double distEndRatio(double dist) const;
104     int findSector(SkPath::Verb verb, double x, double y) const;
105     bool endsIntersect(const SkOpAngle& ) const;
106     double midT() const;
107     bool oppositePlanes(const SkOpAngle& rh) const;
108     bool orderable(const SkOpAngle& rh) const;  // false == this < rh ; true == this > rh
109     bool overlap(const SkOpAngle& test) const;
110     void setCurveHullSweep();
111     void setSector();
112     void setSpans();
113     bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const;
114
115     SkDCubic fCurvePart; // the curve from start to end
116     double fSide;
117     SkLineParameters fTangentHalf;  // used only to sort a pair of lines or line-like sections
118     const SkOpSegment* fSegment;
119     SkOpAngle* fNext;
120     SkOpSpan* fLastMarked;
121     SkDVector fSweep[2];
122     int fStart;
123     int fEnd;
124     int fSectorMask;
125     int8_t fSectorStart;  // in 32nds of a circle
126     int8_t fSectorEnd;
127     bool fIsCurve;
128     bool fStop; // set if ordered angle is greater than the previous
129     mutable bool fUnorderable;  // this is editable by orderable()
130     bool fUnorderedSweep;  // set when a cubic's first control point between the sweep vectors
131     bool fComputeSector;
132     bool fComputedSector;
133
134 #if DEBUG_SORT
135     void debugOne(bool showFunc) const;  // available to testing only
136 #endif
137 #if DEBUG_ANGLE
138     int debugID() const { return fID; }
139     int fID;
140 #endif
141 #if DEBUG_VALIDATE
142     void debugValidateNext() const;  // in debug builds, verify that angle loop is uncorrupted
143 #else
144     void debugValidateNext() const {}
145 #endif
146     void dumpLoop() const;  // utility to be called by user from debugger
147     void dumpPartials() const;  // utility to be called by user from debugger
148     friend class PathOpsAngleTester;
149 };
150
151 #endif