Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPathOpsCurve.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#ifndef SkPathOpsCurve_DEFINE
8#define SkPathOpsCurve_DEFINE
9
10#include "include/core/SkPath.h"
22
23struct SkPathOpsBounds;
24
25struct SkOpCurve {
29
30 const SkPoint& operator[](int n) const {
31 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb));
32 return fPts[n];
33 }
34
35 void dump() const;
36
37 void set(const SkDQuad& quad) {
38 for (int index = 0; index < SkDQuad::kPointCount; ++index) {
39 fPts[index] = quad[index].asSkPoint();
40 }
43 }
44
45 void set(const SkDCubic& cubic) {
46 for (int index = 0; index < SkDCubic::kPointCount; ++index) {
47 fPts[index] = cubic[index].asSkPoint();
48 }
51 }
52
53};
54
55struct SkDCurve {
56 union {
61 };
63
64 const SkDPoint& operator[](int n) const {
65 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb));
66 return fCubic[n];
67 }
68
70 SkASSERT(n >= 0 && n <= SkPathOpsVerbToPoints(fVerb));
71 return fCubic[n];
72 }
73
74 SkDPoint conicTop(const SkPoint curve[3], SkScalar curveWeight,
75 double s, double e, double* topT);
76 SkDPoint cubicTop(const SkPoint curve[4], SkScalar , double s, double e, double* topT);
77 void dump() const;
78 void dumpID(int ) const;
79 SkDPoint lineTop(const SkPoint[2], SkScalar , double , double , double* topT);
80 double nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint& opp) const;
81 SkDPoint quadTop(const SkPoint curve[3], SkScalar , double s, double e, double* topT);
82
83 void setConicBounds(const SkPoint curve[3], SkScalar curveWeight,
84 double s, double e, SkPathOpsBounds* );
85 void setCubicBounds(const SkPoint curve[4], SkScalar ,
86 double s, double e, SkPathOpsBounds* );
87 void setQuadBounds(const SkPoint curve[3], SkScalar ,
88 double s, double e, SkPathOpsBounds*);
89};
90
92public:
93 bool isCurve() const { return fIsCurve; }
94 bool isOrdered() const { return fOrdered; }
96
99private:
100 bool fIsCurve;
101 bool fOrdered; // cleared when a cubic's control point isn't between the sweep vectors
102
103};
104
105extern SkDPoint (SkDCurve::* const Top[])(const SkPoint curve[], SkScalar cWeight,
106 double tStart, double tEnd, double* topT);
107
108static SkDPoint dline_xy_at_t(const SkPoint a[2], SkScalar , double t) {
109 SkDLine line;
110 line.set(a);
111 return line.ptAtT(t);
112}
113
114static SkDPoint dquad_xy_at_t(const SkPoint a[3], SkScalar , double t) {
115 SkDQuad quad;
116 quad.set(a);
117 return quad.ptAtT(t);
118}
119
120static SkDPoint dconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t) {
121 SkDConic conic;
122 conic.set(a, weight);
123 return conic.ptAtT(t);
124}
125
126static SkDPoint dcubic_xy_at_t(const SkPoint a[4], SkScalar , double t) {
127 SkDCubic cubic;
128 cubic.set(a);
129 return cubic.ptAtT(t);
130}
131
132static SkDPoint (* const CurveDPointAtT[])(const SkPoint[], SkScalar , double ) = {
133 nullptr,
138};
139
140static SkDPoint ddline_xy_at_t(const SkDCurve& c, double t) {
141 return c.fLine.ptAtT(t);
142}
143
144static SkDPoint ddquad_xy_at_t(const SkDCurve& c, double t) {
145 return c.fQuad.ptAtT(t);
146}
147
148static SkDPoint ddconic_xy_at_t(const SkDCurve& c, double t) {
149 return c.fConic.ptAtT(t);
150}
151
152static SkDPoint ddcubic_xy_at_t(const SkDCurve& c, double t) {
153 return c.fCubic.ptAtT(t);
154}
155
156static SkDPoint (* const CurveDDPointAtT[])(const SkDCurve& , double ) = {
157 nullptr,
162};
163
164static SkPoint fline_xy_at_t(const SkPoint a[2], SkScalar weight, double t) {
165 return dline_xy_at_t(a, weight, t).asSkPoint();
166}
167
168static SkPoint fquad_xy_at_t(const SkPoint a[3], SkScalar weight, double t) {
169 return dquad_xy_at_t(a, weight, t).asSkPoint();
170}
171
172static SkPoint fconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t) {
173 return dconic_xy_at_t(a, weight, t).asSkPoint();
174}
175
176static SkPoint fcubic_xy_at_t(const SkPoint a[4], SkScalar weight, double t) {
177 return dcubic_xy_at_t(a, weight, t).asSkPoint();
178}
179
180static SkPoint (* const CurvePointAtT[])(const SkPoint[], SkScalar , double ) = {
181 nullptr,
186};
187
188static SkDVector dline_dxdy_at_t(const SkPoint a[2], SkScalar , double ) {
189 SkDLine line;
190 line.set(a);
191 return line[1] - line[0];
192}
193
194static SkDVector dquad_dxdy_at_t(const SkPoint a[3], SkScalar , double t) {
195 SkDQuad quad;
196 quad.set(a);
197 return quad.dxdyAtT(t);
198}
199
200static SkDVector dconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) {
201 SkDConic conic;
202 conic.set(a, weight);
203 return conic.dxdyAtT(t);
204}
205
206static SkDVector dcubic_dxdy_at_t(const SkPoint a[4], SkScalar , double t) {
207 SkDCubic cubic;
208 cubic.set(a);
209 return cubic.dxdyAtT(t);
210}
211
212static SkDVector (* const CurveDSlopeAtT[])(const SkPoint[], SkScalar , double ) = {
213 nullptr,
218};
219
220static SkDVector ddline_dxdy_at_t(const SkDCurve& c, double ) {
221 return c.fLine.fPts[1] - c.fLine.fPts[0];
222}
223
224static SkDVector ddquad_dxdy_at_t(const SkDCurve& c, double t) {
225 return c.fQuad.dxdyAtT(t);
226}
227
228static SkDVector ddconic_dxdy_at_t(const SkDCurve& c, double t) {
229 return c.fConic.dxdyAtT(t);
230}
231
232static SkDVector ddcubic_dxdy_at_t(const SkDCurve& c, double t) {
233 return c.fCubic.dxdyAtT(t);
234}
235
236static SkDVector (* const CurveDDSlopeAtT[])(const SkDCurve& , double ) = {
237 nullptr,
242};
243
244static SkVector fline_dxdy_at_t(const SkPoint a[2], SkScalar , double ) {
245 return a[1] - a[0];
246}
247
248static SkVector fquad_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) {
249 return dquad_dxdy_at_t(a, weight, t).asSkVector();
250}
251
252static SkVector fconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t) {
253 return dconic_dxdy_at_t(a, weight, t).asSkVector();
254}
255
256static SkVector fcubic_dxdy_at_t(const SkPoint a[4], SkScalar weight, double t) {
257 return dcubic_dxdy_at_t(a, weight, t).asSkVector();
258}
259
260static SkVector (* const CurveSlopeAtT[])(const SkPoint[], SkScalar , double ) = {
261 nullptr,
266};
267
268static bool line_is_vertical(const SkPoint a[2], SkScalar , double startT, double endT) {
269 SkDLine line;
270 line.set(a);
271 SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) };
272 return AlmostEqualUlps(dst[0].fX, dst[1].fX);
273}
274
275static bool quad_is_vertical(const SkPoint a[3], SkScalar , double startT, double endT) {
276 SkDQuad quad;
277 quad.set(a);
278 SkDQuad dst = quad.subDivide(startT, endT);
279 return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX);
280}
281
282static bool conic_is_vertical(const SkPoint a[3], SkScalar weight, double startT, double endT) {
283 SkDConic conic;
284 conic.set(a, weight);
285 SkDConic dst = conic.subDivide(startT, endT);
286 return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX);
287}
288
289static bool cubic_is_vertical(const SkPoint a[4], SkScalar , double startT, double endT) {
290 SkDCubic cubic;
291 cubic.set(a);
292 SkDCubic dst = cubic.subDivide(startT, endT);
293 return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX)
294 && AlmostEqualUlps(dst[2].fX, dst[3].fX);
295}
296
297static bool (* const CurveIsVertical[])(const SkPoint[], SkScalar , double , double) = {
298 nullptr,
303};
304
305static void line_intersect_ray(const SkPoint a[2], SkScalar , const SkDLine& ray,
306 SkIntersections* i) {
307 SkDLine line;
308 line.set(a);
309 i->intersectRay(line, ray);
310}
311
312static void quad_intersect_ray(const SkPoint a[3], SkScalar , const SkDLine& ray,
313 SkIntersections* i) {
314 SkDQuad quad;
315 quad.set(a);
316 i->intersectRay(quad, ray);
317}
318
319static void conic_intersect_ray(const SkPoint a[3], SkScalar weight, const SkDLine& ray,
320 SkIntersections* i) {
321 SkDConic conic;
322 conic.set(a, weight);
323 i->intersectRay(conic, ray);
324}
325
326static void cubic_intersect_ray(const SkPoint a[4], SkScalar , const SkDLine& ray,
327 SkIntersections* i) {
328 SkDCubic cubic;
329 cubic.set(a);
330 i->intersectRay(cubic, ray);
331}
332
333static void (* const CurveIntersectRay[])(const SkPoint[] , SkScalar , const SkDLine& ,
334 SkIntersections* ) = {
335 nullptr,
340};
341
342static void dline_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) {
343 i->intersectRay(c.fLine, ray);
344}
345
346static void dquad_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) {
347 i->intersectRay(c.fQuad, ray);
348}
349
350static void dconic_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) {
351 i->intersectRay(c.fConic, ray);
352}
353
354static void dcubic_intersect_ray(const SkDCurve& c, const SkDLine& ray, SkIntersections* i) {
355 i->intersectRay(c.fCubic, ray);
356}
357
358static void (* const CurveDIntersectRay[])(const SkDCurve& , const SkDLine& , SkIntersections* ) = {
359 nullptr,
364};
365
366static int line_intercept_h(const SkPoint a[2], SkScalar , SkScalar y, double* roots) {
367 if (a[0].fY == a[1].fY) {
368 return false;
369 }
370 SkDLine line;
371 roots[0] = SkIntersections::HorizontalIntercept(line.set(a), y);
372 return between(0, roots[0], 1);
373}
374
375static int line_intercept_v(const SkPoint a[2], SkScalar , SkScalar x, double* roots) {
376 if (a[0].fX == a[1].fX) {
377 return false;
378 }
379 SkDLine line;
380 roots[0] = SkIntersections::VerticalIntercept(line.set(a), x);
381 return between(0, roots[0], 1);
382}
383
384static int quad_intercept_h(const SkPoint a[2], SkScalar , SkScalar y, double* roots) {
385 SkDQuad quad;
386 return SkIntersections::HorizontalIntercept(quad.set(a), y, roots);
387}
388
389static int quad_intercept_v(const SkPoint a[2], SkScalar , SkScalar x, double* roots) {
390 SkDQuad quad;
391 return SkIntersections::VerticalIntercept(quad.set(a), x, roots);
392}
393
394static int conic_intercept_h(const SkPoint a[2], SkScalar w, SkScalar y, double* roots) {
395 SkDConic conic;
396 return SkIntersections::HorizontalIntercept(conic.set(a, w), y, roots);
397}
398
399static int conic_intercept_v(const SkPoint a[2], SkScalar w, SkScalar x, double* roots) {
400 SkDConic conic;
401 return SkIntersections::VerticalIntercept(conic.set(a, w), x, roots);
402}
403
404static int cubic_intercept_h(const SkPoint a[3], SkScalar , SkScalar y, double* roots) {
405 SkDCubic cubic;
406 return cubic.set(a).horizontalIntersect(y, roots);
407}
408
409static int cubic_intercept_v(const SkPoint a[3], SkScalar , SkScalar x, double* roots) {
410 SkDCubic cubic;
411 return cubic.set(a).verticalIntersect(x, roots);
412}
413
414static int (* const CurveIntercept[])(const SkPoint[] , SkScalar , SkScalar , double* ) = {
415 nullptr,
416 nullptr,
425};
426
427#endif
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static bool between(SkScalar a, SkScalar b, SkScalar c)
static SkDVector dline_dxdy_at_t(const SkPoint a[2], SkScalar, double)
static SkPoint fline_xy_at_t(const SkPoint a[2], SkScalar weight, double t)
static SkDPoint dconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t)
static SkDVector dquad_dxdy_at_t(const SkPoint a[3], SkScalar, double t)
static int conic_intercept_v(const SkPoint a[2], SkScalar w, SkScalar x, double *roots)
static SkDPoint(*const CurveDPointAtT[])(const SkPoint[], SkScalar, double)
static void quad_intersect_ray(const SkPoint a[3], SkScalar, const SkDLine &ray, SkIntersections *i)
static void dcubic_intersect_ray(const SkDCurve &c, const SkDLine &ray, SkIntersections *i)
static SkDPoint dline_xy_at_t(const SkPoint a[2], SkScalar, double t)
static SkDVector dcubic_dxdy_at_t(const SkPoint a[4], SkScalar, double t)
static bool conic_is_vertical(const SkPoint a[3], SkScalar weight, double startT, double endT)
static void conic_intersect_ray(const SkPoint a[3], SkScalar weight, const SkDLine &ray, SkIntersections *i)
static bool quad_is_vertical(const SkPoint a[3], SkScalar, double startT, double endT)
static void line_intersect_ray(const SkPoint a[2], SkScalar, const SkDLine &ray, SkIntersections *i)
static int quad_intercept_h(const SkPoint a[2], SkScalar, SkScalar y, double *roots)
static SkDPoint dquad_xy_at_t(const SkPoint a[3], SkScalar, double t)
static SkVector fconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t)
static void cubic_intersect_ray(const SkPoint a[4], SkScalar, const SkDLine &ray, SkIntersections *i)
static bool cubic_is_vertical(const SkPoint a[4], SkScalar, double startT, double endT)
static int quad_intercept_v(const SkPoint a[2], SkScalar, SkScalar x, double *roots)
static void dline_intersect_ray(const SkDCurve &c, const SkDLine &ray, SkIntersections *i)
static void dconic_intersect_ray(const SkDCurve &c, const SkDLine &ray, SkIntersections *i)
static SkDVector(*const CurveDDSlopeAtT[])(const SkDCurve &, double)
static SkPoint fconic_xy_at_t(const SkPoint a[3], SkScalar weight, double t)
static SkDVector ddconic_dxdy_at_t(const SkDCurve &c, double t)
static SkDVector ddquad_dxdy_at_t(const SkDCurve &c, double t)
static SkDVector ddcubic_dxdy_at_t(const SkDCurve &c, double t)
static SkDPoint ddconic_xy_at_t(const SkDCurve &c, double t)
static SkDVector ddline_dxdy_at_t(const SkDCurve &c, double)
static bool line_is_vertical(const SkPoint a[2], SkScalar, double startT, double endT)
static bool(*const CurveIsVertical[])(const SkPoint[], SkScalar, double, double)
static SkPoint fcubic_xy_at_t(const SkPoint a[4], SkScalar weight, double t)
static int(*const CurveIntercept[])(const SkPoint[], SkScalar, SkScalar, double *)
static void dquad_intersect_ray(const SkDCurve &c, const SkDLine &ray, SkIntersections *i)
static SkPoint fquad_xy_at_t(const SkPoint a[3], SkScalar weight, double t)
static SkDVector(*const CurveDSlopeAtT[])(const SkPoint[], SkScalar, double)
static int line_intercept_h(const SkPoint a[2], SkScalar, SkScalar y, double *roots)
static void(*const CurveDIntersectRay[])(const SkDCurve &, const SkDLine &, SkIntersections *)
static SkPoint(*const CurvePointAtT[])(const SkPoint[], SkScalar, double)
static SkDPoint dcubic_xy_at_t(const SkPoint a[4], SkScalar, double t)
static SkVector fcubic_dxdy_at_t(const SkPoint a[4], SkScalar weight, double t)
SkDPoint(SkDCurve::*const Top[])(const SkPoint curve[], SkScalar cWeight, double tStart, double tEnd, double *topT)
static SkDPoint(*const CurveDDPointAtT[])(const SkDCurve &, double)
static void(*const CurveIntersectRay[])(const SkPoint[], SkScalar, const SkDLine &, SkIntersections *)
static int cubic_intercept_h(const SkPoint a[3], SkScalar, SkScalar y, double *roots)
static int conic_intercept_h(const SkPoint a[2], SkScalar w, SkScalar y, double *roots)
static SkDPoint ddline_xy_at_t(const SkDCurve &c, double t)
static SkDPoint ddcubic_xy_at_t(const SkDCurve &c, double t)
static SkVector fquad_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t)
static SkVector(*const CurveSlopeAtT[])(const SkPoint[], SkScalar, double)
static SkDPoint ddquad_xy_at_t(const SkDCurve &c, double t)
static int line_intercept_v(const SkPoint a[2], SkScalar, SkScalar x, double *roots)
static SkDVector dconic_dxdy_at_t(const SkPoint a[3], SkScalar weight, double t)
static SkVector fline_dxdy_at_t(const SkPoint a[2], SkScalar, double)
static int cubic_intercept_v(const SkPoint a[3], SkScalar, SkScalar x, double *roots)
bool AlmostEqualUlps(const SkPoint &pt1, const SkPoint &pt2)
int SkPathOpsVerbToPoints(SkPath::Verb verb)
SkPoint SkVector
Type::kYUV Type::kRGBA() int(0.7 *637)
bool isCurve() const
bool isOrdered() const
SkDVector fSweep[2]
void setCurveHullSweep(SkPath::Verb verb)
int intersectRay(const SkDLine &, const SkDLine &)
static double VerticalIntercept(const SkDLine &line, double x)
static double HorizontalIntercept(const SkDLine &line, double y)
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
float SkScalar
Definition extension.cpp:12
struct MyStruct s
struct MyStruct a[10]
double y
double x
SkScalar w
SkDPoint ptAtT(double t) const
SkDVector dxdyAtT(double t) const
SkDVector dxdyAtT(double t) const
SkDPoint ptAtT(double t) const
static const int kPointCount
SkDQuad fQuad
void setCubicBounds(const SkPoint curve[4], SkScalar, double s, double e, SkPathOpsBounds *)
SkDConic fConic
void setConicBounds(const SkPoint curve[3], SkScalar curveWeight, double s, double e, SkPathOpsBounds *)
SkDLine fLine
SkDEBUGCODE(SkPath::Verb fVerb;) const SkDPoint &operator[](int n) const
void dumpID(int) const
void dump() const
double nearPoint(SkPath::Verb verb, const SkDPoint &xy, const SkDPoint &opp) const
SkDCubic fCubic
SkDPoint & operator[](int n)
SkDPoint lineTop(const SkPoint[2], SkScalar, double, double, double *topT)
SkDPoint conicTop(const SkPoint curve[3], SkScalar curveWeight, double s, double e, double *topT)
void setQuadBounds(const SkPoint curve[3], SkScalar, double s, double e, SkPathOpsBounds *)
SkDPoint quadTop(const SkPoint curve[3], SkScalar, double s, double e, double *topT)
SkDPoint cubicTop(const SkPoint curve[4], SkScalar, double s, double e, double *topT)
SkDPoint ptAtT(double t) const
SkDPoint fPts[2]
SkPoint asSkPoint() const
const SkDQuad & set(const SkPoint pts[kPointCount] SkDEBUGPARAMS(SkOpGlobalState *state=nullptr))
SkDQuad subDivide(double t1, double t2) const
SkDPoint ptAtT(double t) const
SkDVector dxdyAtT(double t) const
static const int kPointCount
SkVector asSkVector() const
void dump() const
void set(const SkDQuad &quad)
SkScalar fWeight
void set(const SkDCubic &cubic)
SkDEBUGCODE(SkPath::Verb fVerb;) const SkPoint &operator[](int n) const
SkPoint fPts[4]