blob: aac2838f1258a7e6fda07826f891effa00c70dfe [file] [log] [blame]
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 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.
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +00006 */
7
8#include "GrPathUtils.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00009
robertphillipsd5373412014-06-02 10:20:14 -070010#include "GrTypes.h"
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +000011#include "SkGeometry.h"
halcanary4dbbd042016-06-07 17:21:10 -070012#include "SkMathPriv.h"
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000013
bsalomon@google.com81712882012-11-01 17:12:34 +000014SkScalar GrPathUtils::scaleToleranceToSrc(SkScalar devTol,
bsalomon@google.comb9086a02012-11-01 18:02:54 +000015 const SkMatrix& viewM,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000016 const SkRect& pathBounds) {
bsalomon@google.com181e9bd2011-09-07 18:42:30 +000017 // In order to tesselate the path we get a bound on how much the matrix can
commit-bot@chromium.org18786512014-05-20 14:53:45 +000018 // scale when mapping to screen coordinates.
19 SkScalar stretch = viewM.getMaxScale();
bsalomon@google.com81712882012-11-01 17:12:34 +000020 SkScalar srcTol = devTol;
bsalomon@google.com181e9bd2011-09-07 18:42:30 +000021
22 if (stretch < 0) {
bsalomon@google.com38396322011-09-09 19:32:04 +000023 // take worst case mapRadius amoung four corners.
24 // (less than perfect)
25 for (int i = 0; i < 4; ++i) {
bsalomon@google.comb9086a02012-11-01 18:02:54 +000026 SkMatrix mat;
bsalomon@google.com38396322011-09-09 19:32:04 +000027 mat.setTranslate((i % 2) ? pathBounds.fLeft : pathBounds.fRight,
28 (i < 2) ? pathBounds.fTop : pathBounds.fBottom);
29 mat.postConcat(viewM);
30 stretch = SkMaxScalar(stretch, mat.mapRadius(SK_Scalar1));
31 }
bsalomon@google.com181e9bd2011-09-07 18:42:30 +000032 }
reed80ea19c2015-05-12 10:37:34 -070033 return srcTol / stretch;
bsalomon@google.com181e9bd2011-09-07 18:42:30 +000034}
35
bsalomon@google.comb5b31682011-06-16 18:05:35 +000036static const int MAX_POINTS_PER_CURVE = 1 << 10;
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000037static const SkScalar gMinCurveTol = 0.0001f;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000038
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000039uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[],
bsalomon@google.com81712882012-11-01 17:12:34 +000040 SkScalar tol) {
tomhudson@google.comc10a8882011-06-28 15:19:32 +000041 if (tol < gMinCurveTol) {
tomhudson@google.comafec7ba2011-06-30 14:47:55 +000042 tol = gMinCurveTol;
tomhudson@google.comc10a8882011-06-28 15:19:32 +000043 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000044 SkASSERT(tol > 0);
tomhudson@google.comc10a8882011-06-28 15:19:32 +000045
bsalomon@google.com81712882012-11-01 17:12:34 +000046 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]);
senorblancob6a40b82016-08-19 08:07:22 -070047 if (!SkScalarIsFinite(d)) {
48 return MAX_POINTS_PER_CURVE;
49 } else if (d <= tol) {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000050 return 1;
51 } else {
52 // Each time we subdivide, d should be cut in 4. So we need to
53 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x)
54 // points.
55 // 2^(log4(x)) = sqrt(x);
reed80ea19c2015-05-12 10:37:34 -070056 SkScalar divSqrt = SkScalarSqrt(d / tol);
egdaniel5a23a142015-02-25 06:41:47 -080057 if (((SkScalar)SK_MaxS32) <= divSqrt) {
58 return MAX_POINTS_PER_CURVE;
59 } else {
60 int temp = SkScalarCeilToInt(divSqrt);
61 int pow2 = GrNextPow2(temp);
62 // Because of NaNs & INFs we can wind up with a degenerate temp
63 // such that pow2 comes out negative. Also, our point generator
64 // will always output at least one pt.
65 if (pow2 < 1) {
66 pow2 = 1;
67 }
68 return SkTMin(pow2, MAX_POINTS_PER_CURVE);
bsalomon@google.com61f3bde2011-06-17 20:06:49 +000069 }
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000070 }
71}
72
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000073uint32_t GrPathUtils::generateQuadraticPoints(const SkPoint& p0,
74 const SkPoint& p1,
75 const SkPoint& p2,
bsalomon@google.com81712882012-11-01 17:12:34 +000076 SkScalar tolSqd,
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000077 SkPoint** points,
tomhudson@google.comc10a8882011-06-28 15:19:32 +000078 uint32_t pointsLeft) {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000079 if (pointsLeft < 2 ||
80 (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) {
81 (*points)[0] = p2;
82 *points += 1;
83 return 1;
84 }
85
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000086 SkPoint q[] = {
bsalomon@google.com81712882012-11-01 17:12:34 +000087 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) },
88 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) },
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000089 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000090 SkPoint r = { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) };
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000091
92 pointsLeft >>= 1;
93 uint32_t a = generateQuadraticPoints(p0, q[0], r, tolSqd, points, pointsLeft);
94 uint32_t b = generateQuadraticPoints(r, q[1], p2, tolSqd, points, pointsLeft);
95 return a + b;
96}
97
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000098uint32_t GrPathUtils::cubicPointCount(const SkPoint points[],
bsalomon@google.com81712882012-11-01 17:12:34 +000099 SkScalar tol) {
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000100 if (tol < gMinCurveTol) {
tomhudson@google.comafec7ba2011-06-30 14:47:55 +0000101 tol = gMinCurveTol;
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000102 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000103 SkASSERT(tol > 0);
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000104
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000105 SkScalar d = SkTMax(
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000106 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]),
107 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3]));
epoger@google.com2047f002011-05-17 17:36:59 +0000108 d = SkScalarSqrt(d);
senorblancob6a40b82016-08-19 08:07:22 -0700109 if (!SkScalarIsFinite(d)) {
110 return MAX_POINTS_PER_CURVE;
111 } else if (d <= tol) {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000112 return 1;
113 } else {
reed80ea19c2015-05-12 10:37:34 -0700114 SkScalar divSqrt = SkScalarSqrt(d / tol);
egdaniel5a23a142015-02-25 06:41:47 -0800115 if (((SkScalar)SK_MaxS32) <= divSqrt) {
116 return MAX_POINTS_PER_CURVE;
117 } else {
reed80ea19c2015-05-12 10:37:34 -0700118 int temp = SkScalarCeilToInt(SkScalarSqrt(d / tol));
egdaniel5a23a142015-02-25 06:41:47 -0800119 int pow2 = GrNextPow2(temp);
120 // Because of NaNs & INFs we can wind up with a degenerate temp
121 // such that pow2 comes out negative. Also, our point generator
122 // will always output at least one pt.
123 if (pow2 < 1) {
124 pow2 = 1;
125 }
126 return SkTMin(pow2, MAX_POINTS_PER_CURVE);
bsalomon@google.com61f3bde2011-06-17 20:06:49 +0000127 }
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000128 }
129}
130
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000131uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0,
132 const SkPoint& p1,
133 const SkPoint& p2,
134 const SkPoint& p3,
bsalomon@google.com81712882012-11-01 17:12:34 +0000135 SkScalar tolSqd,
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000136 SkPoint** points,
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000137 uint32_t pointsLeft) {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000138 if (pointsLeft < 2 ||
139 (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd &&
140 p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) {
robertphillipsf08ce6c2015-12-08 05:19:12 -0800141 (*points)[0] = p3;
142 *points += 1;
143 return 1;
144 }
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000145 SkPoint q[] = {
bsalomon@google.com81712882012-11-01 17:12:34 +0000146 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) },
147 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) },
148 { SkScalarAve(p2.fX, p3.fX), SkScalarAve(p2.fY, p3.fY) }
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000149 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000150 SkPoint r[] = {
bsalomon@google.com81712882012-11-01 17:12:34 +0000151 { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) },
152 { SkScalarAve(q[1].fX, q[2].fX), SkScalarAve(q[1].fY, q[2].fY) }
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000153 };
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000154 SkPoint s = { SkScalarAve(r[0].fX, r[1].fX), SkScalarAve(r[0].fY, r[1].fY) };
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000155 pointsLeft >>= 1;
156 uint32_t a = generateCubicPoints(p0, q[0], r[0], s, tolSqd, points, pointsLeft);
157 uint32_t b = generateCubicPoints(s, r[1], q[2], p3, tolSqd, points, pointsLeft);
158 return a + b;
159}
160
bsalomon@google.com8d033a12012-04-27 15:52:53 +0000161int GrPathUtils::worstCasePointCount(const SkPath& path, int* subpaths,
bsalomon@google.com81712882012-11-01 17:12:34 +0000162 SkScalar tol) {
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000163 if (tol < gMinCurveTol) {
tomhudson@google.comafec7ba2011-06-30 14:47:55 +0000164 tol = gMinCurveTol;
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000165 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000166 SkASSERT(tol > 0);
tomhudson@google.comc10a8882011-06-28 15:19:32 +0000167
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000168 int pointCount = 0;
169 *subpaths = 1;
170
171 bool first = true;
172
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000173 SkPath::Iter iter(path, false);
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000174 SkPath::Verb verb;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000175
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000176 SkPoint pts[4];
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000177 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000178
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000179 switch (verb) {
180 case SkPath::kLine_Verb:
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000181 pointCount += 1;
182 break;
egdanielaf18a092015-01-05 10:22:28 -0800183 case SkPath::kConic_Verb: {
184 SkScalar weight = iter.conicWeight();
185 SkAutoConicToQuads converter;
186 const SkPoint* quadPts = converter.computeQuads(pts, weight, 0.25f);
187 for (int i = 0; i < converter.countQuads(); ++i) {
188 pointCount += quadraticPointCount(quadPts + 2*i, tol);
189 }
190 }
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000191 case SkPath::kQuad_Verb:
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000192 pointCount += quadraticPointCount(pts, tol);
193 break;
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000194 case SkPath::kCubic_Verb:
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000195 pointCount += cubicPointCount(pts, tol);
196 break;
bsalomon@google.com94b284d2013-05-10 17:14:06 +0000197 case SkPath::kMove_Verb:
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000198 pointCount += 1;
199 if (!first) {
200 ++(*subpaths);
201 }
202 break;
203 default:
204 break;
205 }
206 first = false;
207 }
208 return pointCount;
209}
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000210
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000211void GrPathUtils::QuadUVMatrix::set(const SkPoint qPts[3]) {
bsalomon@google.com19713172012-03-15 13:51:08 +0000212 SkMatrix m;
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000213 // We want M such that M * xy_pt = uv_pt
214 // We know M * control_pts = [0 1/2 1]
215 // [0 0 1]
216 // [1 1 1]
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000217 // And control_pts = [x0 x1 x2]
218 // [y0 y1 y2]
219 // [1 1 1 ]
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000220 // We invert the control pt matrix and post concat to both sides to get M.
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000221 // Using the known form of the control point matrix and the result, we can
222 // optimize and improve precision.
223
224 double x0 = qPts[0].fX;
225 double y0 = qPts[0].fY;
226 double x1 = qPts[1].fX;
227 double y1 = qPts[1].fY;
228 double x2 = qPts[2].fX;
229 double y2 = qPts[2].fY;
230 double det = x0*y1 - y0*x1 + x2*y0 - y2*x0 + x1*y2 - y1*x2;
231
skia.committer@gmail.com8491d242013-12-05 07:02:16 +0000232 if (!sk_float_isfinite(det)
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000233 || SkScalarNearlyZero((float)det, SK_ScalarNearlyZero * SK_ScalarNearlyZero)) {
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000234 // The quad is degenerate. Hopefully this is rare. Find the pts that are
235 // farthest apart to compute a line (unless it is really a pt).
236 SkScalar maxD = qPts[0].distanceToSqd(qPts[1]);
237 int maxEdge = 0;
238 SkScalar d = qPts[1].distanceToSqd(qPts[2]);
239 if (d > maxD) {
240 maxD = d;
241 maxEdge = 1;
242 }
243 d = qPts[2].distanceToSqd(qPts[0]);
244 if (d > maxD) {
245 maxD = d;
246 maxEdge = 2;
247 }
248 // We could have a tolerance here, not sure if it would improve anything
249 if (maxD > 0) {
250 // Set the matrix to give (u = 0, v = distance_to_line)
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000251 SkVector lineVec = qPts[(maxEdge + 1)%3] - qPts[maxEdge];
bsalomon@google.com20e542e2012-02-15 18:49:41 +0000252 // when looking from the point 0 down the line we want positive
253 // distances to be to the left. This matches the non-degenerate
254 // case.
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000255 lineVec.setOrthog(lineVec, SkPoint::kLeft_Side);
bsalomon@google.com19713172012-03-15 13:51:08 +0000256 // first row
257 fM[0] = 0;
258 fM[1] = 0;
259 fM[2] = 0;
260 // second row
261 fM[3] = lineVec.fX;
262 fM[4] = lineVec.fY;
263 fM[5] = -lineVec.dot(qPts[maxEdge]);
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000264 } else {
265 // It's a point. It should cover zero area. Just set the matrix such
266 // that (u, v) will always be far away from the quad.
bsalomon@google.com19713172012-03-15 13:51:08 +0000267 fM[0] = 0; fM[1] = 0; fM[2] = 100.f;
268 fM[3] = 0; fM[4] = 0; fM[5] = 100.f;
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000269 }
270 } else {
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000271 double scale = 1.0/det;
272
273 // compute adjugate matrix
robertphillips87a22342016-03-01 14:49:44 -0800274 double a2, a3, a4, a5, a6, a7, a8;
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000275 a2 = x1*y2-x2*y1;
276
277 a3 = y2-y0;
278 a4 = x0-x2;
279 a5 = x2*y0-x0*y2;
280
281 a6 = y0-y1;
282 a7 = x1-x0;
283 a8 = x0*y1-x1*y0;
284
skia.committer@gmail.com8491d242013-12-05 07:02:16 +0000285 // this performs the uv_pts*adjugate(control_pts) multiply,
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000286 // then does the scale by 1/det afterwards to improve precision
287 m[SkMatrix::kMScaleX] = (float)((0.5*a3 + a6)*scale);
288 m[SkMatrix::kMSkewX] = (float)((0.5*a4 + a7)*scale);
289 m[SkMatrix::kMTransX] = (float)((0.5*a5 + a8)*scale);
290
291 m[SkMatrix::kMSkewY] = (float)(a6*scale);
292 m[SkMatrix::kMScaleY] = (float)(a7*scale);
293 m[SkMatrix::kMTransY] = (float)(a8*scale);
294
robertphillips87a22342016-03-01 14:49:44 -0800295 // kMPersp0 & kMPersp1 should algebraically be zero
296 m[SkMatrix::kMPersp0] = 0.0f;
297 m[SkMatrix::kMPersp1] = 0.0f;
commit-bot@chromium.orgf543fd92013-12-04 21:33:08 +0000298 m[SkMatrix::kMPersp2] = (float)((a2 + a5 + a8)*scale);
bsalomon@google.com19713172012-03-15 13:51:08 +0000299
bsalomon@google.com19713172012-03-15 13:51:08 +0000300 // It may not be normalized to have 1.0 in the bottom right
301 float m33 = m.get(SkMatrix::kMPersp2);
302 if (1.f != m33) {
303 m33 = 1.f / m33;
304 fM[0] = m33 * m.get(SkMatrix::kMScaleX);
305 fM[1] = m33 * m.get(SkMatrix::kMSkewX);
306 fM[2] = m33 * m.get(SkMatrix::kMTransX);
307 fM[3] = m33 * m.get(SkMatrix::kMSkewY);
308 fM[4] = m33 * m.get(SkMatrix::kMScaleY);
309 fM[5] = m33 * m.get(SkMatrix::kMTransY);
310 } else {
311 fM[0] = m.get(SkMatrix::kMScaleX);
312 fM[1] = m.get(SkMatrix::kMSkewX);
313 fM[2] = m.get(SkMatrix::kMTransX);
314 fM[3] = m.get(SkMatrix::kMSkewY);
315 fM[4] = m.get(SkMatrix::kMScaleY);
316 fM[5] = m.get(SkMatrix::kMTransY);
317 }
bsalomon@google.comdc3c7802012-01-31 20:46:32 +0000318 }
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000319}
320
commit-bot@chromium.org13948402013-08-20 17:55:43 +0000321////////////////////////////////////////////////////////////////////////////////
322
Dean McNamee3b830a92017-01-13 12:17:09 +0000323// k = (y2 - y0, x0 - x2, x2*y0 - x0*y2)
324// l = (y1 - y0, x0 - x1, x1*y0 - x0*y1) * 2*w
325// m = (y2 - y1, x1 - x2, x2*y1 - x1*y2) * 2*w
commit-bot@chromium.org13948402013-08-20 17:55:43 +0000326void GrPathUtils::getConicKLM(const SkPoint p[3], const SkScalar weight, SkScalar klm[9]) {
327 const SkScalar w2 = 2.f * weight;
328 klm[0] = p[2].fY - p[0].fY;
329 klm[1] = p[0].fX - p[2].fX;
Dean McNamee3b830a92017-01-13 12:17:09 +0000330 klm[2] = p[2].fX * p[0].fY - p[0].fX * p[2].fY;
commit-bot@chromium.org13948402013-08-20 17:55:43 +0000331
332 klm[3] = w2 * (p[1].fY - p[0].fY);
333 klm[4] = w2 * (p[0].fX - p[1].fX);
334 klm[5] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY);
335
336 klm[6] = w2 * (p[2].fY - p[1].fY);
337 klm[7] = w2 * (p[1].fX - p[2].fX);
338 klm[8] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY);
339
340 // scale the max absolute value of coeffs to 10
341 SkScalar scale = 0.f;
342 for (int i = 0; i < 9; ++i) {
343 scale = SkMaxScalar(scale, SkScalarAbs(klm[i]));
344 }
345 SkASSERT(scale > 0.f);
346 scale = 10.f / scale;
347 for (int i = 0; i < 9; ++i) {
348 klm[i] *= scale;
349 }
350}
351
352////////////////////////////////////////////////////////////////////////////////
353
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000354namespace {
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000355
356// a is the first control point of the cubic.
357// ab is the vector from a to the second control point.
358// dc is the vector from the fourth to the third control point.
359// d is the fourth control point.
360// p is the candidate quadratic control point.
361// this assumes that the cubic doesn't inflect and is simple
362bool is_point_within_cubic_tangents(const SkPoint& a,
363 const SkVector& ab,
364 const SkVector& dc,
365 const SkPoint& d,
reed026beb52015-06-10 14:23:15 -0700366 SkPathPriv::FirstDirection dir,
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000367 const SkPoint p) {
368 SkVector ap = p - a;
369 SkScalar apXab = ap.cross(ab);
reed026beb52015-06-10 14:23:15 -0700370 if (SkPathPriv::kCW_FirstDirection == dir) {
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000371 if (apXab > 0) {
372 return false;
373 }
374 } else {
reed026beb52015-06-10 14:23:15 -0700375 SkASSERT(SkPathPriv::kCCW_FirstDirection == dir);
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000376 if (apXab < 0) {
377 return false;
378 }
379 }
380
381 SkVector dp = p - d;
382 SkScalar dpXdc = dp.cross(dc);
reed026beb52015-06-10 14:23:15 -0700383 if (SkPathPriv::kCW_FirstDirection == dir) {
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000384 if (dpXdc < 0) {
385 return false;
386 }
387 } else {
reed026beb52015-06-10 14:23:15 -0700388 SkASSERT(SkPathPriv::kCCW_FirstDirection == dir);
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000389 if (dpXdc > 0) {
390 return false;
391 }
392 }
393 return true;
394}
395
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000396void convert_noninflect_cubic_to_quads(const SkPoint p[4],
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000397 SkScalar toleranceSqd,
398 bool constrainWithinTangents,
reed026beb52015-06-10 14:23:15 -0700399 SkPathPriv::FirstDirection dir,
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000400 SkTArray<SkPoint, true>* quads,
401 int sublevel = 0) {
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000402
403 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in which case it is
404 // p[2]. Point d is always p[3]. Point c is p[2] unless p[2] == p[3], in which case it is p[1].
405
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000406 SkVector ab = p[1] - p[0];
407 SkVector dc = p[2] - p[3];
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000408
robertphillipsf08ce6c2015-12-08 05:19:12 -0800409 if (ab.lengthSqd() < SK_ScalarNearlyZero) {
410 if (dc.lengthSqd() < SK_ScalarNearlyZero) {
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000411 SkPoint* degQuad = quads->push_back_n(3);
412 degQuad[0] = p[0];
413 degQuad[1] = p[0];
414 degQuad[2] = p[3];
415 return;
416 }
417 ab = p[2] - p[0];
418 }
robertphillipsf08ce6c2015-12-08 05:19:12 -0800419 if (dc.lengthSqd() < SK_ScalarNearlyZero) {
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000420 dc = p[1] - p[3];
421 }
422
bsalomon3935a7b2014-06-19 12:33:08 -0700423 // When the ab and cd tangents are degenerate or nearly parallel with vector from d to a the
424 // constraint that the quad point falls between the tangents becomes hard to enforce and we are
425 // likely to hit the max subdivision count. However, in this case the cubic is approaching a
426 // line and the accuracy of the quad point isn't so important. We check if the two middle cubic
427 // control points are very close to the baseline vector. If so then we just pick quadratic
428 // points on the control polygon.
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000429
430 if (constrainWithinTangents) {
431 SkVector da = p[0] - p[3];
bsalomon3935a7b2014-06-19 12:33:08 -0700432 bool doQuads = dc.lengthSqd() < SK_ScalarNearlyZero ||
433 ab.lengthSqd() < SK_ScalarNearlyZero;
434 if (!doQuads) {
435 SkScalar invDALengthSqd = da.lengthSqd();
436 if (invDALengthSqd > SK_ScalarNearlyZero) {
437 invDALengthSqd = SkScalarInvert(invDALengthSqd);
438 // cross(ab, da)^2/length(da)^2 == sqd distance from b to line from d to a.
439 // same goes for point c using vector cd.
440 SkScalar detABSqd = ab.cross(da);
441 detABSqd = SkScalarSquare(detABSqd);
442 SkScalar detDCSqd = dc.cross(da);
443 detDCSqd = SkScalarSquare(detDCSqd);
444 if (SkScalarMul(detABSqd, invDALengthSqd) < toleranceSqd &&
445 SkScalarMul(detDCSqd, invDALengthSqd) < toleranceSqd) {
446 doQuads = true;
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000447 }
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000448 }
449 }
bsalomon3935a7b2014-06-19 12:33:08 -0700450 if (doQuads) {
451 SkPoint b = p[0] + ab;
452 SkPoint c = p[3] + dc;
453 SkPoint mid = b + c;
454 mid.scale(SK_ScalarHalf);
455 // Insert two quadratics to cover the case when ab points away from d and/or dc
456 // points away from a.
457 if (SkVector::DotProduct(da, dc) < 0 || SkVector::DotProduct(ab,da) > 0) {
458 SkPoint* qpts = quads->push_back_n(6);
459 qpts[0] = p[0];
460 qpts[1] = b;
461 qpts[2] = mid;
462 qpts[3] = mid;
463 qpts[4] = c;
464 qpts[5] = p[3];
465 } else {
466 SkPoint* qpts = quads->push_back_n(3);
467 qpts[0] = p[0];
468 qpts[1] = mid;
469 qpts[2] = p[3];
470 }
471 return;
472 }
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000473 }
474
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000475 static const SkScalar kLengthScale = 3 * SK_Scalar1 / 2;
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000476 static const int kMaxSubdivs = 10;
477
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000478 ab.scale(kLengthScale);
479 dc.scale(kLengthScale);
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000480
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000481 // e0 and e1 are extrapolations along vectors ab and dc.
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000482 SkVector c0 = p[0];
483 c0 += ab;
484 SkVector c1 = p[3];
485 c1 += dc;
486
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000487 SkScalar dSqd = sublevel > kMaxSubdivs ? 0 : c0.distanceToSqd(c1);
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000488 if (dSqd < toleranceSqd) {
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000489 SkPoint cAvg = c0;
490 cAvg += c1;
491 cAvg.scale(SK_ScalarHalf);
492
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000493 bool subdivide = false;
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000494
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000495 if (constrainWithinTangents &&
496 !is_point_within_cubic_tangents(p[0], ab, dc, p[3], dir, cAvg)) {
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000497 // choose a new cAvg that is the intersection of the two tangent lines.
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000498 ab.setOrthog(ab);
499 SkScalar z0 = -ab.dot(p[0]);
500 dc.setOrthog(dc);
501 SkScalar z1 = -dc.dot(p[3]);
502 cAvg.fX = SkScalarMul(ab.fY, z1) - SkScalarMul(z0, dc.fY);
503 cAvg.fY = SkScalarMul(z0, dc.fX) - SkScalarMul(ab.fX, z1);
504 SkScalar z = SkScalarMul(ab.fX, dc.fY) - SkScalarMul(ab.fY, dc.fX);
505 z = SkScalarInvert(z);
506 cAvg.fX *= z;
507 cAvg.fY *= z;
508 if (sublevel <= kMaxSubdivs) {
509 SkScalar d0Sqd = c0.distanceToSqd(cAvg);
510 SkScalar d1Sqd = c1.distanceToSqd(cAvg);
bsalomon@google.com54ad8512012-08-02 14:55:45 +0000511 // We need to subdivide if d0 + d1 > tolerance but we have the sqd values. We know
512 // the distances and tolerance can't be negative.
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000513 // (d0 + d1)^2 > toleranceSqd
514 // d0Sqd + 2*d0*d1 + d1Sqd > toleranceSqd
515 SkScalar d0d1 = SkScalarSqrt(SkScalarMul(d0Sqd, d1Sqd));
516 subdivide = 2 * d0d1 + d0Sqd + d1Sqd > toleranceSqd;
517 }
518 }
519 if (!subdivide) {
520 SkPoint* pts = quads->push_back_n(3);
521 pts[0] = p[0];
522 pts[1] = cAvg;
523 pts[2] = p[3];
524 return;
525 }
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000526 }
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000527 SkPoint choppedPts[7];
528 SkChopCubicAtHalf(p, choppedPts);
529 convert_noninflect_cubic_to_quads(choppedPts + 0,
530 toleranceSqd,
531 constrainWithinTangents,
532 dir,
533 quads,
534 sublevel + 1);
535 convert_noninflect_cubic_to_quads(choppedPts + 3,
536 toleranceSqd,
537 constrainWithinTangents,
538 dir,
539 quads,
540 sublevel + 1);
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000541}
542}
543
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000544void GrPathUtils::convertCubicToQuads(const SkPoint p[4],
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000545 SkScalar tolScale,
546 SkTArray<SkPoint, true>* quads) {
547 SkPoint chopped[10];
548 int count = SkChopCubicAtInflections(p, chopped);
549
bsalomon18fab302016-02-16 08:00:05 -0800550 const SkScalar tolSqd = SkScalarSquare(tolScale);
bsalomon@google.coma51ab842012-07-10 19:53:34 +0000551
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000552 for (int i = 0; i < count; ++i) {
553 SkPoint* cubic = chopped + 3*i;
bsalomon18fab302016-02-16 08:00:05 -0800554 // The direction param is ignored if the third param is false.
555 convert_noninflect_cubic_to_quads(cubic, tolSqd, false,
556 SkPathPriv::kCCW_FirstDirection, quads);
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000557 }
bsalomon18fab302016-02-16 08:00:05 -0800558}
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000559
bsalomon18fab302016-02-16 08:00:05 -0800560void GrPathUtils::convertCubicToQuadsConstrainToTangents(const SkPoint p[4],
561 SkScalar tolScale,
562 SkPathPriv::FirstDirection dir,
563 SkTArray<SkPoint, true>* quads) {
564 SkPoint chopped[10];
565 int count = SkChopCubicAtInflections(p, chopped);
566
567 const SkScalar tolSqd = SkScalarSquare(tolScale);
568
569 for (int i = 0; i < count; ++i) {
570 SkPoint* cubic = chopped + 3*i;
571 convert_noninflect_cubic_to_quads(cubic, tolSqd, true, dir, quads);
572 }
bsalomon@google.com69cc6ad2012-01-17 14:25:10 +0000573}
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000574
575////////////////////////////////////////////////////////////////////////////////
576
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000577// Solves linear system to extract klm
578// P.K = k (similarly for l, m)
579// Where P is matrix of control points
580// K is coefficients for the line K
581// k is vector of values of K evaluated at the control points
582// Solving for K, thus K = P^(-1) . k
583static void calc_cubic_klm(const SkPoint p[4], const SkScalar controlK[4],
584 const SkScalar controlL[4], const SkScalar controlM[4],
585 SkScalar k[3], SkScalar l[3], SkScalar m[3]) {
586 SkMatrix matrix;
587 matrix.setAll(p[0].fX, p[0].fY, 1.f,
588 p[1].fX, p[1].fY, 1.f,
589 p[2].fX, p[2].fY, 1.f);
590 SkMatrix inverse;
591 if (matrix.invert(&inverse)) {
592 inverse.mapHomogeneousPoints(k, controlK, 1);
593 inverse.mapHomogeneousPoints(l, controlL, 1);
594 inverse.mapHomogeneousPoints(m, controlM, 1);
595 }
596
597}
598
599static void set_serp_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
600 SkScalar tempSqrt = SkScalarSqrt(9.f * d[1] * d[1] - 12.f * d[0] * d[2]);
601 SkScalar ls = 3.f * d[1] - tempSqrt;
602 SkScalar lt = 6.f * d[0];
603 SkScalar ms = 3.f * d[1] + tempSqrt;
604 SkScalar mt = 6.f * d[0];
605
606 k[0] = ls * ms;
607 k[1] = (3.f * ls * ms - ls * mt - lt * ms) / 3.f;
608 k[2] = (lt * (mt - 2.f * ms) + ls * (3.f * ms - 2.f * mt)) / 3.f;
609 k[3] = (lt - ls) * (mt - ms);
610
611 l[0] = ls * ls * ls;
612 const SkScalar lt_ls = lt - ls;
613 l[1] = ls * ls * lt_ls * -1.f;
614 l[2] = lt_ls * lt_ls * ls;
615 l[3] = -1.f * lt_ls * lt_ls * lt_ls;
616
617 m[0] = ms * ms * ms;
618 const SkScalar mt_ms = mt - ms;
619 m[1] = ms * ms * mt_ms * -1.f;
620 m[2] = mt_ms * mt_ms * ms;
621 m[3] = -1.f * mt_ms * mt_ms * mt_ms;
622
623 // If d0 < 0 we need to flip the orientation of our curve
624 // This is done by negating the k and l values
625 // We want negative distance values to be on the inside
626 if ( d[0] > 0) {
627 for (int i = 0; i < 4; ++i) {
628 k[i] = -k[i];
629 l[i] = -l[i];
630 }
631 }
632}
633
634static void set_loop_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
635 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]);
636 SkScalar ls = d[1] - tempSqrt;
637 SkScalar lt = 2.f * d[0];
638 SkScalar ms = d[1] + tempSqrt;
639 SkScalar mt = 2.f * d[0];
640
641 k[0] = ls * ms;
642 k[1] = (3.f * ls*ms - ls * mt - lt * ms) / 3.f;
643 k[2] = (lt * (mt - 2.f * ms) + ls * (3.f * ms - 2.f * mt)) / 3.f;
644 k[3] = (lt - ls) * (mt - ms);
645
646 l[0] = ls * ls * ms;
647 l[1] = (ls * (ls * (mt - 3.f * ms) + 2.f * lt * ms))/-3.f;
648 l[2] = ((lt - ls) * (ls * (2.f * mt - 3.f * ms) + lt * ms))/3.f;
649 l[3] = -1.f * (lt - ls) * (lt - ls) * (mt - ms);
650
651 m[0] = ls * ms * ms;
652 m[1] = (ms * (ls * (2.f * mt - 3.f * ms) + lt * ms))/-3.f;
653 m[2] = ((mt - ms) * (ls * (mt - 3.f * ms) + 2.f * lt * ms))/3.f;
654 m[3] = -1.f * (lt - ls) * (mt - ms) * (mt - ms);
655
656
657 // If (d0 < 0 && sign(k1) > 0) || (d0 > 0 && sign(k1) < 0),
658 // we need to flip the orientation of our curve.
659 // This is done by negating the k and l values
commit-bot@chromium.org07e1c3f2013-08-22 20:41:15 +0000660 if ( (d[0] < 0 && k[1] > 0) || (d[0] > 0 && k[1] < 0)) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000661 for (int i = 0; i < 4; ++i) {
662 k[i] = -k[i];
663 l[i] = -l[i];
664 }
665 }
666}
667
668static void set_cusp_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
669 const SkScalar ls = d[2];
670 const SkScalar lt = 3.f * d[1];
671
672 k[0] = ls;
673 k[1] = ls - lt / 3.f;
674 k[2] = ls - 2.f * lt / 3.f;
675 k[3] = ls - lt;
676
677 l[0] = ls * ls * ls;
678 const SkScalar ls_lt = ls - lt;
679 l[1] = ls * ls * ls_lt;
680 l[2] = ls_lt * ls_lt * ls;
681 l[3] = ls_lt * ls_lt * ls_lt;
682
683 m[0] = 1.f;
684 m[1] = 1.f;
685 m[2] = 1.f;
686 m[3] = 1.f;
687}
688
689// For the case when a cubic is actually a quadratic
690// M =
691// 0 0 0
692// 1/3 0 1/3
693// 2/3 1/3 2/3
694// 1 1 1
695static void set_quadratic_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
696 k[0] = 0.f;
697 k[1] = 1.f/3.f;
698 k[2] = 2.f/3.f;
699 k[3] = 1.f;
700
701 l[0] = 0.f;
702 l[1] = 0.f;
703 l[2] = 1.f/3.f;
704 l[3] = 1.f;
705
706 m[0] = 0.f;
707 m[1] = 1.f/3.f;
708 m[2] = 2.f/3.f;
709 m[3] = 1.f;
710
711 // If d2 < 0 we need to flip the orientation of our curve
712 // This is done by negating the k and l values
713 if ( d[2] > 0) {
714 for (int i = 0; i < 4; ++i) {
715 k[i] = -k[i];
716 l[i] = -l[i];
717 }
718 }
719}
720
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000721int GrPathUtils::chopCubicAtLoopIntersection(const SkPoint src[4], SkPoint dst[10], SkScalar klm[9],
722 SkScalar klm_rev[3]) {
723 // Variable to store the two parametric values at the loop double point
724 SkScalar smallS = 0.f;
725 SkScalar largeS = 0.f;
726
727 SkScalar d[3];
caryclark8dd31cf2014-12-12 09:11:23 -0800728 SkCubicType cType = SkClassifyCubic(src, d);
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000729
730 int chop_count = 0;
caryclark8dd31cf2014-12-12 09:11:23 -0800731 if (kLoop_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000732 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]);
733 SkScalar ls = d[1] - tempSqrt;
734 SkScalar lt = 2.f * d[0];
735 SkScalar ms = d[1] + tempSqrt;
736 SkScalar mt = 2.f * d[0];
737 ls = ls / lt;
738 ms = ms / mt;
739 // need to have t values sorted since this is what is expected by SkChopCubicAt
740 if (ls <= ms) {
741 smallS = ls;
742 largeS = ms;
743 } else {
744 smallS = ms;
745 largeS = ls;
746 }
747
748 SkScalar chop_ts[2];
749 if (smallS > 0.f && smallS < 1.f) {
750 chop_ts[chop_count++] = smallS;
751 }
752 if (largeS > 0.f && largeS < 1.f) {
753 chop_ts[chop_count++] = largeS;
754 }
755 if(dst) {
756 SkChopCubicAt(src, dst, chop_ts, chop_count);
757 }
758 } else {
759 if (dst) {
760 memcpy(dst, src, sizeof(SkPoint) * 4);
761 }
762 }
763
764 if (klm && klm_rev) {
765 // Set klm_rev to to match the sub_section of cubic that needs to have its orientation
766 // flipped. This will always be the section that is the "loop"
767 if (2 == chop_count) {
768 klm_rev[0] = 1.f;
769 klm_rev[1] = -1.f;
770 klm_rev[2] = 1.f;
771 } else if (1 == chop_count) {
772 if (smallS < 0.f) {
773 klm_rev[0] = -1.f;
774 klm_rev[1] = 1.f;
775 } else {
776 klm_rev[0] = 1.f;
777 klm_rev[1] = -1.f;
778 }
779 } else {
780 if (smallS < 0.f && largeS > 1.f) {
781 klm_rev[0] = -1.f;
782 } else {
783 klm_rev[0] = 1.f;
784 }
785 }
786 SkScalar controlK[4];
787 SkScalar controlL[4];
788 SkScalar controlM[4];
789
caryclark8dd31cf2014-12-12 09:11:23 -0800790 if (kSerpentine_SkCubicType == cType || (kCusp_SkCubicType == cType && 0.f != d[0])) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000791 set_serp_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800792 } else if (kLoop_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000793 set_loop_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800794 } else if (kCusp_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000795 SkASSERT(0.f == d[0]);
796 set_cusp_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800797 } else if (kQuadratic_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000798 set_quadratic_klm(d, controlK, controlL, controlM);
799 }
800
801 calc_cubic_klm(src, controlK, controlL, controlM, klm, &klm[3], &klm[6]);
802 }
803 return chop_count + 1;
804}
805
806void GrPathUtils::getCubicKLM(const SkPoint p[4], SkScalar klm[9]) {
807 SkScalar d[3];
caryclark8dd31cf2014-12-12 09:11:23 -0800808 SkCubicType cType = SkClassifyCubic(p, d);
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000809
810 SkScalar controlK[4];
811 SkScalar controlL[4];
812 SkScalar controlM[4];
813
caryclark8dd31cf2014-12-12 09:11:23 -0800814 if (kSerpentine_SkCubicType == cType || (kCusp_SkCubicType == cType && 0.f != d[0])) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000815 set_serp_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800816 } else if (kLoop_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000817 set_loop_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800818 } else if (kCusp_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000819 SkASSERT(0.f == d[0]);
820 set_cusp_klm(d, controlK, controlL, controlM);
caryclark8dd31cf2014-12-12 09:11:23 -0800821 } else if (kQuadratic_SkCubicType == cType) {
commit-bot@chromium.org858638d2013-08-20 14:45:45 +0000822 set_quadratic_klm(d, controlK, controlL, controlM);
823 }
824
825 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]);
826}