1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPathOpsCurve_DEFINE
#define SkPathOpsCurve_DEFINE
#include "SkIntersections.h"
#include "SkPathOpsCubic.h"
#include "SkPathOpsLine.h"
#include "SkPathOpsQuad.h"
static SkDPoint dline_xy_at_t(const SkPoint a[2], double t) {
SkDLine line;
line.set(a);
return line.ptAtT(t);
}
static SkDPoint dquad_xy_at_t(const SkPoint a[3], double t) {
SkDQuad quad;
quad.set(a);
return quad.ptAtT(t);
}
static SkDPoint dcubic_xy_at_t(const SkPoint a[4], double t) {
SkDCubic cubic;
cubic.set(a);
return cubic.ptAtT(t);
}
static SkDPoint (* const CurveDPointAtT[])(const SkPoint[], double ) = {
NULL,
dline_xy_at_t,
dquad_xy_at_t,
dcubic_xy_at_t
};
static SkPoint fline_xy_at_t(const SkPoint a[2], double t) {
return dline_xy_at_t(a, t).asSkPoint();
}
static SkPoint fquad_xy_at_t(const SkPoint a[3], double t) {
return dquad_xy_at_t(a, t).asSkPoint();
}
static SkPoint fcubic_xy_at_t(const SkPoint a[4], double t) {
return dcubic_xy_at_t(a, t).asSkPoint();
}
static SkPoint (* const CurvePointAtT[])(const SkPoint[], double ) = {
NULL,
fline_xy_at_t,
fquad_xy_at_t,
fcubic_xy_at_t
};
static SkDVector dline_dxdy_at_t(const SkPoint a[2], double ) {
SkDLine line;
line.set(a);
return line[1] - line[0];
}
static SkDVector dquad_dxdy_at_t(const SkPoint a[3], double t) {
SkDQuad quad;
quad.set(a);
return quad.dxdyAtT(t);
}
static SkDVector dcubic_dxdy_at_t(const SkPoint a[4], double t) {
SkDCubic cubic;
cubic.set(a);
return cubic.dxdyAtT(t);
}
static SkDVector (* const CurveDSlopeAtT[])(const SkPoint[], double ) = {
NULL,
dline_dxdy_at_t,
dquad_dxdy_at_t,
dcubic_dxdy_at_t
};
static SkVector fline_dxdy_at_t(const SkPoint a[2], double ) {
return a[1] - a[0];
}
static SkVector fquad_dxdy_at_t(const SkPoint a[3], double t) {
return dquad_dxdy_at_t(a, t).asSkVector();
}
static SkVector fcubic_dxdy_at_t(const SkPoint a[4], double t) {
return dcubic_dxdy_at_t(a, t).asSkVector();
}
static SkVector (* const CurveSlopeAtT[])(const SkPoint[], double ) = {
NULL,
fline_dxdy_at_t,
fquad_dxdy_at_t,
fcubic_dxdy_at_t
};
static SkPoint quad_top(const SkPoint a[3], double startT, double endT) {
SkDQuad quad;
quad.set(a);
SkDPoint topPt = quad.top(startT, endT);
return topPt.asSkPoint();
}
static SkPoint cubic_top(const SkPoint a[4], double startT, double endT) {
SkDCubic cubic;
cubic.set(a);
SkDPoint topPt = cubic.top(startT, endT);
return topPt.asSkPoint();
}
static SkPoint (* const CurveTop[])(const SkPoint[], double , double ) = {
NULL,
NULL,
quad_top,
cubic_top
};
static bool line_is_vertical(const SkPoint a[2], double startT, double endT) {
SkDLine line;
line.set(a);
SkDPoint dst[2] = { line.ptAtT(startT), line.ptAtT(endT) };
return AlmostEqualUlps(dst[0].fX, dst[1].fX);
}
static bool quad_is_vertical(const SkPoint a[3], double startT, double endT) {
SkDQuad quad;
quad.set(a);
SkDQuad dst = quad.subDivide(startT, endT);
return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX);
}
static bool cubic_is_vertical(const SkPoint a[4], double startT, double endT) {
SkDCubic cubic;
cubic.set(a);
SkDCubic dst = cubic.subDivide(startT, endT);
return AlmostEqualUlps(dst[0].fX, dst[1].fX) && AlmostEqualUlps(dst[1].fX, dst[2].fX)
&& AlmostEqualUlps(dst[2].fX, dst[3].fX);
}
static bool (* const CurveIsVertical[])(const SkPoint[], double , double) = {
NULL,
line_is_vertical,
quad_is_vertical,
cubic_is_vertical
};
static void line_intersect_ray(const SkPoint a[2], const SkDLine& ray, SkIntersections* i) {
SkDLine line;
line.set(a);
i->intersectRay(line, ray);
}
static void quad_intersect_ray(const SkPoint a[3], const SkDLine& ray, SkIntersections* i) {
SkDQuad quad;
quad.set(a);
i->intersectRay(quad, ray);
}
static void cubic_intersect_ray(const SkPoint a[4], const SkDLine& ray, SkIntersections* i) {
SkDCubic cubic;
cubic.set(a);
i->intersectRay(cubic, ray);
}
static void (* const CurveIntersectRay[])(const SkPoint[] , const SkDLine& , SkIntersections* ) = {
NULL,
line_intersect_ray,
quad_intersect_ray,
cubic_intersect_ray
};
#endif
|