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 SkIntersections_DEFINE | 7 #ifndef SkIntersections_DEFINE |
8 #define SkIntersections_DEFINE | 8 #define SkIntersections_DEFINE |
9 | 9 |
10 #include "SkPathOpsCubic.h" | 10 #include "SkPathOpsCubic.h" |
11 #include "SkPathOpsLine.h" | 11 #include "SkPathOpsLine.h" |
12 #include "SkPathOpsPoint.h" | 12 #include "SkPathOpsPoint.h" |
13 #include "SkPathOpsQuad.h" | 13 #include "SkPathOpsQuad.h" |
14 | 14 |
15 class SkIntersections { | 15 class SkIntersections { |
16 public: | 16 public: |
17 SkIntersections() | 17 SkIntersections() |
18 : fSwap(0) | 18 : fSwap(0) |
| 19 , fFlatMeasure(false) |
19 #ifdef SK_DEBUG | 20 #ifdef SK_DEBUG |
20 , fDepth(0) | 21 , fDepth(0) |
21 #endif | 22 #endif |
22 { | 23 { |
23 sk_bzero(fPt, sizeof(fPt)); | 24 sk_bzero(fPt, sizeof(fPt)); |
24 sk_bzero(fPt2, sizeof(fPt2)); | 25 sk_bzero(fPt2, sizeof(fPt2)); |
25 sk_bzero(fT, sizeof(fT)); | 26 sk_bzero(fT, sizeof(fT)); |
26 sk_bzero(fIsCoincident, sizeof(fIsCoincident)); | 27 sk_bzero(fIsCoincident, sizeof(fIsCoincident)); |
27 sk_bzero(fNearlySame, sizeof(fNearlySame)); | 28 sk_bzero(fNearlySame, sizeof(fNearlySame)); |
28 reset(); | 29 reset(); |
29 fMax = 0; // require that the caller set the max | 30 fMax = 0; // require that the caller set the max |
30 } | 31 } |
31 | 32 |
32 class TArray { | 33 class TArray { |
33 public: | 34 public: |
34 explicit TArray(const double ts[9]) : fTArray(ts) {} | 35 explicit TArray(const double ts[9]) : fTArray(ts) {} |
35 double operator[](int n) const { | 36 double operator[](int n) const { |
36 return fTArray[n]; | 37 return fTArray[n]; |
37 } | 38 } |
38 const double* fTArray; | 39 const double* fTArray; |
39 }; | 40 }; |
40 TArray operator[](int n) const { return TArray(fT[n]); } | 41 TArray operator[](int n) const { return TArray(fT[n]); } |
41 | 42 |
| 43 void allowFlatMeasure(bool flatAllowed) { |
| 44 fFlatMeasure = flatAllowed; |
| 45 } |
| 46 |
42 void allowNear(bool nearAllowed) { | 47 void allowNear(bool nearAllowed) { |
43 fAllowNear = nearAllowed; | 48 fAllowNear = nearAllowed; |
44 } | 49 } |
45 | 50 |
46 int cubic(const SkPoint a[4]) { | 51 int cubic(const SkPoint a[4]) { |
47 SkDCubic cubic; | 52 SkDCubic cubic; |
48 cubic.set(a); | 53 cubic.set(a); |
49 fMax = 1; // self intersect | 54 fMax = 1; // self intersect |
50 return intersect(cubic); | 55 return intersect(cubic); |
51 } | 56 } |
(...skipping 29 matching lines...) Expand all Loading... |
81 line.set(b); | 86 line.set(b); |
82 fMax = 3; | 87 fMax = 3; |
83 return intersect(cubic, line); | 88 return intersect(cubic, line); |
84 } | 89 } |
85 | 90 |
86 int cubicQuad(const SkPoint a[4], const SkPoint b[3]) { | 91 int cubicQuad(const SkPoint a[4], const SkPoint b[3]) { |
87 SkDCubic cubic; | 92 SkDCubic cubic; |
88 cubic.set(a); | 93 cubic.set(a); |
89 SkDQuad quad; | 94 SkDQuad quad; |
90 quad.set(b); | 95 quad.set(b); |
91 fMax = 6; | 96 fMax = 7; |
92 return intersect(cubic, quad); | 97 return intersect(cubic, quad); |
93 } | 98 } |
94 | 99 |
| 100 bool flatMeasure() const { |
| 101 return fFlatMeasure; |
| 102 } |
| 103 |
95 bool hasT(double t) const { | 104 bool hasT(double t) const { |
96 SkASSERT(t == 0 || t == 1); | 105 SkASSERT(t == 0 || t == 1); |
97 return fUsed > 0 && (t == 0 ? fT[0][0] == 0 : fT[0][fUsed - 1] == 1); | 106 return fUsed > 0 && (t == 0 ? fT[0][0] == 0 : fT[0][fUsed - 1] == 1); |
98 } | 107 } |
99 | 108 |
100 int insertSwap(double one, double two, const SkDPoint& pt) { | 109 int insertSwap(double one, double two, const SkDPoint& pt) { |
101 if (fSwap) { | 110 if (fSwap) { |
102 return insert(two, one, pt); | 111 return insert(two, one, pt); |
103 } else { | 112 } else { |
104 return insert(one, two, pt); | 113 return insert(one, two, pt); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 203 |
195 void swap() { | 204 void swap() { |
196 fSwap ^= true; | 205 fSwap ^= true; |
197 } | 206 } |
198 | 207 |
199 void swapPts(); | 208 void swapPts(); |
200 | 209 |
201 bool swapped() const { | 210 bool swapped() const { |
202 return fSwap; | 211 return fSwap; |
203 } | 212 } |
204 | 213 |
205 int used() const { | 214 int used() const { |
206 return fUsed; | 215 return fUsed; |
207 } | 216 } |
208 | 217 |
209 void downDepth() { | 218 void downDepth() { |
210 SkASSERT(--fDepth >= 0); | 219 SkASSERT(--fDepth >= 0); |
211 } | 220 } |
212 | 221 |
213 void upDepth() { | 222 void upDepth() { |
214 SkASSERT(++fDepth < 16); | 223 SkASSERT(++fDepth < 16); |
215 } | 224 } |
216 | 225 |
| 226 void alignQuadPts(const SkPoint a[3], const SkPoint b[3]); |
217 void append(const SkIntersections& ); | 227 void append(const SkIntersections& ); |
218 void cleanUpCoincidence(); | 228 int cleanUpCoincidence(); |
219 int coincidentUsed() const; | 229 int coincidentUsed() const; |
220 void cubicInsert(double one, double two, const SkDPoint& pt, const SkDCubic&
c1, | 230 void cubicInsert(double one, double two, const SkDPoint& pt, const SkDCubic&
c1, |
221 const SkDCubic& c2); | 231 const SkDCubic& c2); |
222 int cubicRay(const SkPoint pts[4], const SkDLine& line); | 232 int cubicRay(const SkPoint pts[4], const SkDLine& line); |
223 void flip(); | 233 void flip(); |
224 int horizontal(const SkDLine&, double y); | 234 int horizontal(const SkDLine&, double y); |
225 int horizontal(const SkDLine&, double left, double right, double y, bool fli
pped); | 235 int horizontal(const SkDLine&, double left, double right, double y, bool fli
pped); |
226 int horizontal(const SkDQuad&, double left, double right, double y, bool fli
pped); | 236 int horizontal(const SkDQuad&, double left, double right, double y, bool fli
pped); |
227 int horizontal(const SkDQuad&, double left, double right, double y, double t
Range[2]); | 237 int horizontal(const SkDQuad&, double left, double right, double y, double t
Range[2]); |
228 int horizontal(const SkDCubic&, double y, double tRange[3]); | 238 int horizontal(const SkDCubic&, double y, double tRange[3]); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 285 |
276 SkDPoint fPt[9]; // FIXME: since scans store points as SkPoint, this should
also | 286 SkDPoint fPt[9]; // FIXME: since scans store points as SkPoint, this should
also |
277 SkDPoint fPt2[9]; // used by nearly same to store alternate intersection po
int | 287 SkDPoint fPt2[9]; // used by nearly same to store alternate intersection po
int |
278 double fT[2][9]; | 288 double fT[2][9]; |
279 uint16_t fIsCoincident[2]; // bit set for each curve's coincident T | 289 uint16_t fIsCoincident[2]; // bit set for each curve's coincident T |
280 bool fNearlySame[2]; // true if end points nearly match | 290 bool fNearlySame[2]; // true if end points nearly match |
281 unsigned char fUsed; | 291 unsigned char fUsed; |
282 unsigned char fMax; | 292 unsigned char fMax; |
283 bool fAllowNear; | 293 bool fAllowNear; |
284 bool fSwap; | 294 bool fSwap; |
| 295 bool fFlatMeasure; // backwards-compatibility when cubics uses quad interse
ction |
285 #ifdef SK_DEBUG | 296 #ifdef SK_DEBUG |
286 int fDepth; | 297 int fDepth; |
287 #endif | 298 #endif |
288 }; | 299 }; |
289 | 300 |
290 extern int (SkIntersections::* const CurveRay[])(const SkPoint[], const SkDLine&
); | 301 extern int (SkIntersections::* const CurveRay[])(const SkPoint[], const SkDLine&
); |
291 extern int (SkIntersections::* const CurveVertical[])(const SkPoint[], SkScalar
top, SkScalar bottom, | 302 extern int (SkIntersections::* const CurveVertical[])(const SkPoint[], SkScalar
top, SkScalar bottom, |
292 SkScalar x, bool flipped); | 303 SkScalar x, bool flipped); |
293 | 304 |
294 #endif | 305 #endif |
OLD | NEW |