caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | |
| 13 | struct SkDQuadPair { |
| 14 | const SkDQuad& first() const { return (const SkDQuad&) pts[0]; } |
| 15 | const SkDQuad& second() const { return (const SkDQuad&) pts[2]; } |
| 16 | SkDPoint pts[5]; |
| 17 | }; |
| 18 | |
| 19 | struct SkDQuad { |
| 20 | SkDPoint fPts[3]; |
| 21 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 22 | SkDQuad flip() const { |
| 23 | SkDQuad result = {{fPts[2], fPts[1], fPts[0]}}; |
| 24 | return result; |
| 25 | } |
| 26 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 27 | void set(const SkPoint pts[3]) { |
| 28 | fPts[0] = pts[0]; |
| 29 | fPts[1] = pts[1]; |
| 30 | fPts[2] = pts[2]; |
| 31 | } |
| 32 | |
| 33 | const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 3); return fPts[n]; } |
| 34 | SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 3); return fPts[n]; } |
| 35 | |
| 36 | static int AddValidTs(double s[], int realRoots, double* t); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 37 | void align(int endIndex, SkDPoint* dstPt) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 38 | SkDQuadPair chopAt(double t) const; |
| 39 | SkDVector dxdyAtT(double t) const; |
| 40 | static int FindExtrema(double a, double b, double c, double tValue[1]); |
| 41 | bool isLinear(int startIndex, int endIndex) const; |
| 42 | bool monotonicInY() const; |
| 43 | double nearestT(const SkDPoint&) const; |
| 44 | bool pointInHull(const SkDPoint&) const; |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 45 | SkDPoint ptAtT(double t) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 46 | 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, double s[2]); |
| 48 | static void SetABC(const double* quad, double* a, double* b, double* c); |
| 49 | SkDQuad subDivide(double t1, double t2) const; |
| 50 | static SkDQuad SubDivide(const SkPoint a[3], double t1, double t2) { |
| 51 | SkDQuad quad; |
| 52 | quad.set(a); |
| 53 | return quad.subDivide(t1, t2); |
| 54 | } |
| 55 | SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2) const; |
| 56 | static SkDPoint SubDivide(const SkPoint pts[3], const SkDPoint& a, const SkDPoint& c, |
| 57 | double t1, double t2) { |
| 58 | SkDQuad quad; |
| 59 | quad.set(pts); |
| 60 | return quad.subDivide(a, c, t1, t2); |
| 61 | } |
| 62 | SkDCubic toCubic() const; |
| 63 | SkDPoint top(double startT, double endT) const; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 64 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 65 | // utilities callable by the user from the debugger when the implementation code is linked in |
| 66 | void dump() const; |
| 67 | void dumpComma(const char*) const; |
| 68 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | private: |
| 70 | // static double Tangent(const double* quadratic, double t); // uncalled |
| 71 | }; |
| 72 | |
| 73 | #endif |