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 #ifndef SkPathOpsCurve_DEFINE | 7 #ifndef SkPathOpsCurve_DEFINE |
8 #define SkPathOpsCurve_DEFINE | 8 #define SkPathOpsCurve_DEFINE |
9 | 9 |
10 #include "SkIntersections.h" | 10 #include "SkIntersections.h" |
11 #include "SkPathOpsCubic.h" | 11 #include "SkPathOpsCubic.h" |
12 #include "SkPathOpsLine.h" | 12 #include "SkPathOpsLine.h" |
13 #include "SkPathOpsQuad.h" | 13 #include "SkPathOpsQuad.h" |
14 | 14 |
15 #ifndef SK_RELEASE | 15 #ifndef SK_RELEASE |
16 #include "SkPath.h" | 16 #include "SkPath.h" |
17 #endif | 17 #endif |
18 | 18 |
| 19 struct SkPathOpsBounds; |
| 20 |
19 struct SkOpCurve { | 21 struct SkOpCurve { |
20 SkPoint fPts[4]; | 22 SkPoint fPts[4]; |
21 SkScalar fWeight; | 23 SkScalar fWeight; |
22 SkDEBUGCODE(SkPath::Verb fVerb); | 24 SkDEBUGCODE(SkPath::Verb fVerb); |
23 | 25 |
24 const SkPoint& operator[](int n) const { | 26 const SkPoint& operator[](int n) const { |
25 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); | 27 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
26 return fPts[n]; | 28 return fPts[n]; |
27 } | 29 } |
28 | 30 |
29 void dump() const; | 31 void dump() const; |
30 | 32 |
31 void set(const SkDQuad& quad) { | 33 void set(const SkDQuad& quad) { |
32 for (int index = 0; index < SkDQuad::kPointCount; ++index) { | 34 for (int index = 0; index < SkDQuad::kPointCount; ++index) { |
33 fPts[index] = quad[index].asSkPoint(); | 35 fPts[index] = quad[index].asSkPoint(); |
34 } | 36 } |
35 SkDEBUGCODE(fWeight = 1); | 37 SkDEBUGCODE(fWeight = 1); |
36 SkDEBUGCODE(fVerb = SkPath::kQuad_Verb); | 38 SkDEBUGCODE(fVerb = SkPath::kQuad_Verb); |
37 } | 39 } |
38 | 40 |
39 void set(const SkDCubic& cubic) { | 41 void set(const SkDCubic& cubic) { |
40 for (int index = 0; index < SkDCubic::kPointCount; ++index) { | 42 for (int index = 0; index < SkDCubic::kPointCount; ++index) { |
41 fPts[index] = cubic[index].asSkPoint(); | 43 fPts[index] = cubic[index].asSkPoint(); |
42 } | 44 } |
43 SkDEBUGCODE(fWeight = 1); | 45 SkDEBUGCODE(fWeight = 1); |
44 SkDEBUGCODE(fVerb = SkPath::kCubic_Verb); | 46 SkDEBUGCODE(fVerb = SkPath::kCubic_Verb); |
45 } | 47 } |
| 48 |
46 }; | 49 }; |
47 | 50 |
48 struct SkDCurve { | 51 struct SkDCurve { |
49 union { | 52 union { |
50 SkDLine fLine; | 53 SkDLine fLine; |
51 SkDQuad fQuad; | 54 SkDQuad fQuad; |
52 SkDConic fConic; | 55 SkDConic fConic; |
53 SkDCubic fCubic; | 56 SkDCubic fCubic; |
54 }; | 57 }; |
55 SkDEBUGCODE(SkPath::Verb fVerb); | 58 SkDEBUGCODE(SkPath::Verb fVerb); |
56 | 59 |
57 const SkDPoint& operator[](int n) const { | 60 const SkDPoint& operator[](int n) const { |
58 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); | 61 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
59 return fCubic[n]; | 62 return fCubic[n]; |
60 } | 63 } |
61 | 64 |
62 SkDPoint& operator[](int n) { | 65 SkDPoint& operator[](int n) { |
63 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); | 66 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb)); |
64 return fCubic[n]; | 67 return fCubic[n]; |
65 } | 68 } |
66 | 69 |
| 70 SkDPoint conicTop(const SkPoint curve[3], SkScalar curveWeight, |
| 71 double s, double e, double* topT); |
| 72 SkDPoint cubicTop(const SkPoint curve[4], SkScalar , double s, double e, dou
ble* topT); |
67 void dumpID(int ) const; | 73 void dumpID(int ) const; |
| 74 SkDPoint lineTop(const SkPoint[2], SkScalar , double , double , double* topT
); |
| 75 SkDPoint quadTop(const SkPoint curve[3], SkScalar , double s, double e, doub
le* topT); |
| 76 |
| 77 void setConicBounds(const SkPoint curve[3], SkScalar curveWeight, |
| 78 double s, double e, SkPathOpsBounds* ); |
| 79 void setCubicBounds(const SkPoint curve[4], SkScalar , |
| 80 double s, double e, SkPathOpsBounds* ); |
| 81 void setLineBounds(const SkPoint[2], SkScalar , double , double , SkPathOpsB
ounds* ); |
| 82 void setQuadBounds(const SkPoint curve[3], SkScalar , |
| 83 double s, double e, SkPathOpsBounds*); |
68 }; | 84 }; |
69 | 85 |
| 86 |
| 87 extern void (SkDCurve::* const SetBounds[])(const SkPoint curve[], SkScalar cWei
ght, |
| 88 double tStart, double tEnd, SkPathOpsBounds* ); |
| 89 |
| 90 extern SkDPoint (SkDCurve::* const Top[])(const SkPoint curve[], SkScalar cWeigh
t, |
| 91 double tStart, double tEnd, double* topT); |
| 92 |
70 static SkDPoint dline_xy_at_t(const SkPoint a[2], SkScalar , double t) { | 93 static SkDPoint dline_xy_at_t(const SkPoint a[2], SkScalar , double t) { |
71 SkDLine line; | 94 SkDLine line; |
72 line.set(a); | 95 line.set(a); |
73 return line.ptAtT(t); | 96 return line.ptAtT(t); |
74 } | 97 } |
75 | 98 |
76 static SkDPoint dquad_xy_at_t(const SkPoint a[3], SkScalar , double t) { | 99 static SkDPoint dquad_xy_at_t(const SkPoint a[3], SkScalar , double t) { |
77 SkDQuad quad; | 100 SkDQuad quad; |
78 quad.set(a); | 101 quad.set(a); |
79 return quad.ptAtT(t); | 102 return quad.ptAtT(t); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 195 } |
173 | 196 |
174 static SkVector (* const CurveSlopeAtT[])(const SkPoint[], SkScalar , double ) =
{ | 197 static SkVector (* const CurveSlopeAtT[])(const SkPoint[], SkScalar , double ) =
{ |
175 NULL, | 198 NULL, |
176 fline_dxdy_at_t, | 199 fline_dxdy_at_t, |
177 fquad_dxdy_at_t, | 200 fquad_dxdy_at_t, |
178 fconic_dxdy_at_t, | 201 fconic_dxdy_at_t, |
179 fcubic_dxdy_at_t | 202 fcubic_dxdy_at_t |
180 }; | 203 }; |
181 | 204 |
182 static SkPoint quad_top(const SkPoint a[3], SkScalar , double startT, double end
T, double* topT) { | |
183 SkDQuad quad; | |
184 quad.set(a); | |
185 SkDPoint topPt = quad.top(startT, endT, topT); | |
186 return topPt.asSkPoint(); | |
187 } | |
188 | |
189 static SkPoint conic_top(const SkPoint a[3], SkScalar weight, double startT, dou
ble endT, | |
190 double* topT) { | |
191 SkDConic conic; | |
192 conic.set(a, weight); | |
193 SkDPoint topPt = conic.top(startT, endT, topT); | |
194 return topPt.asSkPoint(); | |
195 } | |
196 | |
197 static SkPoint cubic_top(const SkPoint a[4], SkScalar , double startT, double en
dT, double* topT) { | |
198 SkDCubic cubic; | |
199 cubic.set(a); | |
200 SkDPoint topPt = cubic.top(startT, endT, topT); | |
201 return topPt.asSkPoint(); | |
202 } | |
203 | |
204 static SkPoint (* const CurveTop[])(const SkPoint[], SkScalar , double , double
, double* ) = { | |
205 NULL, | |
206 NULL, | |
207 quad_top, | |
208 conic_top, | |
209 cubic_top | |
210 }; | |
211 | |
212 static bool line_is_vertical(const SkPoint a[2], SkScalar , double startT, doubl
e endT) { | 205 static bool line_is_vertical(const SkPoint a[2], SkScalar , double startT, doubl
e endT) { |
213 SkDLine line; | 206 SkDLine line; |
214 line.set(a); | 207 line.set(a); |
215 SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) }; | 208 SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) }; |
216 return AlmostEqualUlps(dst[0].fX, dst[1].fX); | 209 return AlmostEqualUlps(dst[0].fX, dst[1].fX); |
217 } | 210 } |
218 | 211 |
219 static bool quad_is_vertical(const SkPoint a[3], SkScalar , double startT, doubl
e endT) { | 212 static bool quad_is_vertical(const SkPoint a[3], SkScalar , double startT, doubl
e endT) { |
220 SkDQuad quad; | 213 SkDQuad quad; |
221 quad.set(a); | 214 quad.set(a); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 static void (* const CurveIntersectRay[])(const SkPoint[] , SkScalar , const SkD
Line& , | 270 static void (* const CurveIntersectRay[])(const SkPoint[] , SkScalar , const SkD
Line& , |
278 SkIntersections* ) = { | 271 SkIntersections* ) = { |
279 NULL, | 272 NULL, |
280 line_intersect_ray, | 273 line_intersect_ray, |
281 quad_intersect_ray, | 274 quad_intersect_ray, |
282 conic_intersect_ray, | 275 conic_intersect_ray, |
283 cubic_intersect_ray | 276 cubic_intersect_ray |
284 }; | 277 }; |
285 | 278 |
286 #endif | 279 #endif |
OLD | NEW |