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 SkPathOpsCubic_DEFINED |
| 9 | #define SkPathOpsCubic_DEFINED |
| 10 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | #include "SkPathOpsPoint.h" |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 13 | #include "SkTArray.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 14 | |
| 15 | struct SkDCubicPair { |
| 16 | const SkDCubic& first() const { return (const SkDCubic&) pts[0]; } |
| 17 | const SkDCubic& second() const { return (const SkDCubic&) pts[3]; } |
| 18 | SkDPoint pts[7]; |
| 19 | }; |
| 20 | |
| 21 | struct SkDCubic { |
| 22 | SkDPoint fPts[4]; |
| 23 | |
| 24 | void set(const SkPoint pts[4]) { |
| 25 | fPts[0] = pts[0]; |
| 26 | fPts[1] = pts[1]; |
| 27 | fPts[2] = pts[2]; |
| 28 | fPts[3] = pts[3]; |
| 29 | } |
| 30 | |
| 31 | static const int gPrecisionUnit; |
| 32 | |
| 33 | const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 4); return fPts[n]; } |
| 34 | SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 4); return fPts[n]; } |
| 35 | |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 36 | void align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 37 | double calcPrecision() const; |
| 38 | SkDCubicPair chopAt(double t) const; |
| 39 | bool clockwise() const; |
| 40 | static void Coefficients(const double* cubic, double* A, double* B, double* C, double* D); |
| 41 | bool controlsContainedByEnds() const; |
| 42 | SkDVector dxdyAtT(double t) const; |
| 43 | bool endsAreExtremaInXOrY() const; |
| 44 | static int FindExtrema(double a, double b, double c, double d, double tValue[2]); |
| 45 | int findInflections(double tValues[]) const; |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 46 | |
| 47 | static int FindInflections(const SkPoint a[4], double tValues[]) { |
| 48 | SkDCubic cubic; |
| 49 | cubic.set(a); |
| 50 | return cubic.findInflections(tValues); |
| 51 | } |
| 52 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 53 | int findMaxCurvature(double tValues[]) const; |
| 54 | bool isLinear(int startIndex, int endIndex) const; |
| 55 | bool monotonicInY() const; |
caryclark@google.com | 4fdbb22 | 2013-07-23 15:27:41 +0000 | [diff] [blame] | 56 | SkDPoint ptAtT(double t) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 57 | static int RootsReal(double A, double B, double C, double D, double t[3]); |
| 58 | static int RootsValidT(const double A, const double B, const double C, double D, double s[3]); |
| 59 | bool serpentine() const; |
| 60 | SkDCubic subDivide(double t1, double t2) const; |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 61 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 62 | static SkDCubic SubDivide(const SkPoint a[4], double t1, double t2) { |
| 63 | SkDCubic cubic; |
| 64 | cubic.set(a); |
| 65 | return cubic.subDivide(t1, t2); |
| 66 | } |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 67 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 68 | void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, SkDPoint p[2]) const; |
| 69 | |
| 70 | static void SubDivide(const SkPoint pts[4], const SkDPoint& a, const SkDPoint& d, double t1, |
| 71 | double t2, SkDPoint p[2]) { |
| 72 | SkDCubic cubic; |
| 73 | cubic.set(pts); |
| 74 | cubic.subDivide(a, d, t1, t2, p); |
| 75 | } |
| 76 | |
| 77 | SkDPoint top(double startT, double endT) const; |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 78 | void toQuadraticTs(double precision, SkTArray<double, true>* ts) const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 79 | SkDQuad toQuad() const; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef SK_DEBUG |
| 82 | void dump(); |
| 83 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | #endif |