blob: 1037cae4f759f94e5c01a3bd3784a44c16ceb3d5 [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
caryclark@google.comcffbcc32013-06-04 17:59:42 +000011#include "SkPath.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000012#include "SkPathOpsPoint.h"
caryclark@google.comd892bd82013-06-17 14:10:36 +000013#include "SkTArray.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000014
15struct 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
21struct SkDCubic {
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000022 enum SearchAxis {
23 kXAxis,
24 kYAxis
25 };
caryclark@google.com07393ca2013-04-08 11:47:37 +000026
27 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < 4); return fPts[n]; }
28 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < 4); return fPts[n]; }
29
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +000030 void align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const;
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000031 double binarySearch(double min, double max, double axisIntercept, SearchAxis xAxis) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000032 double calcPrecision() const;
33 SkDCubicPair chopAt(double t) const;
34 bool clockwise() const;
35 static void Coefficients(const double* cubic, double* A, double* B, double* C, double* D);
36 bool controlsContainedByEnds() const;
37 SkDVector dxdyAtT(double t) const;
38 bool endsAreExtremaInXOrY() const;
39 static int FindExtrema(double a, double b, double c, double d, double tValue[2]);
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000040 int findInflections(double tValues[2]) const;
caryclark@google.comb3f09212013-04-17 15:49:16 +000041
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000042 static int FindInflections(const SkPoint a[4], double tValues[2]) {
caryclark@google.comb3f09212013-04-17 15:49:16 +000043 SkDCubic cubic;
44 cubic.set(a);
45 return cubic.findInflections(tValues);
46 }
47
caryclark@google.com07393ca2013-04-08 11:47:37 +000048 int findMaxCurvature(double tValues[]) const;
49 bool isLinear(int startIndex, int endIndex) const;
50 bool monotonicInY() const;
caryclark@google.com4fdbb222013-07-23 15:27:41 +000051 SkDPoint ptAtT(double t) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000052 static int RootsReal(double A, double B, double C, double D, double t[3]);
53 static int RootsValidT(const double A, const double B, const double C, double D, double s[3]);
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000054
55 int searchRoots(double extremes[6], int extrema, double axisIntercept,
56 SearchAxis xAxis, double* validRoots) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000057 bool serpentine() const;
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000058
59 void set(const SkPoint pts[4]) {
60 fPts[0] = pts[0];
61 fPts[1] = pts[1];
62 fPts[2] = pts[2];
63 fPts[3] = pts[3];
64 }
65
caryclark@google.com07393ca2013-04-08 11:47:37 +000066 SkDCubic subDivide(double t1, double t2) const;
caryclark@google.comb3f09212013-04-17 15:49:16 +000067
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 static SkDCubic SubDivide(const SkPoint a[4], double t1, double t2) {
69 SkDCubic cubic;
70 cubic.set(a);
71 return cubic.subDivide(t1, t2);
72 }
caryclark@google.comb3f09212013-04-17 15:49:16 +000073
caryclark@google.com07393ca2013-04-08 11:47:37 +000074 void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, SkDPoint p[2]) const;
75
76 static void SubDivide(const SkPoint pts[4], const SkDPoint& a, const SkDPoint& d, double t1,
77 double t2, SkDPoint p[2]) {
78 SkDCubic cubic;
79 cubic.set(pts);
80 cubic.subDivide(a, d, t1, t2, p);
81 }
82
83 SkDPoint top(double startT, double endT) const;
caryclark@google.comd892bd82013-06-17 14:10:36 +000084 void toQuadraticTs(double precision, SkTArray<double, true>* ts) const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000085 SkDQuad toQuad() const;
caryclark@google.com570863f2013-09-16 15:55:01 +000086
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000087 // utilities callable by the user from the debugger when the implementation code is linked in
88 void dump() const;
89 void dumpNumber() const;
commit-bot@chromium.org2db7fe72014-05-07 15:31:40 +000090
91 static const int gPrecisionUnit;
92
93 SkDPoint fPts[4];
caryclark@google.com07393ca2013-04-08 11:47:37 +000094};
95
96#endif