Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPathOpsConic.h
Go to the documentation of this file.
1/*
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
19
20class SkIntersections;
21class SkOpGlobalState;
22struct SkDCubic;
23struct SkDLine;
24struct SkDRect;
25
26struct SkDConic {
27 static const int kPointCount = 3;
28 static const int kPointLast = kPointCount - 1;
29 static const int kMaxIntersections = 4;
30
33
34 bool collapsed() const {
35 return fPts.collapsed();
36 }
37
38 bool controlsInside() const {
39 return fPts.controlsInside();
40 }
41
42 void debugInit() {
44 fWeight = 0;
45 }
46
47 void debugSet(const SkDPoint* pts, SkScalar weight);
48
49 SkDConic flip() const {
50 SkDConic result = {{{fPts[2], fPts[1], fPts[0]}
51 SkDEBUGPARAMS(fPts.fDebugGlobalState) }, fWeight};
52 return result;
53 }
54
55#ifdef SK_DEBUG
56 SkOpGlobalState* globalState() const { return fPts.globalState(); }
57#endif
58
59 static bool IsConic() { return true; }
60
61 const SkDConic& set(const SkPoint pts[kPointCount], SkScalar weight
64 fWeight = weight;
65 return *this;
66 }
67
68 const SkDPoint& operator[](int n) const { return fPts[n]; }
69 SkDPoint& operator[](int n) { return fPts[n]; }
70
71 static int AddValidTs(double s[], int realRoots, double* t) {
72 return SkDQuad::AddValidTs(s, realRoots, t);
73 }
74
75 void align(int endIndex, SkDPoint* dstPt) const {
76 fPts.align(endIndex, dstPt);
77 }
78
79 SkDVector dxdyAtT(double t) const;
80 static int FindExtrema(const double src[], SkScalar weight, double tValue[1]);
81
82 bool hullIntersects(const SkDQuad& quad, bool* isLinear) const {
83 return fPts.hullIntersects(quad, isLinear);
84 }
85
86 bool hullIntersects(const SkDConic& conic, bool* isLinear) const {
87 return fPts.hullIntersects(conic.fPts, isLinear);
88 }
89
90 bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const;
91
92 bool isLinear(int startIndex, int endIndex) const {
93 return fPts.isLinear(startIndex, endIndex);
94 }
95
96 static int maxIntersections() { return kMaxIntersections; }
97
98 bool monotonicInX() const {
99 return fPts.monotonicInX();
100 }
101
102 bool monotonicInY() const {
103 return fPts.monotonicInY();
104 }
105
106 void otherPts(int oddMan, const SkDPoint* endPt[2]) const {
107 fPts.otherPts(oddMan, endPt);
108 }
109
110 static int pointCount() { return kPointCount; }
111 static int pointLast() { return kPointLast; }
112 SkDPoint ptAtT(double t) const;
113
114 static int RootsReal(double A, double B, double C, double t[2]) {
115 return SkDQuad::RootsReal(A, B, C, t);
116 }
117
118 static int RootsValidT(const double A, const double B, const double C, double s[2]) {
119 return SkDQuad::RootsValidT(A, B, C, s);
120 }
121
122 SkDConic subDivide(double t1, double t2) const;
123 void subDivide(double t1, double t2, SkDConic* c) const { *c = this->subDivide(t1, t2); }
124
125 static SkDConic SubDivide(const SkPoint a[kPointCount], SkScalar weight, double t1, double t2) {
126 SkDConic conic;
127 conic.set(a, weight);
128 return conic.subDivide(t1, t2);
129 }
130
131 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2,
132 SkScalar* weight) const;
133
134 static SkDPoint SubDivide(const SkPoint pts[kPointCount], SkScalar weight,
135 const SkDPoint& a, const SkDPoint& c,
136 double t1, double t2, SkScalar* newWeight) {
137 SkDConic conic;
138 conic.set(pts, weight);
139 return conic.subDivide(a, c, t1, t2, newWeight);
140 }
141
142 // utilities callable by the user from the debugger when the implementation code is linked in
143 void dump() const;
144 void dumpID(int id) const;
145 void dumpInner() const;
146
147};
148
149class SkTConic : public SkTCurve {
150public:
152
154
156 : fConic(c) {
157 }
158
159 ~SkTConic() override {}
160
161 const SkDPoint& operator[](int n) const override { return fConic[n]; }
162 SkDPoint& operator[](int n) override { return fConic[n]; }
163
164 bool collapsed() const override { return fConic.collapsed(); }
165 bool controlsInside() const override { return fConic.controlsInside(); }
166 void debugInit() override { return fConic.debugInit(); }
167#if DEBUG_T_SECT
168 void dumpID(int id) const override { return fConic.dumpID(id); }
169#endif
170 SkDVector dxdyAtT(double t) const override { return fConic.dxdyAtT(t); }
171#ifdef SK_DEBUG
172 SkOpGlobalState* globalState() const override { return fConic.globalState(); }
173#endif
174 bool hullIntersects(const SkDQuad& quad, bool* isLinear) const override;
175
176 bool hullIntersects(const SkDConic& conic, bool* isLinear) const override {
177 return conic.hullIntersects(fConic, isLinear);
178 }
179
180 bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const override;
181
182 bool hullIntersects(const SkTCurve& curve, bool* isLinear) const override {
183 return curve.hullIntersects(fConic, isLinear);
184 }
185
186 int intersectRay(SkIntersections* i, const SkDLine& line) const override;
187 bool IsConic() const override { return true; }
188 SkTCurve* make(SkArenaAlloc& heap) const override { return heap.make<SkTConic>(); }
189
190 int maxIntersections() const override { return SkDConic::kMaxIntersections; }
191
192 void otherPts(int oddMan, const SkDPoint* endPt[2]) const override {
193 fConic.otherPts(oddMan, endPt);
194 }
195
196 int pointCount() const override { return SkDConic::kPointCount; }
197 int pointLast() const override { return SkDConic::kPointLast; }
198 SkDPoint ptAtT(double t) const override { return fConic.ptAtT(t); }
199 void setBounds(SkDRect* ) const override;
200
201 void subDivide(double t1, double t2, SkTCurve* curve) const override {
202 ((SkTConic*) curve)->fConic = fConic.subDivide(t1, t2);
203 }
204};
205
206#endif
#define SkDEBUGPARAMS(...)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
int intersectRay(SkIntersections *i, const SkDLine &line) const override
const SkDPoint & operator[](int n) const override
int pointLast() const override
SkDVector dxdyAtT(double t) const override
bool controlsInside() const override
bool IsConic() const override
SkDPoint ptAtT(double t) const override
bool hullIntersects(const SkTCurve &curve, bool *isLinear) const override
bool hullIntersects(const SkDQuad &quad, bool *isLinear) const override
void setBounds(SkDRect *) const override
void subDivide(double t1, double t2, SkTCurve *curve) const override
int maxIntersections() const override
~SkTConic() override
bool hullIntersects(const SkDConic &conic, bool *isLinear) const override
SkTConic(const SkDConic &c)
void otherPts(int oddMan, const SkDPoint *endPt[2]) const override
SkTCurve * make(SkArenaAlloc &heap) const override
int pointCount() const override
void debugInit() override
SkDPoint & operator[](int n) override
bool collapsed() const override
SkDConic fConic
virtual bool hullIntersects(const SkDQuad &, bool *isLinear) const =0
float SkScalar
Definition extension.cpp:12
struct MyStruct s
struct MyStruct a[10]
AtkStateType state
GAsyncResult * result
SkDPoint & operator[](int n)
SkDPoint ptAtT(double t) const
static int RootsValidT(const double A, const double B, const double C, double s[2])
void dump() const
static int pointLast()
const SkDConic & set(const SkPoint pts[kPointCount], SkScalar weight SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
bool hullIntersects(const SkDConic &conic, bool *isLinear) const
SkDQuad fPts
static SkDPoint SubDivide(const SkPoint pts[kPointCount], SkScalar weight, const SkDPoint &a, const SkDPoint &c, double t1, double t2, SkScalar *newWeight)
void otherPts(int oddMan, const SkDPoint *endPt[2]) const
bool controlsInside() const
static int FindExtrema(const double src[], SkScalar weight, double tValue[1])
static const int kPointCount
void debugInit()
void align(int endIndex, SkDPoint *dstPt) const
bool collapsed() const
void subDivide(double t1, double t2, SkDConic *c) const
static int maxIntersections()
static const int kMaxIntersections
SkDConic flip() const
static int AddValidTs(double s[], int realRoots, double *t)
static int pointCount()
static const int kPointLast
bool monotonicInY() const
static SkDConic SubDivide(const SkPoint a[kPointCount], SkScalar weight, double t1, double t2)
void dumpInner() const
void dumpID(int id) const
bool monotonicInX() const
SkDConic subDivide(double t1, double t2) const
bool isLinear(int startIndex, int endIndex) const
SkDVector dxdyAtT(double t) const
static int RootsReal(double A, double B, double C, double t[2])
void debugSet(const SkDPoint *pts, SkScalar weight)
bool hullIntersects(const SkDQuad &quad, bool *isLinear) const
static bool IsConic()
const SkDPoint & operator[](int n) const
SkScalar fWeight
static int RootsValidT(const double A, const double B, const double C, double s[2])
bool monotonicInY() const
void otherPts(int oddMan, const SkDPoint *endPt[2]) const
const SkDQuad & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
bool isLinear(int startIndex, int endIndex) const
static int RootsReal(double A, double B, double C, double t[2])
bool collapsed() const
void debugInit()
void align(int endIndex, SkDPoint *dstPt) const
bool controlsInside() const
static int AddValidTs(double s[], int realRoots, double *t)
bool monotonicInX() const
bool hullIntersects(const SkDQuad &, bool *isLinear) const