2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "GrPathUtils.h"
11 #include "SkGeometry.h"
13 SkScalar GrPathUtils::scaleToleranceToSrc(SkScalar devTol,
14 const SkMatrix& viewM,
15 const SkRect& pathBounds) {
16 // In order to tesselate the path we get a bound on how much the matrix can
17 // stretch when mapping to screen coordinates.
18 SkScalar stretch = viewM.getMaxStretch();
19 SkScalar srcTol = devTol;
22 // take worst case mapRadius amoung four corners.
23 // (less than perfect)
24 for (int i = 0; i < 4; ++i) {
26 mat.setTranslate((i % 2) ? pathBounds.fLeft : pathBounds.fRight,
27 (i < 2) ? pathBounds.fTop : pathBounds.fBottom);
28 mat.postConcat(viewM);
29 stretch = SkMaxScalar(stretch, mat.mapRadius(SK_Scalar1));
32 srcTol = SkScalarDiv(srcTol, stretch);
36 static const int MAX_POINTS_PER_CURVE = 1 << 10;
37 static const SkScalar gMinCurveTol = SkFloatToScalar(0.0001f);
39 uint32_t GrPathUtils::quadraticPointCount(const GrPoint points[],
41 if (tol < gMinCurveTol) {
46 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]);
50 // Each time we subdivide, d should be cut in 4. So we need to
51 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x)
53 // 2^(log4(x)) = sqrt(x);
54 int temp = SkScalarCeil(SkScalarSqrt(SkScalarDiv(d, tol)));
55 int pow2 = GrNextPow2(temp);
56 // Because of NaNs & INFs we can wind up with a degenerate temp
57 // such that pow2 comes out negative. Also, our point generator
58 // will always output at least one pt.
62 return GrMin(pow2, MAX_POINTS_PER_CURVE);
66 uint32_t GrPathUtils::generateQuadraticPoints(const GrPoint& p0,
71 uint32_t pointsLeft) {
73 (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) {
80 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) },
81 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) },
83 GrPoint r = { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) };
86 uint32_t a = generateQuadraticPoints(p0, q[0], r, tolSqd, points, pointsLeft);
87 uint32_t b = generateQuadraticPoints(r, q[1], p2, tolSqd, points, pointsLeft);
91 uint32_t GrPathUtils::cubicPointCount(const GrPoint points[],
93 if (tol < gMinCurveTol) {
99 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]),
100 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3]));
105 int temp = SkScalarCeil(SkScalarSqrt(SkScalarDiv(d, tol)));
106 int pow2 = GrNextPow2(temp);
107 // Because of NaNs & INFs we can wind up with a degenerate temp
108 // such that pow2 comes out negative. Also, our point generator
109 // will always output at least one pt.
113 return GrMin(pow2, MAX_POINTS_PER_CURVE);
117 uint32_t GrPathUtils::generateCubicPoints(const GrPoint& p0,
123 uint32_t pointsLeft) {
124 if (pointsLeft < 2 ||
125 (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd &&
126 p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) {
132 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) },
133 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) },
134 { SkScalarAve(p2.fX, p3.fX), SkScalarAve(p2.fY, p3.fY) }
137 { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) },
138 { SkScalarAve(q[1].fX, q[2].fX), SkScalarAve(q[1].fY, q[2].fY) }
140 GrPoint s = { SkScalarAve(r[0].fX, r[1].fX), SkScalarAve(r[0].fY, r[1].fY) };
142 uint32_t a = generateCubicPoints(p0, q[0], r[0], s, tolSqd, points, pointsLeft);
143 uint32_t b = generateCubicPoints(s, r[1], q[2], p3, tolSqd, points, pointsLeft);
147 int GrPathUtils::worstCasePointCount(const SkPath& path, int* subpaths,
149 if (tol < gMinCurveTol) {
159 SkPath::Iter iter(path, false);
163 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
166 case SkPath::kLine_Verb:
169 case SkPath::kQuad_Verb:
170 pointCount += quadraticPointCount(pts, tol);
172 case SkPath::kCubic_Verb:
173 pointCount += cubicPointCount(pts, tol);
175 case SkPath::kMove_Verb:
189 void GrPathUtils::QuadUVMatrix::set(const GrPoint qPts[3]) {
190 // can't make this static, no cons :(
192 #ifndef SK_SCALAR_IS_FLOAT
193 GrCrash("Expected scalar is float.");
196 // We want M such that M * xy_pt = uv_pt
197 // We know M * control_pts = [0 1/2 1]
200 // We invert the control pt matrix and post concat to both sides to get M.
201 UVpts.setAll(0, SK_ScalarHalf, SK_Scalar1,
203 SkScalarToPersp(SK_Scalar1),
204 SkScalarToPersp(SK_Scalar1),
205 SkScalarToPersp(SK_Scalar1));
206 m.setAll(qPts[0].fX, qPts[1].fX, qPts[2].fX,
207 qPts[0].fY, qPts[1].fY, qPts[2].fY,
208 SkScalarToPersp(SK_Scalar1),
209 SkScalarToPersp(SK_Scalar1),
210 SkScalarToPersp(SK_Scalar1));
212 // The quad is degenerate. Hopefully this is rare. Find the pts that are
213 // farthest apart to compute a line (unless it is really a pt).
214 SkScalar maxD = qPts[0].distanceToSqd(qPts[1]);
216 SkScalar d = qPts[1].distanceToSqd(qPts[2]);
221 d = qPts[2].distanceToSqd(qPts[0]);
226 // We could have a tolerance here, not sure if it would improve anything
228 // Set the matrix to give (u = 0, v = distance_to_line)
229 GrVec lineVec = qPts[(maxEdge + 1)%3] - qPts[maxEdge];
230 // when looking from the point 0 down the line we want positive
231 // distances to be to the left. This matches the non-degenerate
233 lineVec.setOrthog(lineVec, GrPoint::kLeft_Side);
234 lineVec.dot(qPts[0]);
242 fM[5] = -lineVec.dot(qPts[maxEdge]);
244 // It's a point. It should cover zero area. Just set the matrix such
245 // that (u, v) will always be far away from the quad.
246 fM[0] = 0; fM[1] = 0; fM[2] = 100.f;
247 fM[3] = 0; fM[4] = 0; fM[5] = 100.f;
252 // The matrix should not have perspective.
253 SkDEBUGCODE(static const SkScalar gTOL = SkFloatToScalar(1.f / 100.f));
254 SkASSERT(SkScalarAbs(m.get(SkMatrix::kMPersp0)) < gTOL);
255 SkASSERT(SkScalarAbs(m.get(SkMatrix::kMPersp1)) < gTOL);
257 // It may not be normalized to have 1.0 in the bottom right
258 float m33 = m.get(SkMatrix::kMPersp2);
261 fM[0] = m33 * m.get(SkMatrix::kMScaleX);
262 fM[1] = m33 * m.get(SkMatrix::kMSkewX);
263 fM[2] = m33 * m.get(SkMatrix::kMTransX);
264 fM[3] = m33 * m.get(SkMatrix::kMSkewY);
265 fM[4] = m33 * m.get(SkMatrix::kMScaleY);
266 fM[5] = m33 * m.get(SkMatrix::kMTransY);
268 fM[0] = m.get(SkMatrix::kMScaleX);
269 fM[1] = m.get(SkMatrix::kMSkewX);
270 fM[2] = m.get(SkMatrix::kMTransX);
271 fM[3] = m.get(SkMatrix::kMSkewY);
272 fM[4] = m.get(SkMatrix::kMScaleY);
273 fM[5] = m.get(SkMatrix::kMTransY);
278 ////////////////////////////////////////////////////////////////////////////////
280 // k = (y2 - y0, x0 - x2, (x2 - x0)*y0 - (y2 - y0)*x0 )
281 // l = (2*w * (y1 - y0), 2*w * (x0 - x1), 2*w * (x1*y0 - x0*y1))
282 // m = (2*w * (y2 - y1), 2*w * (x1 - x2), 2*w * (x2*y1 - x1*y2))
283 void GrPathUtils::getConicKLM(const SkPoint p[3], const SkScalar weight, SkScalar klm[9]) {
284 const SkScalar w2 = 2.f * weight;
285 klm[0] = p[2].fY - p[0].fY;
286 klm[1] = p[0].fX - p[2].fX;
287 klm[2] = (p[2].fX - p[0].fX) * p[0].fY - (p[2].fY - p[0].fY) * p[0].fX;
289 klm[3] = w2 * (p[1].fY - p[0].fY);
290 klm[4] = w2 * (p[0].fX - p[1].fX);
291 klm[5] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY);
293 klm[6] = w2 * (p[2].fY - p[1].fY);
294 klm[7] = w2 * (p[1].fX - p[2].fX);
295 klm[8] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY);
297 // scale the max absolute value of coeffs to 10
298 SkScalar scale = 0.f;
299 for (int i = 0; i < 9; ++i) {
300 scale = SkMaxScalar(scale, SkScalarAbs(klm[i]));
302 SkASSERT(scale > 0.f);
303 scale = 10.f / scale;
304 for (int i = 0; i < 9; ++i) {
309 ////////////////////////////////////////////////////////////////////////////////
313 // a is the first control point of the cubic.
314 // ab is the vector from a to the second control point.
315 // dc is the vector from the fourth to the third control point.
316 // d is the fourth control point.
317 // p is the candidate quadratic control point.
318 // this assumes that the cubic doesn't inflect and is simple
319 bool is_point_within_cubic_tangents(const SkPoint& a,
323 SkPath::Direction dir,
326 SkScalar apXab = ap.cross(ab);
327 if (SkPath::kCW_Direction == dir) {
332 SkASSERT(SkPath::kCCW_Direction == dir);
339 SkScalar dpXdc = dp.cross(dc);
340 if (SkPath::kCW_Direction == dir) {
345 SkASSERT(SkPath::kCCW_Direction == dir);
353 void convert_noninflect_cubic_to_quads(const SkPoint p[4],
354 SkScalar toleranceSqd,
355 bool constrainWithinTangents,
356 SkPath::Direction dir,
357 SkTArray<SkPoint, true>* quads,
360 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in which case it is
361 // 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].
363 SkVector ab = p[1] - p[0];
364 SkVector dc = p[2] - p[3];
368 SkPoint* degQuad = quads->push_back_n(3);
380 // When the ab and cd tangents are nearly parallel with vector from d to a the constraint that
381 // the quad point falls between the tangents becomes hard to enforce and we are likely to hit
382 // the max subdivision count. However, in this case the cubic is approaching a line and the
383 // accuracy of the quad point isn't so important. We check if the two middle cubic control
384 // points are very close to the baseline vector. If so then we just pick quadratic points on the
387 if (constrainWithinTangents) {
388 SkVector da = p[0] - p[3];
389 SkScalar invDALengthSqd = da.lengthSqd();
390 if (invDALengthSqd > SK_ScalarNearlyZero) {
391 invDALengthSqd = SkScalarInvert(invDALengthSqd);
392 // cross(ab, da)^2/length(da)^2 == sqd distance from b to line from d to a.
393 // same goed for point c using vector cd.
394 SkScalar detABSqd = ab.cross(da);
395 detABSqd = SkScalarSquare(detABSqd);
396 SkScalar detDCSqd = dc.cross(da);
397 detDCSqd = SkScalarSquare(detDCSqd);
398 if (SkScalarMul(detABSqd, invDALengthSqd) < toleranceSqd &&
399 SkScalarMul(detDCSqd, invDALengthSqd) < toleranceSqd) {
400 SkPoint b = p[0] + ab;
401 SkPoint c = p[3] + dc;
403 mid.scale(SK_ScalarHalf);
404 // Insert two quadratics to cover the case when ab points away from d and/or dc
405 // points away from a.
406 if (SkVector::DotProduct(da, dc) < 0 || SkVector::DotProduct(ab,da) > 0) {
407 SkPoint* qpts = quads->push_back_n(6);
415 SkPoint* qpts = quads->push_back_n(3);
425 static const SkScalar kLengthScale = 3 * SK_Scalar1 / 2;
426 static const int kMaxSubdivs = 10;
428 ab.scale(kLengthScale);
429 dc.scale(kLengthScale);
431 // e0 and e1 are extrapolations along vectors ab and dc.
437 SkScalar dSqd = sublevel > kMaxSubdivs ? 0 : c0.distanceToSqd(c1);
438 if (dSqd < toleranceSqd) {
441 cAvg.scale(SK_ScalarHalf);
443 bool subdivide = false;
445 if (constrainWithinTangents &&
446 !is_point_within_cubic_tangents(p[0], ab, dc, p[3], dir, cAvg)) {
447 // choose a new cAvg that is the intersection of the two tangent lines.
449 SkScalar z0 = -ab.dot(p[0]);
451 SkScalar z1 = -dc.dot(p[3]);
452 cAvg.fX = SkScalarMul(ab.fY, z1) - SkScalarMul(z0, dc.fY);
453 cAvg.fY = SkScalarMul(z0, dc.fX) - SkScalarMul(ab.fX, z1);
454 SkScalar z = SkScalarMul(ab.fX, dc.fY) - SkScalarMul(ab.fY, dc.fX);
455 z = SkScalarInvert(z);
458 if (sublevel <= kMaxSubdivs) {
459 SkScalar d0Sqd = c0.distanceToSqd(cAvg);
460 SkScalar d1Sqd = c1.distanceToSqd(cAvg);
461 // We need to subdivide if d0 + d1 > tolerance but we have the sqd values. We know
462 // the distances and tolerance can't be negative.
463 // (d0 + d1)^2 > toleranceSqd
464 // d0Sqd + 2*d0*d1 + d1Sqd > toleranceSqd
465 SkScalar d0d1 = SkScalarSqrt(SkScalarMul(d0Sqd, d1Sqd));
466 subdivide = 2 * d0d1 + d0Sqd + d1Sqd > toleranceSqd;
470 SkPoint* pts = quads->push_back_n(3);
477 SkPoint choppedPts[7];
478 SkChopCubicAtHalf(p, choppedPts);
479 convert_noninflect_cubic_to_quads(choppedPts + 0,
481 constrainWithinTangents,
485 convert_noninflect_cubic_to_quads(choppedPts + 3,
487 constrainWithinTangents,
494 void GrPathUtils::convertCubicToQuads(const GrPoint p[4],
496 bool constrainWithinTangents,
497 SkPath::Direction dir,
498 SkTArray<SkPoint, true>* quads) {
500 int count = SkChopCubicAtInflections(p, chopped);
502 // base tolerance is 1 pixel.
503 static const SkScalar kTolerance = SK_Scalar1;
504 const SkScalar tolSqd = SkScalarSquare(SkScalarMul(tolScale, kTolerance));
506 for (int i = 0; i < count; ++i) {
507 SkPoint* cubic = chopped + 3*i;
508 convert_noninflect_cubic_to_quads(cubic, tolSqd, constrainWithinTangents, dir, quads);
513 ////////////////////////////////////////////////////////////////////////////////
516 kSerpentine_CubicType,
519 kQuadratic_CubicType,
524 // discr(I) = d0^2 * (3*d1^2 - 4*d0*d2)
526 // discr(I) > 0 Serpentine
529 // d0 = d1 = 0 Quadratic
530 // d0 = d1 = d2 = 0 Line
531 // p0 = p1 = p2 = p3 Point
532 static CubicType classify_cubic(const SkPoint p[4], const SkScalar d[3]) {
533 if (p[0] == p[1] && p[0] == p[2] && p[0] == p[3]) {
534 return kPoint_CubicType;
536 const SkScalar discr = d[0] * d[0] * (3.f * d[1] * d[1] - 4.f * d[0] * d[2]);
537 if (discr > SK_ScalarNearlyZero) {
538 return kSerpentine_CubicType;
539 } else if (discr < -SK_ScalarNearlyZero) {
540 return kLoop_CubicType;
542 if (0.f == d[0] && 0.f == d[1]) {
543 return (0.f == d[2] ? kLine_CubicType : kQuadratic_CubicType);
545 return kCusp_CubicType;
550 // Assumes the third component of points is 1.
551 // Calcs p0 . (p1 x p2)
552 static SkScalar calc_dot_cross_cubic(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2) {
553 const SkScalar xComp = p0.fX * (p1.fY - p2.fY);
554 const SkScalar yComp = p0.fY * (p2.fX - p1.fX);
555 const SkScalar wComp = p1.fX * p2.fY - p1.fY * p2.fX;
556 return (xComp + yComp + wComp);
559 // Solves linear system to extract klm
560 // P.K = k (similarly for l, m)
561 // Where P is matrix of control points
562 // K is coefficients for the line K
563 // k is vector of values of K evaluated at the control points
564 // Solving for K, thus K = P^(-1) . k
565 static void calc_cubic_klm(const SkPoint p[4], const SkScalar controlK[4],
566 const SkScalar controlL[4], const SkScalar controlM[4],
567 SkScalar k[3], SkScalar l[3], SkScalar m[3]) {
569 matrix.setAll(p[0].fX, p[0].fY, 1.f,
570 p[1].fX, p[1].fY, 1.f,
571 p[2].fX, p[2].fY, 1.f);
573 if (matrix.invert(&inverse)) {
574 inverse.mapHomogeneousPoints(k, controlK, 1);
575 inverse.mapHomogeneousPoints(l, controlL, 1);
576 inverse.mapHomogeneousPoints(m, controlM, 1);
581 static void set_serp_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
582 SkScalar tempSqrt = SkScalarSqrt(9.f * d[1] * d[1] - 12.f * d[0] * d[2]);
583 SkScalar ls = 3.f * d[1] - tempSqrt;
584 SkScalar lt = 6.f * d[0];
585 SkScalar ms = 3.f * d[1] + tempSqrt;
586 SkScalar mt = 6.f * d[0];
589 k[1] = (3.f * ls * ms - ls * mt - lt * ms) / 3.f;
590 k[2] = (lt * (mt - 2.f * ms) + ls * (3.f * ms - 2.f * mt)) / 3.f;
591 k[3] = (lt - ls) * (mt - ms);
594 const SkScalar lt_ls = lt - ls;
595 l[1] = ls * ls * lt_ls * -1.f;
596 l[2] = lt_ls * lt_ls * ls;
597 l[3] = -1.f * lt_ls * lt_ls * lt_ls;
600 const SkScalar mt_ms = mt - ms;
601 m[1] = ms * ms * mt_ms * -1.f;
602 m[2] = mt_ms * mt_ms * ms;
603 m[3] = -1.f * mt_ms * mt_ms * mt_ms;
605 // If d0 < 0 we need to flip the orientation of our curve
606 // This is done by negating the k and l values
607 // We want negative distance values to be on the inside
609 for (int i = 0; i < 4; ++i) {
616 static void set_loop_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
617 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]);
618 SkScalar ls = d[1] - tempSqrt;
619 SkScalar lt = 2.f * d[0];
620 SkScalar ms = d[1] + tempSqrt;
621 SkScalar mt = 2.f * d[0];
624 k[1] = (3.f * ls*ms - ls * mt - lt * ms) / 3.f;
625 k[2] = (lt * (mt - 2.f * ms) + ls * (3.f * ms - 2.f * mt)) / 3.f;
626 k[3] = (lt - ls) * (mt - ms);
629 l[1] = (ls * (ls * (mt - 3.f * ms) + 2.f * lt * ms))/-3.f;
630 l[2] = ((lt - ls) * (ls * (2.f * mt - 3.f * ms) + lt * ms))/3.f;
631 l[3] = -1.f * (lt - ls) * (lt - ls) * (mt - ms);
634 m[1] = (ms * (ls * (2.f * mt - 3.f * ms) + lt * ms))/-3.f;
635 m[2] = ((mt - ms) * (ls * (mt - 3.f * ms) + 2.f * lt * ms))/3.f;
636 m[3] = -1.f * (lt - ls) * (mt - ms) * (mt - ms);
639 // If (d0 < 0 && sign(k1) > 0) || (d0 > 0 && sign(k1) < 0),
640 // we need to flip the orientation of our curve.
641 // This is done by negating the k and l values
642 if ( (d[0] < 0 && k[1] > 0) || (d[0] > 0 && k[1] < 0)) {
643 for (int i = 0; i < 4; ++i) {
650 static void set_cusp_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
651 const SkScalar ls = d[2];
652 const SkScalar lt = 3.f * d[1];
655 k[1] = ls - lt / 3.f;
656 k[2] = ls - 2.f * lt / 3.f;
660 const SkScalar ls_lt = ls - lt;
661 l[1] = ls * ls * ls_lt;
662 l[2] = ls_lt * ls_lt * ls;
663 l[3] = ls_lt * ls_lt * ls_lt;
671 // For the case when a cubic is actually a quadratic
677 static void set_quadratic_klm(const SkScalar d[3], SkScalar k[4], SkScalar l[4], SkScalar m[4]) {
693 // If d2 < 0 we need to flip the orientation of our curve
694 // This is done by negating the k and l values
696 for (int i = 0; i < 4; ++i) {
703 // Calc coefficients of I(s,t) where roots of I are inflection points of curve
704 // I(s,t) = t*(3*d0*s^2 - 3*d1*s*t + d2*t^2)
705 // d0 = a1 - 2*a2+3*a3
708 // a1 = p0 . (p3 x p2)
709 // a2 = p1 . (p0 x p3)
710 // a3 = p2 . (p1 x p0)
711 // Places the values of d1, d2, d3 in array d passed in
712 static void calc_cubic_inflection_func(const SkPoint p[4], SkScalar d[3]) {
713 SkScalar a1 = calc_dot_cross_cubic(p[0], p[3], p[2]);
714 SkScalar a2 = calc_dot_cross_cubic(p[1], p[0], p[3]);
715 SkScalar a3 = calc_dot_cross_cubic(p[2], p[1], p[0]);
717 // need to scale a's or values in later calculations will grow to high
718 SkScalar max = SkScalarAbs(a1);
719 max = SkMaxScalar(max, SkScalarAbs(a2));
720 max = SkMaxScalar(max, SkScalarAbs(a3));
728 d[0] = d[1] - a2 + a1;
731 int GrPathUtils::chopCubicAtLoopIntersection(const SkPoint src[4], SkPoint dst[10], SkScalar klm[9],
732 SkScalar klm_rev[3]) {
733 // Variable to store the two parametric values at the loop double point
734 SkScalar smallS = 0.f;
735 SkScalar largeS = 0.f;
738 calc_cubic_inflection_func(src, d);
740 CubicType cType = classify_cubic(src, d);
743 if (kLoop_CubicType == cType) {
744 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]);
745 SkScalar ls = d[1] - tempSqrt;
746 SkScalar lt = 2.f * d[0];
747 SkScalar ms = d[1] + tempSqrt;
748 SkScalar mt = 2.f * d[0];
751 // need to have t values sorted since this is what is expected by SkChopCubicAt
761 if (smallS > 0.f && smallS < 1.f) {
762 chop_ts[chop_count++] = smallS;
764 if (largeS > 0.f && largeS < 1.f) {
765 chop_ts[chop_count++] = largeS;
768 SkChopCubicAt(src, dst, chop_ts, chop_count);
772 memcpy(dst, src, sizeof(SkPoint) * 4);
776 if (klm && klm_rev) {
777 // Set klm_rev to to match the sub_section of cubic that needs to have its orientation
778 // flipped. This will always be the section that is the "loop"
779 if (2 == chop_count) {
783 } else if (1 == chop_count) {
792 if (smallS < 0.f && largeS > 1.f) {
798 SkScalar controlK[4];
799 SkScalar controlL[4];
800 SkScalar controlM[4];
802 if (kSerpentine_CubicType == cType || (kCusp_CubicType == cType && 0.f != d[0])) {
803 set_serp_klm(d, controlK, controlL, controlM);
804 } else if (kLoop_CubicType == cType) {
805 set_loop_klm(d, controlK, controlL, controlM);
806 } else if (kCusp_CubicType == cType) {
807 SkASSERT(0.f == d[0]);
808 set_cusp_klm(d, controlK, controlL, controlM);
809 } else if (kQuadratic_CubicType == cType) {
810 set_quadratic_klm(d, controlK, controlL, controlM);
813 calc_cubic_klm(src, controlK, controlL, controlM, klm, &klm[3], &klm[6]);
815 return chop_count + 1;
818 void GrPathUtils::getCubicKLM(const SkPoint p[4], SkScalar klm[9]) {
820 calc_cubic_inflection_func(p, d);
822 CubicType cType = classify_cubic(p, d);
824 SkScalar controlK[4];
825 SkScalar controlL[4];
826 SkScalar controlM[4];
828 if (kSerpentine_CubicType == cType || (kCusp_CubicType == cType && 0.f != d[0])) {
829 set_serp_klm(d, controlK, controlL, controlM);
830 } else if (kLoop_CubicType == cType) {
831 set_loop_klm(d, controlK, controlL, controlM);
832 } else if (kCusp_CubicType == cType) {
833 SkASSERT(0.f == d[0]);
834 set_cusp_klm(d, controlK, controlL, controlM);
835 } else if (kQuadratic_CubicType == cType) {
836 set_quadratic_klm(d, controlK, controlL, controlM);
839 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]);