| 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 SkPathOpsQuad_DEFINED | 8 #ifndef SkPathOpsQuad_DEFINED |
| 9 #define SkPathOpsQuad_DEFINED | 9 #define SkPathOpsQuad_DEFINED |
| 10 | 10 |
| 11 #include "SkPathOpsPoint.h" | 11 #include "SkPathOpsPoint.h" |
| 12 | 12 |
| 13 struct SkDQuadPair { | 13 struct SkDQuadPair { |
| 14 const SkDQuad& first() const { return (const SkDQuad&) pts[0]; } | 14 const SkDQuad& first() const { return (const SkDQuad&) pts[0]; } |
| 15 const SkDQuad& second() const { return (const SkDQuad&) pts[2]; } | 15 const SkDQuad& second() const { return (const SkDQuad&) pts[2]; } |
| 16 SkDPoint pts[5]; | 16 SkDPoint pts[5]; |
| 17 }; | 17 }; |
| 18 | 18 |
| 19 struct SkDQuad { | 19 struct SkDQuad { |
| 20 SkDPoint fPts[3]; | 20 static const int kPointCount = 3; |
| 21 static const int kPointLast = kPointCount - 1; |
| 22 static const int kMaxIntersections = 4; |
| 23 |
| 24 SkDPoint fPts[kPointCount]; |
| 25 |
| 26 bool collapsed() const { |
| 27 return fPts[0].approximatelyEqual(fPts[1]) && fPts[0].approximatelyEqual
(fPts[2]); |
| 28 } |
| 29 |
| 30 bool controlsInside() const { |
| 31 SkDVector v01 = fPts[0] - fPts[1]; |
| 32 SkDVector v02 = fPts[0] - fPts[2]; |
| 33 SkDVector v12 = fPts[1] - fPts[2]; |
| 34 return v02.dot(v01) > 0 && v02.dot(v12) > 0; |
| 35 } |
| 21 | 36 |
| 22 SkDQuad flip() const { | 37 SkDQuad flip() const { |
| 23 SkDQuad result = {{fPts[2], fPts[1], fPts[0]}}; | 38 SkDQuad result = {{fPts[2], fPts[1], fPts[0]}}; |
| 24 return result; | 39 return result; |
| 25 } | 40 } |
| 26 | 41 |
| 27 void set(const SkPoint pts[3]) { | 42 static bool IsCubic() { return false; } |
| 43 |
| 44 void set(const SkPoint pts[kPointCount]) { |
| 28 fPts[0] = pts[0]; | 45 fPts[0] = pts[0]; |
| 29 fPts[1] = pts[1]; | 46 fPts[1] = pts[1]; |
| 30 fPts[2] = pts[2]; | 47 fPts[2] = pts[2]; |
| 31 } | 48 } |
| 32 | 49 |
| 33 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 3); return
fPts[n]; } | 50 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < kPointCount
); return fPts[n]; } |
| 34 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 3); return fPts[n]; } | 51 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < kPointCount); return fP
ts[n]; } |
| 35 | 52 |
| 36 static int AddValidTs(double s[], int realRoots, double* t); | 53 static int AddValidTs(double s[], int realRoots, double* t); |
| 37 void align(int endIndex, SkDPoint* dstPt) const; | 54 void align(int endIndex, SkDPoint* dstPt) const; |
| 38 SkDQuadPair chopAt(double t) const; | 55 SkDQuadPair chopAt(double t) const; |
| 39 SkDVector dxdyAtT(double t) const; | 56 SkDVector dxdyAtT(double t) const; |
| 40 static int FindExtrema(double a, double b, double c, double tValue[1]); | 57 static int FindExtrema(double a, double b, double c, double tValue[1]); |
| 58 bool hullIntersects(const SkDQuad& , bool* isLinear) const; |
| 41 bool isLinear(int startIndex, int endIndex) const; | 59 bool isLinear(int startIndex, int endIndex) const; |
| 42 bool monotonicInY() const; | 60 bool monotonicInY() const; |
| 43 double nearestT(const SkDPoint&) const; | 61 double nearestT(const SkDPoint&) const; |
| 44 bool pointInHull(const SkDPoint&) const; | 62 void otherPts(int oddMan, const SkDPoint* endPt[2]) const; |
| 45 SkDPoint ptAtT(double t) const; | 63 SkDPoint ptAtT(double t) const; |
| 46 static int RootsReal(double A, double B, double C, double t[2]); | 64 static int RootsReal(double A, double B, double C, double t[2]); |
| 47 static int RootsValidT(const double A, const double B, const double C, doubl
e s[2]); | 65 static int RootsValidT(const double A, const double B, const double C, doubl
e s[2]); |
| 48 static void SetABC(const double* quad, double* a, double* b, double* c); | 66 static void SetABC(const double* quad, double* a, double* b, double* c); |
| 49 SkDQuad subDivide(double t1, double t2) const; | 67 SkDQuad subDivide(double t1, double t2) const; |
| 50 static SkDQuad SubDivide(const SkPoint a[3], double t1, double t2) { | 68 static SkDQuad SubDivide(const SkPoint a[kPointCount], double t1, double t2)
{ |
| 51 SkDQuad quad; | 69 SkDQuad quad; |
| 52 quad.set(a); | 70 quad.set(a); |
| 53 return quad.subDivide(t1, t2); | 71 return quad.subDivide(t1, t2); |
| 54 } | 72 } |
| 55 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t
2) const; | 73 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t
2) const; |
| 56 static SkDPoint SubDivide(const SkPoint pts[3], const SkDPoint& a, const SkD
Point& c, | 74 static SkDPoint SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a,
const SkDPoint& c, |
| 57 double t1, double t2) { | 75 double t1, double t2) { |
| 58 SkDQuad quad; | 76 SkDQuad quad; |
| 59 quad.set(pts); | 77 quad.set(pts); |
| 60 return quad.subDivide(a, c, t1, t2); | 78 return quad.subDivide(a, c, t1, t2); |
| 61 } | 79 } |
| 62 SkDCubic toCubic() const; | 80 SkDCubic toCubic() const; |
| 63 SkDPoint top(double startT, double endT) const; | 81 SkDPoint top(double startT, double endT) const; |
| 64 | 82 |
| 65 // utilities callable by the user from the debugger when the implementation
code is linked in | 83 // utilities callable by the user from the debugger when the implementation
code is linked in |
| 66 void dump() const; | 84 void dump() const; |
| 67 void dumpComma(const char*) const; | 85 void dumpID(int id) const; |
| 86 void dumpInner() const; |
| 68 | 87 |
| 69 private: | 88 private: |
| 70 // static double Tangent(const double* quadratic, double t); // uncalled | 89 // static double Tangent(const double* quadratic, double t); // uncalled |
| 71 }; | 90 }; |
| 72 | 91 |
| 73 #endif | 92 #endif |
| OLD | NEW |