blob: dce7032ddcd1d5f946c3cc0e9c736b049b41497e [file] [log] [blame]
caryclark1049f122015-04-20 08:31:59 -07001/*
2 * Copyright 2015 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 SkPathOpsConic_DEFINED
9#define SkPathOpsConic_DEFINED
10
11#include "SkPathOpsPoint.h"
12#include "SkPathOpsQuad.h"
13
14struct SkDConic {
15 static const int kPointCount = 3;
16 static const int kPointLast = kPointCount - 1;
17 static const int kMaxIntersections = 4;
18
19 SkDQuad fPts;
20 SkScalar fWeight;
21
22 bool collapsed() const {
23 return fPts.collapsed();
24 }
25
26 bool controlsInside() const {
27 return fPts.controlsInside();
28 }
29
30 void debugInit() {
31 fPts.debugInit();
32 }
33
34 SkDConic flip() const {
35 SkDConic result = {{{fPts[2], fPts[1], fPts[0]}}, fWeight};
36 return result;
37 }
38
39 static bool IsCubic() { return false; }
40
41 const SkDConic& set(const SkPoint pts[kPointCount], SkScalar weight) {
42 fPts.set(pts);
43 fWeight = weight;
44 return *this;
45 }
46
47 const SkDPoint& operator[](int n) const { return fPts[n]; }
48 SkDPoint& operator[](int n) { return fPts[n]; }
49
50 static int AddValidTs(double s[], int realRoots, double* t) {
51 return SkDQuad::AddValidTs(s, realRoots, t);
52 }
53
54 void align(int endIndex, SkDPoint* dstPt) const {
55 fPts.align(endIndex, dstPt);
56 }
57
58 SkDVector dxdyAtT(double t) const;
59 static int FindExtrema(const double src[], SkScalar weight, double tValue[1]);
60
61 bool hullIntersects(const SkDQuad& quad, bool* isLinear) const {
62 return fPts.hullIntersects(quad, isLinear);
63 }
64
65 bool hullIntersects(const SkDConic& conic, bool* isLinear) const {
66 return fPts.hullIntersects(conic.fPts, isLinear);
67 }
68
69 bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const;
70
71 bool isLinear(int startIndex, int endIndex) const {
72 return fPts.isLinear(startIndex, endIndex);
73 }
74
75 bool monotonicInY() const {
76 return fPts.monotonicInY();
77 }
78
79 void otherPts(int oddMan, const SkDPoint* endPt[2]) const {
80 fPts.otherPts(oddMan, endPt);
81 }
82
83 SkDPoint ptAtT(double t) const;
84
85 static int RootsReal(double A, double B, double C, double t[2]) {
86 return SkDQuad::RootsReal(A, B, C, t);
87 }
88
89 static int RootsValidT(const double A, const double B, const double C, double s[2]) {
90 return SkDQuad::RootsValidT(A, B, C, s);
91 }
92
93 SkDConic subDivide(double t1, double t2) const;
94
95 static SkDConic SubDivide(const SkPoint a[kPointCount], SkScalar weight, double t1, double t2) {
96 SkDConic conic;
97 conic.set(a, weight);
98 return conic.subDivide(t1, t2);
99 }
100
101 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2,
102 SkScalar* weight) const;
103
104 static SkDPoint SubDivide(const SkPoint pts[kPointCount], SkScalar weight,
105 const SkDPoint& a, const SkDPoint& c,
106 double t1, double t2, SkScalar* newWeight) {
107 SkDConic conic;
108 conic.set(pts, weight);
109 return conic.subDivide(a, c, t1, t2, newWeight);
110 }
111
112 SkDPoint top(double startT, double endT) const;
113
114 // utilities callable by the user from the debugger when the implementation code is linked in
115 void dump() const;
116 void dumpID(int id) const;
117 void dumpInner() const;
118};
119
120
121#endif