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