Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPathOpsCubic.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 SkPathOpsCubic_DEFINED
9#define SkPathOpsCubic_DEFINED
10
20
21class SkIntersections;
22class SkOpGlobalState;
23struct SkDConic;
24struct SkDCubicPair;
25struct SkDLine;
26struct SkDQuad;
27struct SkDRect;
28
29struct SkDCubic {
30 static const int kPointCount = 4;
31 static const int kPointLast = kPointCount - 1;
32 static const int kMaxIntersections = 9;
33
38
39 bool collapsed() const {
42 }
43
44 bool controlsInside() const {
45 SkDVector v01 = fPts[0] - fPts[1];
46 SkDVector v02 = fPts[0] - fPts[2];
47 SkDVector v03 = fPts[0] - fPts[3];
48 SkDVector v13 = fPts[1] - fPts[3];
49 SkDVector v23 = fPts[2] - fPts[3];
50 return v03.dot(v01) > 0 && v03.dot(v02) > 0 && v03.dot(v13) > 0 && v03.dot(v23) > 0;
51 }
52
53 static bool IsConic() { return false; }
54
55 const SkDPoint& operator[](int n) const { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; }
56 SkDPoint& operator[](int n) { SkASSERT(n >= 0 && n < kPointCount); return fPts[n]; }
57
58 void align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const;
59 double binarySearch(double min, double max, double axisIntercept, SearchAxis xAxis) const;
60 double calcPrecision() const;
61 SkDCubicPair chopAt(double t) const;
62 static void Coefficients(const double* cubic, double* A, double* B, double* C, double* D);
63 static int ComplexBreak(const SkPoint pts[4], SkScalar* t);
64 int convexHull(char order[kPointCount]) const;
65
66 void debugInit() {
67 sk_bzero(fPts, sizeof(fPts));
68 }
69
70 void debugSet(const SkDPoint* pts);
71
72 void dump() const; // callable from the debugger when the implementation code is linked in
73 void dumpID(int id) const;
74 void dumpInner() const;
75 SkDVector dxdyAtT(double t) const;
76 bool endsAreExtremaInXOrY() const;
77 static int FindExtrema(const double src[], double tValue[2]);
78 int findInflections(double tValues[2]) const;
79
80 static int FindInflections(const SkPoint a[kPointCount], double tValues[2]) {
81 SkDCubic cubic;
82 return cubic.set(a).findInflections(tValues);
83 }
84
85 int findMaxCurvature(double tValues[]) const;
86
87#ifdef SK_DEBUG
88 SkOpGlobalState* globalState() const { return fDebugGlobalState; }
89#endif
90
91 bool hullIntersects(const SkDCubic& c2, bool* isLinear) const;
92 bool hullIntersects(const SkDConic& c, bool* isLinear) const;
93 bool hullIntersects(const SkDQuad& c2, bool* isLinear) const;
94 bool hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear) const;
95 bool isLinear(int startIndex, int endIndex) const;
96 static int maxIntersections() { return kMaxIntersections; }
97 bool monotonicInX() const;
98 bool monotonicInY() const;
99 void otherPts(int index, const SkDPoint* o1Pts[kPointCount - 1]) const;
100 static int pointCount() { return kPointCount; }
101 static int pointLast() { return kPointLast; }
102 SkDPoint ptAtT(double t) const;
103 static int RootsReal(double A, double B, double C, double D, double t[3]);
104 static int RootsValidT(const double A, const double B, const double C, double D, double s[3]);
105
106 int searchRoots(double extremes[6], int extrema, double axisIntercept,
107 SearchAxis xAxis, double* validRoots) const;
108
109 bool toFloatPoints(SkPoint* ) const;
110 /**
111 * Return the number of valid roots (0 < root < 1) for this cubic intersecting the
112 * specified horizontal line.
113 */
114 int horizontalIntersect(double yIntercept, double roots[3]) const;
115 /**
116 * Return the number of valid roots (0 < root < 1) for this cubic intersecting the
117 * specified vertical line.
118 */
119 int verticalIntersect(double xIntercept, double roots[3]) const;
120
121// add debug only global pointer so asserts can be skipped by fuzzers
122 const SkDCubic& set(const SkPoint pts[kPointCount]
123 SkDEBUGPARAMS(SkOpGlobalState* state = nullptr)) {
124 fPts[0] = pts[0];
125 fPts[1] = pts[1];
126 fPts[2] = pts[2];
127 fPts[3] = pts[3];
128 SkDEBUGCODE(fDebugGlobalState = state);
129 return *this;
130 }
131
132 SkDCubic subDivide(double t1, double t2) const;
133 void subDivide(double t1, double t2, SkDCubic* c) const { *c = this->subDivide(t1, t2); }
134
135 static SkDCubic SubDivide(const SkPoint a[kPointCount], double t1, double t2) {
136 SkDCubic cubic;
137 return cubic.set(a).subDivide(t1, t2);
138 }
139
140 void subDivide(const SkDPoint& a, const SkDPoint& d, double t1, double t2, SkDPoint p[2]) const;
141
142 static void SubDivide(const SkPoint pts[kPointCount], const SkDPoint& a, const SkDPoint& d, double t1,
143 double t2, SkDPoint p[2]) {
144 SkDCubic cubic;
145 cubic.set(pts).subDivide(a, d, t1, t2, p);
146 }
147
148 double top(const SkDCubic& dCurve, double startT, double endT, SkDPoint*topPt) const;
149 SkDQuad toQuad() const;
150
151 static const int gPrecisionUnit;
153 SkDEBUGCODE(SkOpGlobalState* fDebugGlobalState;)
154};
155
156/* Given the set [0, 1, 2, 3], and two of the four members, compute an XOR mask
157 that computes the other two. Note that:
158
159 one ^ two == 3 for (0, 3), (1, 2)
160 one ^ two < 3 for (0, 1), (0, 2), (1, 3), (2, 3)
161 3 - (one ^ two) is either 0, 1, or 2
162 1 >> (3 - (one ^ two)) is either 0 or 1
163thus:
164 returned == 2 for (0, 3), (1, 2)
165 returned == 3 for (0, 1), (0, 2), (1, 3), (2, 3)
166given that:
167 (0, 3) ^ 2 -> (2, 1) (1, 2) ^ 2 -> (3, 0)
168 (0, 1) ^ 3 -> (3, 2) (0, 2) ^ 3 -> (3, 1) (1, 3) ^ 3 -> (2, 0) (2, 3) ^ 3 -> (1, 0)
169*/
170inline int other_two(int one, int two) {
171 return 1 >> (3 - (one ^ two)) ^ 3;
172}
173
175 SkDCubic first() const {
176#ifdef SK_DEBUG
178 result.debugSet(&pts[0]);
179 return result;
180#else
181 return (const SkDCubic&) pts[0];
182#endif
183 }
184 SkDCubic second() const {
185#ifdef SK_DEBUG
187 result.debugSet(&pts[3]);
188 return result;
189#else
190 return (const SkDCubic&) pts[3];
191#endif
192 }
194};
195
196class SkTCubic : public SkTCurve {
197public:
199
201
203 : fCubic(c) {
204 }
205
206 ~SkTCubic() override {}
207
208 const SkDPoint& operator[](int n) const override { return fCubic[n]; }
209 SkDPoint& operator[](int n) override { return fCubic[n]; }
210
211 bool collapsed() const override { return fCubic.collapsed(); }
212 bool controlsInside() const override { return fCubic.controlsInside(); }
213 void debugInit() override { return fCubic.debugInit(); }
214#if DEBUG_T_SECT
215 void dumpID(int id) const override { return fCubic.dumpID(id); }
216#endif
217 SkDVector dxdyAtT(double t) const override { return fCubic.dxdyAtT(t); }
218#ifdef SK_DEBUG
219 SkOpGlobalState* globalState() const override { return fCubic.globalState(); }
220#endif
221 bool hullIntersects(const SkDQuad& quad, bool* isLinear) const override;
222 bool hullIntersects(const SkDConic& conic, bool* isLinear) const override;
223
224 bool hullIntersects(const SkDCubic& cubic, bool* isLinear) const override {
225 return cubic.hullIntersects(fCubic, isLinear);
226 }
227
228 bool hullIntersects(const SkTCurve& curve, bool* isLinear) const override {
229 return curve.hullIntersects(fCubic, isLinear);
230 }
231
232 int intersectRay(SkIntersections* i, const SkDLine& line) const override;
233 bool IsConic() const override { return false; }
234 SkTCurve* make(SkArenaAlloc& heap) const override { return heap.make<SkTCubic>(); }
235
236 int maxIntersections() const override { return SkDCubic::kMaxIntersections; }
237
238 void otherPts(int oddMan, const SkDPoint* endPt[2]) const override {
239 fCubic.otherPts(oddMan, endPt);
240 }
241
242 int pointCount() const override { return SkDCubic::kPointCount; }
243 int pointLast() const override { return SkDCubic::kPointLast; }
244 SkDPoint ptAtT(double t) const override { return fCubic.ptAtT(t); }
245 void setBounds(SkDRect* ) const override;
246
247 void subDivide(double t1, double t2, SkTCurve* curve) const override {
248 ((SkTCubic*) curve)->fCubic = fCubic.subDivide(t1, t2);
249 }
250};
251
252#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
int other_two(int one, int two)
#define SkDEBUGPARAMS(...)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
void otherPts(int oddMan, const SkDPoint *endPt[2]) const override
bool hullIntersects(const SkDQuad &quad, bool *isLinear) const override
void subDivide(double t1, double t2, SkTCurve *curve) const override
SkDPoint & operator[](int n) override
bool hullIntersects(const SkDCubic &cubic, bool *isLinear) const override
bool controlsInside() const override
SkTCurve * make(SkArenaAlloc &heap) const override
const SkDPoint & operator[](int n) const override
SkDPoint ptAtT(double t) const override
int pointLast() const override
int pointCount() const override
int intersectRay(SkIntersections *i, const SkDLine &line) const override
SkDVector dxdyAtT(double t) const override
bool collapsed() const override
~SkTCubic() override
bool IsConic() const override
void debugInit() override
bool hullIntersects(const SkTCurve &curve, bool *isLinear) const override
SkDCubic fCubic
void setBounds(SkDRect *) const override
int maxIntersections() const override
SkTCubic(const SkDCubic &c)
virtual bool hullIntersects(const SkDQuad &, bool *isLinear) const =0
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
float SkScalar
Definition extension.cpp:12
struct MyStruct s
struct MyStruct a[10]
AtkStateType state
GAsyncResult * result
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
SkDCubic second() const
SkDPoint pts[7]
SkDCubic first() const
int findMaxCurvature(double tValues[]) const
int convexHull(char order[kPointCount]) const
bool hullIntersects(const SkDCubic &c2, bool *isLinear) const
bool collapsed() const
bool toFloatPoints(SkPoint *) const
void subDivide(double t1, double t2, SkDCubic *c) const
static int maxIntersections()
bool isLinear(int startIndex, int endIndex) const
static const int kPointLast
void dump() const
SkDCubicPair chopAt(double t) const
void debugSet(const SkDPoint *pts)
static int RootsReal(double A, double B, double C, double D, double t[3])
double binarySearch(double min, double max, double axisIntercept, SearchAxis xAxis) const
int horizontalIntersect(double yIntercept, double roots[3]) const
void dumpInner() const
int findInflections(double tValues[2]) const
void debugInit()
static int pointLast()
bool monotonicInX() const
void dumpID(int id) const
const SkDPoint & operator[](int n) const
bool endsAreExtremaInXOrY() const
int verticalIntersect(double xIntercept, double roots[3]) const
static SkDCubic SubDivide(const SkPoint a[kPointCount], double t1, double t2)
void align(int endIndex, int ctrlIndex, SkDPoint *dstPt) const
const SkDCubic & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
static int FindInflections(const SkPoint a[kPointCount], double tValues[2])
double calcPrecision() const
SkDPoint fPts[kPointCount]
bool monotonicInY() const
static const int gPrecisionUnit
static int pointCount()
static int FindExtrema(const double src[], double tValue[2])
double top(const SkDCubic &dCurve, double startT, double endT, SkDPoint *topPt) const
bool controlsInside() const
static void Coefficients(const double *cubic, double *A, double *B, double *C, double *D)
int searchRoots(double extremes[6], int extrema, double axisIntercept, SearchAxis xAxis, double *validRoots) const
static const int kMaxIntersections
static int RootsValidT(const double A, const double B, const double C, double D, double s[3])
SkDPoint & operator[](int n)
SkDVector dxdyAtT(double t) const
SkDPoint ptAtT(double t) const
static void SubDivide(const SkPoint pts[kPointCount], const SkDPoint &a, const SkDPoint &d, double t1, double t2, SkDPoint p[2])
void otherPts(int index, const SkDPoint *o1Pts[kPointCount - 1]) const
static const int kPointCount
SkDQuad toQuad() const
static bool IsConic()
SkDCubic subDivide(double t1, double t2) const
static int ComplexBreak(const SkPoint pts[4], SkScalar *t)
bool approximatelyEqual(const SkDPoint &a) const
double dot(const SkDVector &a) const