michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkPathOpsCubic_DEFINED michael@0: #define SkPathOpsCubic_DEFINED michael@0: michael@0: #include "SkPath.h" michael@0: #include "SkPathOpsPoint.h" michael@0: #include "SkTArray.h" michael@0: michael@0: struct SkDCubicPair { michael@0: const SkDCubic& first() const { return (const SkDCubic&) pts[0]; } michael@0: const SkDCubic& second() const { return (const SkDCubic&) pts[3]; } michael@0: SkDPoint pts[7]; michael@0: }; michael@0: michael@0: struct SkDCubic { michael@0: SkDPoint fPts[4]; michael@0: michael@0: void set(const SkPoint pts[4]) { michael@0: fPts[0] = pts[0]; michael@0: fPts[1] = pts[1]; michael@0: fPts[2] = pts[2]; michael@0: fPts[3] = pts[3]; michael@0: } michael@0: michael@0: static const int gPrecisionUnit; michael@0: michael@0: const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 4); return fPts[n]; } michael@0: SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 4); return fPts[n]; } michael@0: michael@0: void align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const; michael@0: double calcPrecision() const; michael@0: SkDCubicPair chopAt(double t) const; michael@0: bool clockwise() const; michael@0: static void Coefficients(const double* cubic, double* A, double* B, double* C, double* D); michael@0: bool controlsContainedByEnds() const; michael@0: SkDVector dxdyAtT(double t) const; michael@0: bool endsAreExtremaInXOrY() const; michael@0: static int FindExtrema(double a, double b, double c, double d, double tValue[2]); michael@0: int findInflections(double tValues[]) const; michael@0: michael@0: static int FindInflections(const SkPoint a[4], double tValues[]) { michael@0: SkDCubic cubic; michael@0: cubic.set(a); michael@0: return cubic.findInflections(tValues); michael@0: } michael@0: michael@0: int findMaxCurvature(double tValues[]) const; michael@0: bool isLinear(int startIndex, int endIndex) const; michael@0: bool monotonicInY() const; michael@0: SkDPoint ptAtT(double t) const; michael@0: static int RootsReal(double A, double B, double C, double D, double t[3]); michael@0: static int RootsValidT(const double A, const double B, const double C, double D, double s[3]); michael@0: bool serpentine() const; michael@0: SkDCubic subDivide(double t1, double t2) const; michael@0: michael@0: static SkDCubic SubDivide(const SkPoint a[4], double t1, double t2) { michael@0: SkDCubic cubic; michael@0: cubic.set(a); michael@0: return cubic.subDivide(t1, t2); michael@0: } michael@0: michael@0: void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, SkDPoint p[2]) const; michael@0: michael@0: static void SubDivide(const SkPoint pts[4], const SkDPoint& a, const SkDPoint& d, double t1, michael@0: double t2, SkDPoint p[2]) { michael@0: SkDCubic cubic; michael@0: cubic.set(pts); michael@0: cubic.subDivide(a, d, t1, t2, p); michael@0: } michael@0: michael@0: SkDPoint top(double startT, double endT) const; michael@0: void toQuadraticTs(double precision, SkTArray* ts) const; michael@0: SkDQuad toQuad() const; michael@0: michael@0: #ifdef SK_DEBUG michael@0: void dump(); michael@0: #endif michael@0: }; michael@0: michael@0: #endif