blob: 37492ddbbaf76f6c40d86d59fd7bcbba6942c82a [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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
11#include "SkPathOpsPoint.h"
12#include "SkTDArray.h"
13
14struct SkDCubicPair {
15 const SkDCubic& first() const { return (const SkDCubic&) pts[0]; }
16 const SkDCubic& second() const { return (const SkDCubic&) pts[3]; }
17 SkDPoint pts[7];
18};
19
20struct SkDCubic {
21 SkDPoint fPts[4];
22
23 void set(const SkPoint pts[4]) {
24 fPts[0] = pts[0];
25 fPts[1] = pts[1];
26 fPts[2] = pts[2];
27 fPts[3] = pts[3];
28 }
29
30 static const int gPrecisionUnit;
31
32 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 4); return fPts[n]; }
33 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 4); return fPts[n]; }
34
35 double calcPrecision() const;
36 SkDCubicPair chopAt(double t) const;
37 bool clockwise() const;
38 static void Coefficients(const double* cubic, double* A, double* B, double* C, double* D);
39 bool controlsContainedByEnds() const;
40 SkDVector dxdyAtT(double t) const;
41 bool endsAreExtremaInXOrY() const;
42 static int FindExtrema(double a, double b, double c, double d, double tValue[2]);
43 int findInflections(double tValues[]) const;
caryclark@google.comb3f09212013-04-17 15:49:16 +000044
45 static int FindInflections(const SkPoint a[4], double tValues[]) {
46 SkDCubic cubic;
47 cubic.set(a);
48 return cubic.findInflections(tValues);
49 }
50
caryclark@google.com07393ca2013-04-08 11:47:37 +000051 int findMaxCurvature(double tValues[]) const;
52 bool isLinear(int startIndex, int endIndex) const;
53 bool monotonicInY() const;
54 static int RootsReal(double A, double B, double C, double D, double t[3]);
55 static int RootsValidT(const double A, const double B, const double C, double D, double s[3]);
56 bool serpentine() const;
57 SkDCubic subDivide(double t1, double t2) const;
caryclark@google.comb3f09212013-04-17 15:49:16 +000058
caryclark@google.com07393ca2013-04-08 11:47:37 +000059 static SkDCubic SubDivide(const SkPoint a[4], double t1, double t2) {
60 SkDCubic cubic;
61 cubic.set(a);
62 return cubic.subDivide(t1, t2);
63 }
caryclark@google.comb3f09212013-04-17 15:49:16 +000064
caryclark@google.com07393ca2013-04-08 11:47:37 +000065 void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, SkDPoint p[2]) const;
66
67 static void SubDivide(const SkPoint pts[4], const SkDPoint& a, const SkDPoint& d, double t1,
68 double t2, SkDPoint p[2]) {
69 SkDCubic cubic;
70 cubic.set(pts);
71 cubic.subDivide(a, d, t1, t2, p);
72 }
73
74 SkDPoint top(double startT, double endT) const;
75 void toQuadraticTs(double precision, SkTDArray<double>* ts) const;
76 SkDQuad toQuad() const;
77 SkDPoint xyAtT(double t) const;
78};
79
80#endif