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 | 7 |
8 #ifndef SkPathOpsCubic_DEFINED | 8 #ifndef SkPathOpsCubic_DEFINED |
9 #define SkPathOpsCubic_DEFINED | 9 #define SkPathOpsCubic_DEFINED |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 double calcPrecision() const; | 51 double calcPrecision() const; |
52 SkDCubicPair chopAt(double t) const; | 52 SkDCubicPair chopAt(double t) const; |
53 static void Coefficients(const double* cubic, double* A, double* B, double*
C, double* D); | 53 static void Coefficients(const double* cubic, double* A, double* B, double*
C, double* D); |
54 static bool ComplexBreak(const SkPoint pts[4], SkScalar* t); | 54 static bool ComplexBreak(const SkPoint pts[4], SkScalar* t); |
55 int convexHull(char order[kPointCount]) const; | 55 int convexHull(char order[kPointCount]) const; |
56 | 56 |
57 void debugInit() { | 57 void debugInit() { |
58 sk_bzero(fPts, sizeof(fPts)); | 58 sk_bzero(fPts, sizeof(fPts)); |
59 } | 59 } |
60 | 60 |
| 61 void debugSet(const SkDPoint* pts); |
| 62 |
61 void dump() const; // callable from the debugger when the implementation co
de is linked in | 63 void dump() const; // callable from the debugger when the implementation co
de is linked in |
62 void dumpID(int id) const; | 64 void dumpID(int id) const; |
63 void dumpInner() const; | 65 void dumpInner() const; |
64 SkDVector dxdyAtT(double t) const; | 66 SkDVector dxdyAtT(double t) const; |
65 bool endsAreExtremaInXOrY() const; | 67 bool endsAreExtremaInXOrY() const; |
66 static int FindExtrema(const double src[], double tValue[2]); | 68 static int FindExtrema(const double src[], double tValue[2]); |
67 int findInflections(double tValues[2]) const; | 69 int findInflections(double tValues[2]) const; |
68 | 70 |
69 static int FindInflections(const SkPoint a[kPointCount], double tValues[2])
{ | 71 static int FindInflections(const SkPoint a[kPointCount], double tValues[2])
{ |
70 SkDCubic cubic; | 72 SkDCubic cubic; |
71 return cubic.set(a).findInflections(tValues); | 73 return cubic.set(a).findInflections(tValues); |
72 } | 74 } |
73 | 75 |
74 int findMaxCurvature(double tValues[]) const; | 76 int findMaxCurvature(double tValues[]) const; |
| 77 |
| 78 #ifdef SK_DEBUG |
| 79 SkOpGlobalState* globalState() const { return fDebugGlobalState; } |
| 80 #endif |
| 81 |
75 bool hullIntersects(const SkDCubic& c2, bool* isLinear) const; | 82 bool hullIntersects(const SkDCubic& c2, bool* isLinear) const; |
76 bool hullIntersects(const SkDConic& c, bool* isLinear) const; | 83 bool hullIntersects(const SkDConic& c, bool* isLinear) const; |
77 bool hullIntersects(const SkDQuad& c2, bool* isLinear) const; | 84 bool hullIntersects(const SkDQuad& c2, bool* isLinear) const; |
78 bool hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear) const; | 85 bool hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear) const; |
79 bool isLinear(int startIndex, int endIndex) const; | 86 bool isLinear(int startIndex, int endIndex) const; |
80 bool monotonicInX() const; | 87 bool monotonicInX() const; |
81 bool monotonicInY() const; | 88 bool monotonicInY() const; |
82 void otherPts(int index, const SkDPoint* o1Pts[kPointCount - 1]) const; | 89 void otherPts(int index, const SkDPoint* o1Pts[kPointCount - 1]) const; |
83 SkDPoint ptAtT(double t) const; | 90 SkDPoint ptAtT(double t) const; |
84 static int RootsReal(double A, double B, double C, double D, double t[3]); | 91 static int RootsReal(double A, double B, double C, double D, double t[3]); |
85 static int RootsValidT(const double A, const double B, const double C, doubl
e D, double s[3]); | 92 static int RootsValidT(const double A, const double B, const double C, doubl
e D, double s[3]); |
86 | 93 |
87 int searchRoots(double extremes[6], int extrema, double axisIntercept, | 94 int searchRoots(double extremes[6], int extrema, double axisIntercept, |
88 SearchAxis xAxis, double* validRoots) const; | 95 SearchAxis xAxis, double* validRoots) const; |
89 | 96 |
90 /** | 97 /** |
91 * Return the number of valid roots (0 < root < 1) for this cubic intersect
ing the | 98 * Return the number of valid roots (0 < root < 1) for this cubic intersect
ing the |
92 * specified horizontal line. | 99 * specified horizontal line. |
93 */ | 100 */ |
94 int horizontalIntersect(double yIntercept, double roots[3]) const; | 101 int horizontalIntersect(double yIntercept, double roots[3]) const; |
95 /** | 102 /** |
96 * Return the number of valid roots (0 < root < 1) for this cubic intersect
ing the | 103 * Return the number of valid roots (0 < root < 1) for this cubic intersect
ing the |
97 * specified vertical line. | 104 * specified vertical line. |
98 */ | 105 */ |
99 int verticalIntersect(double xIntercept, double roots[3]) const; | 106 int verticalIntersect(double xIntercept, double roots[3]) const; |
100 | 107 |
101 const SkDCubic& set(const SkPoint pts[kPointCount]) { | 108 // add debug only global pointer so asserts can be skipped by fuzzers |
| 109 const SkDCubic& set(const SkPoint pts[kPointCount] |
| 110 SkDEBUGPARAMS(SkOpGlobalState* state = nullptr)) { |
102 fPts[0] = pts[0]; | 111 fPts[0] = pts[0]; |
103 fPts[1] = pts[1]; | 112 fPts[1] = pts[1]; |
104 fPts[2] = pts[2]; | 113 fPts[2] = pts[2]; |
105 fPts[3] = pts[3]; | 114 fPts[3] = pts[3]; |
| 115 SkDEBUGCODE(fDebugGlobalState = state); |
106 return *this; | 116 return *this; |
107 } | 117 } |
108 | 118 |
109 SkDCubic subDivide(double t1, double t2) const; | 119 SkDCubic subDivide(double t1, double t2) const; |
110 | 120 |
111 static SkDCubic SubDivide(const SkPoint a[kPointCount], double t1, double t2
) { | 121 static SkDCubic SubDivide(const SkPoint a[kPointCount], double t1, double t2
) { |
112 SkDCubic cubic; | 122 SkDCubic cubic; |
113 return cubic.set(a).subDivide(t1, t2); | 123 return cubic.set(a).subDivide(t1, t2); |
114 } | 124 } |
115 | 125 |
116 void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, S
kDPoint p[2]) const; | 126 void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, S
kDPoint p[2]) const; |
117 | 127 |
118 static void SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a, con
st SkDPoint& d, double t1, | 128 static void SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a, con
st SkDPoint& d, double t1, |
119 double t2, SkDPoint p[2]) { | 129 double t2, SkDPoint p[2]) { |
120 SkDCubic cubic; | 130 SkDCubic cubic; |
121 cubic.set(pts).subDivide(a, d, t1, t2, p); | 131 cubic.set(pts).subDivide(a, d, t1, t2, p); |
122 } | 132 } |
123 | 133 |
124 double top(const SkDCubic& dCurve, double startT, double endT, SkDPoint*topP
t) const; | 134 double top(const SkDCubic& dCurve, double startT, double endT, SkDPoint*topP
t) const; |
125 SkDQuad toQuad() const; | 135 SkDQuad toQuad() const; |
126 | 136 |
127 static const int gPrecisionUnit; | 137 static const int gPrecisionUnit; |
128 | |
129 SkDPoint fPts[kPointCount]; | 138 SkDPoint fPts[kPointCount]; |
| 139 SkDEBUGCODE(SkOpGlobalState* fDebugGlobalState); |
130 }; | 140 }; |
131 | 141 |
132 /* Given the set [0, 1, 2, 3], and two of the four members, compute an XOR mask | 142 /* Given the set [0, 1, 2, 3], and two of the four members, compute an XOR mask |
133 that computes the other two. Note that: | 143 that computes the other two. Note that: |
134 | 144 |
135 one ^ two == 3 for (0, 3), (1, 2) | 145 one ^ two == 3 for (0, 3), (1, 2) |
136 one ^ two < 3 for (0, 1), (0, 2), (1, 3), (2, 3) | 146 one ^ two < 3 for (0, 1), (0, 2), (1, 3), (2, 3) |
137 3 - (one ^ two) is either 0, 1, or 2 | 147 3 - (one ^ two) is either 0, 1, or 2 |
138 1 >> (3 - (one ^ two)) is either 0 or 1 | 148 1 >> (3 - (one ^ two)) is either 0 or 1 |
139 thus: | 149 thus: |
140 returned == 2 for (0, 3), (1, 2) | 150 returned == 2 for (0, 3), (1, 2) |
141 returned == 3 for (0, 1), (0, 2), (1, 3), (2, 3) | 151 returned == 3 for (0, 1), (0, 2), (1, 3), (2, 3) |
142 given that: | 152 given that: |
143 (0, 3) ^ 2 -> (2, 1) (1, 2) ^ 2 -> (3, 0) | 153 (0, 3) ^ 2 -> (2, 1) (1, 2) ^ 2 -> (3, 0) |
144 (0, 1) ^ 3 -> (3, 2) (0, 2) ^ 3 -> (3, 1) (1, 3) ^ 3 -> (2, 0) (2, 3) ^ 3
-> (1, 0) | 154 (0, 1) ^ 3 -> (3, 2) (0, 2) ^ 3 -> (3, 1) (1, 3) ^ 3 -> (2, 0) (2, 3) ^ 3
-> (1, 0) |
145 */ | 155 */ |
146 inline int other_two(int one, int two) { | 156 inline int other_two(int one, int two) { |
147 return 1 >> (3 - (one ^ two)) ^ 3; | 157 return 1 >> (3 - (one ^ two)) ^ 3; |
148 } | 158 } |
149 | 159 |
150 #endif | 160 #endif |
OLD | NEW |