• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkPath.h"
12 #include "SkPathOpsCubic.h"
13 
14 class SkOpSegment;
15 struct SkOpSpan;
16 
17 // sorting angles
18 // given angles of {dx dy ddx ddy dddx dddy} sort them
19 class SkOpAngle {
20 public:
21     enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
22     enum IncludeType {
23         kUnaryWinding,
24         kUnaryXor,
25         kBinarySingle,
26         kBinaryOpp,
27     };
28 
29     bool operator<(const SkOpAngle& rh) const;
30 
31     bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
32 
dx()33     double dx() const {
34         return fTangentPart.dx();
35     }
36 
dy()37     double dy() const {
38         return fTangentPart.dy();
39     }
40 
end()41     int end() const {
42         return fEnd;
43     }
44 
45     bool isHorizontal() const;
46 
lastMarked()47     SkOpSpan* lastMarked() const {
48         return fLastMarked;
49     }
50 
51     void set(const SkOpSegment* segment, int start, int end);
52 
setLastMarked(SkOpSpan * marked)53     void setLastMarked(SkOpSpan* marked) {
54         fLastMarked = marked;
55     }
56 
segment()57     SkOpSegment* segment() const {
58         return const_cast<SkOpSegment*>(fSegment);
59     }
60 
sign()61     int sign() const {
62         return SkSign32(fStart - fEnd);
63     }
64 
start()65     int start() const {
66         return fStart;
67     }
68 
unorderable()69     bool unorderable() const {
70         return fUnorderable;
71     }
72 
unsortable()73     bool unsortable() const {
74         return fUnsortable;
75     }
76 
77 #ifdef SK_DEBUG
78     void dump() const;
79 #endif
80 
81 #if DEBUG_ANGLE
setID(int id)82     void setID(int id) {
83         fID = id;
84     }
85 #endif
86 
87 private:
88     bool lengthen(const SkOpAngle& );
89     void setSpans();
90 
91     SkDCubic fCurvePart; // the curve from start to end
92     SkDCubic fCurveHalf; // the curve from start to 1 or 0
93     double fSide;
94     double fSide2;
95     SkLineParameters fTangentPart;
96     SkLineParameters fTangentHalf;
97     const SkOpSegment* fSegment;
98     SkOpSpan* fLastMarked;
99     int fStart;
100     int fEnd;
101     bool fComputed; // tangent is computed, may contain some error
102     // if subdividing a quad or cubic causes the tangent to go from the maximum angle to the
103     // minimum, mark it unorderable. It still can be sorted, which is good enough for find-top
104     // but can't be ordered, and therefore can't be used to compute winding
105     bool fUnorderable;
106     mutable bool fUnsortable;  // this alone is editable by the less than operator
107 #if DEBUG_ANGLE
108     int fID;
109 #endif
110 };
111 
112 #endif
113