SkPathOpsQuad.h revision 03b03cad01628146bbb8d4f33c073bd0c77ee558
1/* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkPathOpsQuad_DEFINED 9#define SkPathOpsQuad_DEFINED 10 11#include "SkPathOpsPoint.h" 12 13struct SkOpCurve; 14 15struct SkDQuadPair { 16 const SkDQuad& first() const { return (const SkDQuad&) pts[0]; } 17 const SkDQuad& second() const { return (const SkDQuad&) pts[2]; } 18 SkDPoint pts[5]; 19}; 20 21struct SkDQuad { 22 static const int kPointCount = 3; 23 static const int kPointLast = kPointCount - 1; 24 static const int kMaxIntersections = 4; 25 26 SkDPoint fPts[kPointCount]; 27 28 bool collapsed() const { 29 return fPts[0].approximatelyEqual(fPts[1]) && fPts[0].approximatelyEqual(fPts[2]); 30 } 31 32 bool controlsInside() const { 33 SkDVector v01 = fPts[0] - fPts[1]; 34 SkDVector v02 = fPts[0] - fPts[2]; 35 SkDVector v12 = fPts[1] - fPts[2]; 36 return v02.dot(v01) > 0 && v02.dot(v12) > 0; 37 } 38 39 void debugInit() { 40 sk_bzero(fPts, sizeof(fPts)); 41 } 42 43 SkDQuad flip() const { 44 SkDQuad result = {{fPts[2], fPts[1], fPts[0]}}; 45 return result; 46 } 47 48 static bool IsCubic() { return false; } 49 50 const SkDQuad& set(const SkPoint pts[kPointCount]) { 51 fPts[0] = pts[0]; 52 fPts[1] = pts[1]; 53 fPts[2] = pts[2]; 54 return *this; 55 } 56 57 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; } 58 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; } 59 60 static int AddValidTs(double s[], int realRoots, double* t); 61 void align(int endIndex, SkDPoint* dstPt) const; 62 SkDQuadPair chopAt(double t) const; 63 static bool Clockwise(const SkOpCurve& edge, bool* swap); 64 SkDVector dxdyAtT(double t) const; 65 static int FindExtrema(double a, double b, double c, double tValue[1]); 66 bool hullIntersects(const SkDQuad& , bool* isLinear) const; 67 bool hullIntersects(const SkDConic& , bool* isLinear) const; 68 bool hullIntersects(const SkDCubic& , bool* isLinear) const; 69 bool isLinear(int startIndex, int endIndex) const; 70 bool monotonicInY() const; 71 double nearestT(const SkDPoint&) const; 72 void otherPts(int oddMan, const SkDPoint* endPt[2]) const; 73 SkDPoint ptAtT(double t) const; 74 static int RootsReal(double A, double B, double C, double t[2]); 75 static int RootsValidT(const double A, const double B, const double C, double s[2]); 76 static void SetABC(const double* quad, double* a, double* b, double* c); 77 SkDQuad subDivide(double t1, double t2) const; 78 static SkDQuad SubDivide(const SkPoint a[kPointCount], double t1, double t2) { 79 SkDQuad quad; 80 quad.set(a); 81 return quad.subDivide(t1, t2); 82 } 83 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2) const; 84 static SkDPoint SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a, const SkDPoint& c, 85 double t1, double t2) { 86 SkDQuad quad; 87 quad.set(pts); 88 return quad.subDivide(a, c, t1, t2); 89 } 90 SkDConic toConic() const; 91 SkDCubic toCubic() const; 92 SkDPoint top(double startT, double endT, double* topT) const; 93 94 // utilities callable by the user from the debugger when the implementation code is linked in 95 void dump() const; 96 void dumpID(int id) const; 97 void dumpInner() const; 98 99private: 100// static double Tangent(const double* quadratic, double t); // uncalled 101}; 102 103#endif 104