Flutter Engine
The Flutter Engine
SkPathOpsQuad.h
Go to the documentation of this file.
1/*
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 SkPathOpsQuad_DEFINED
9#define SkPathOpsQuad_DEFINED
10
20
21class SkIntersections;
22class SkOpGlobalState;
23struct SkDConic;
24struct SkDLine;
25struct SkDQuad;
26struct SkDRect;
27
29 const SkDQuad& first() const { return (const SkDQuad&) pts[0]; }
30 const SkDQuad& second() const { return (const SkDQuad&) pts[2]; }
32};
33
34struct SkDQuad {
35 static const int kPointCount = 3;
36 static const int kPointLast = kPointCount - 1;
37 static const int kMaxIntersections = 4;
38
40
41 bool collapsed() const {
43 }
44
45 bool controlsInside() const {
46 SkDVector v01 = fPts[0] - fPts[1];
47 SkDVector v02 = fPts[0] - fPts[2];
48 SkDVector v12 = fPts[1] - fPts[2];
49 return v02.dot(v01) > 0 && v02.dot(v12) > 0;
50 }
51
52 void debugInit() {
53 sk_bzero(fPts, sizeof(fPts));
54 }
55
56 void debugSet(const SkDPoint* pts);
57
58 SkDQuad flip() const {
59 SkDQuad result = {{fPts[2], fPts[1], fPts[0]} SkDEBUGPARAMS(fDebugGlobalState) };
60 return result;
61 }
62
63 static bool IsConic() { return false; }
64
65 const SkDQuad& set(const SkPoint pts[kPointCount]
67 fPts[0] = pts[0];
68 fPts[1] = pts[1];
69 fPts[2] = pts[2];
70 SkDEBUGCODE(fDebugGlobalState = state);
71 return *this;
72 }
73
74 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; }
75 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; }
76
77 static int AddValidTs(double s[], int realRoots, double* t);
78 void align(int endIndex, SkDPoint* dstPt) const;
79 SkDQuadPair chopAt(double t) const;
80 SkDVector dxdyAtT(double t) const;
81 static int FindExtrema(const double src[], double tValue[1]);
82
83#ifdef SK_DEBUG
84 SkOpGlobalState* globalState() const { return fDebugGlobalState; }
85#endif
86
87 /**
88 * Return the number of valid roots (0 < root < 1) for this cubic intersecting the
89 * specified horizontal line.
90 */
91 int horizontalIntersect(double yIntercept, double roots[2]) const;
92
93 bool hullIntersects(const SkDQuad& , bool* isLinear) const;
94 bool hullIntersects(const SkDConic& , bool* isLinear) const;
95 bool hullIntersects(const SkDCubic& , bool* isLinear) const;
96 bool isLinear(int startIndex, int endIndex) const;
97 static int maxIntersections() { return kMaxIntersections; }
98 bool monotonicInX() const;
99 bool monotonicInY() const;
100 void otherPts(int oddMan, const SkDPoint* endPt[2]) const;
101 static int pointCount() { return kPointCount; }
102 static int pointLast() { return kPointLast; }
103 SkDPoint ptAtT(double t) const;
104 static int RootsReal(double A, double B, double C, double t[2]);
105 static int RootsValidT(const double A, const double B, const double C, double s[2]);
106 static void SetABC(const double* quad, double* a, double* b, double* c);
107 SkDQuad subDivide(double t1, double t2) const;
108 void subDivide(double t1, double t2, SkDQuad* quad) const { *quad = this->subDivide(t1, t2); }
109
110 static SkDQuad SubDivide(const SkPoint a[kPointCount], double t1, double t2) {
111 SkDQuad quad;
112 quad.set(a);
113 return quad.subDivide(t1, t2);
114 }
115 SkDPoint subDivide(const SkDPoint& a, const SkDPoint& c, double t1, double t2) const;
116 static SkDPoint SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a, const SkDPoint& c,
117 double t1, double t2) {
118 SkDQuad quad;
119 quad.set(pts);
120 return quad.subDivide(a, c, t1, t2);
121 }
122
123 /**
124 * Return the number of valid roots (0 < root < 1) for this cubic intersecting the
125 * specified vertical line.
126 */
127 int verticalIntersect(double xIntercept, double roots[2]) const;
128
129 SkDCubic debugToCubic() const;
130 // utilities callable by the user from the debugger when the implementation code is linked in
131 void dump() const;
132 void dumpID(int id) const;
133 void dumpInner() const;
134
135 SkDEBUGCODE(SkOpGlobalState* fDebugGlobalState;)
136};
137
138
139class SkTQuad : public SkTCurve {
140public:
142
144
145 SkTQuad(const SkDQuad& q)
146 : fQuad(q) {
147 }
148
149 ~SkTQuad() override {}
150
151 const SkDPoint& operator[](int n) const override { return fQuad[n]; }
152 SkDPoint& operator[](int n) override { return fQuad[n]; }
153
154 bool collapsed() const override { return fQuad.collapsed(); }
155 bool controlsInside() const override { return fQuad.controlsInside(); }
156 void debugInit() override { return fQuad.debugInit(); }
157#if DEBUG_T_SECT
158 void dumpID(int id) const override { return fQuad.dumpID(id); }
159#endif
160 SkDVector dxdyAtT(double t) const override { return fQuad.dxdyAtT(t); }
161#ifdef SK_DEBUG
162 SkOpGlobalState* globalState() const override { return fQuad.globalState(); }
163#endif
164
165 bool hullIntersects(const SkDQuad& quad, bool* isLinear) const override {
166 return quad.hullIntersects(fQuad, isLinear);
167 }
168
169 bool hullIntersects(const SkDConic& conic, bool* isLinear) const override;
170 bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const override;
171
172 bool hullIntersects(const SkTCurve& curve, bool* isLinear) const override {
173 return curve.hullIntersects(fQuad, isLinear);
174 }
175
176 int intersectRay(SkIntersections* i, const SkDLine& line) const override;
177 bool IsConic() const override { return false; }
178 SkTCurve* make(SkArenaAlloc& heap) const override { return heap.make<SkTQuad>(); }
179
180 int maxIntersections() const override { return SkDQuad::kMaxIntersections; }
181
182 void otherPts(int oddMan, const SkDPoint* endPt[2]) const override {
183 fQuad.otherPts(oddMan, endPt);
184 }
185
186 int pointCount() const override { return SkDQuad::kPointCount; }
187 int pointLast() const override { return SkDQuad::kPointLast; }
188 SkDPoint ptAtT(double t) const override { return fQuad.ptAtT(t); }
189 void setBounds(SkDRect* ) const override;
190
191 void subDivide(double t1, double t2, SkTCurve* curve) const override {
192 ((SkTQuad*) curve)->fQuad = fQuad.subDivide(t1, t2);
193 }
194};
195
196#endif
sk_bzero(glyphs, sizeof(glyphs))
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkDEBUGPARAMS(...)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
virtual bool hullIntersects(const SkDQuad &, bool *isLinear) const =0
bool IsConic() const override
int pointCount() const override
void debugInit() override
~SkTQuad() override
bool hullIntersects(const SkDQuad &quad, bool *isLinear) const override
bool collapsed() const override
bool hullIntersects(const SkTCurve &curve, bool *isLinear) const override
void setBounds(SkDRect *) const override
SkDPoint & operator[](int n) override
SkDVector dxdyAtT(double t) const override
int maxIntersections() const override
int intersectRay(SkIntersections *i, const SkDLine &line) const override
void subDivide(double t1, double t2, SkTCurve *curve) const override
SkTQuad(const SkDQuad &q)
SkTCurve * make(SkArenaAlloc &heap) const override
bool controlsInside() const override
SkDQuad fQuad
const SkDPoint & operator[](int n) const override
int pointLast() const override
SkDPoint ptAtT(double t) const override
void otherPts(int oddMan, const SkDPoint *endPt[2]) const override
static bool b
struct MyStruct s
struct MyStruct a[10]
AtkStateType state
GAsyncResult * result
AI float conic(float tolerance, const SkPoint pts[], float w, const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:287
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
bool approximatelyEqual(const SkDPoint &a) const
const SkDQuad & first() const
Definition: SkPathOpsQuad.h:29
SkDPoint pts[5]
Definition: SkPathOpsQuad.h:31
const SkDQuad & second() const
Definition: SkPathOpsQuad.h:30
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
void dumpID(int id) const
const SkDQuad & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
Definition: SkPathOpsQuad.h:65
bool isLinear(int startIndex, int endIndex) const
void dumpInner() const
static SkDQuad SubDivide(const SkPoint a[kPointCount], double t1, double t2)
static int RootsReal(double A, double B, double C, double t[2])
static int pointCount()
bool collapsed() const
Definition: SkPathOpsQuad.h:41
void debugSet(const SkDPoint *pts)
void debugInit()
Definition: SkPathOpsQuad.h:52
SkDQuadPair chopAt(double t) const
void dump() const
SkDQuad subDivide(double t1, double t2) const
void align(int endIndex, SkDPoint *dstPt) const
static const int kMaxIntersections
Definition: SkPathOpsQuad.h:37
SkDPoint & operator[](int n)
Definition: SkPathOpsQuad.h:75
bool controlsInside() const
Definition: SkPathOpsQuad.h:45
static int AddValidTs(double s[], int realRoots, double *t)
bool monotonicInX() const
SkDQuad flip() const
Definition: SkPathOpsQuad.h:58
bool hullIntersects(const SkDQuad &, bool *isLinear) const
static int FindExtrema(const double src[], double tValue[1])
SkDPoint ptAtT(double t) const
const SkDPoint & operator[](int n) const
Definition: SkPathOpsQuad.h:74
SkDPoint fPts[kPointCount]
Definition: SkPathOpsQuad.h:39
SkDVector dxdyAtT(double t) const
static SkDPoint SubDivide(const SkPoint pts[kPointCount], const SkDPoint &a, const SkDPoint &c, double t1, double t2)
int verticalIntersect(double xIntercept, double roots[2]) const
SkDCubic debugToCubic() const
static void SetABC(const double *quad, double *a, double *b, double *c)
static int pointLast()
static bool IsConic()
Definition: SkPathOpsQuad.h:63
void subDivide(double t1, double t2, SkDQuad *quad) const
int horizontalIntersect(double yIntercept, double roots[2]) const
static int maxIntersections()
Definition: SkPathOpsQuad.h:97
static const int kPointCount
Definition: SkPathOpsQuad.h:35
static const int kPointLast
Definition: SkPathOpsQuad.h:36
double dot(const SkDVector &a) const