Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: src/gpu/GrPathUtils.cpp

Issue 1504983003: Loosen check for zero vectors in GrPathUtils::convert_noninflect_cubic_to_quads (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrPathUtils.h" 8 #include "GrPathUtils.h"
9 9
10 #include "GrTypes.h" 10 #include "GrTypes.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0, 126 uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0,
127 const SkPoint& p1, 127 const SkPoint& p1,
128 const SkPoint& p2, 128 const SkPoint& p2,
129 const SkPoint& p3, 129 const SkPoint& p3,
130 SkScalar tolSqd, 130 SkScalar tolSqd,
131 SkPoint** points, 131 SkPoint** points,
132 uint32_t pointsLeft) { 132 uint32_t pointsLeft) {
133 if (pointsLeft < 2 || 133 if (pointsLeft < 2 ||
134 (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd && 134 (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd &&
135 p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) { 135 p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) {
136 (*points)[0] = p3; 136 (*points)[0] = p3;
137 *points += 1; 137 *points += 1;
138 return 1; 138 return 1;
139 } 139 }
140 SkPoint q[] = { 140 SkPoint q[] = {
141 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) }, 141 { SkScalarAve(p0.fX, p1.fX), SkScalarAve(p0.fY, p1.fY) },
142 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) }, 142 { SkScalarAve(p1.fX, p2.fX), SkScalarAve(p1.fY, p2.fY) },
143 { SkScalarAve(p2.fX, p3.fX), SkScalarAve(p2.fY, p3.fY) } 143 { SkScalarAve(p2.fX, p3.fX), SkScalarAve(p2.fY, p3.fY) }
144 }; 144 };
145 SkPoint r[] = { 145 SkPoint r[] = {
146 { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) }, 146 { SkScalarAve(q[0].fX, q[1].fX), SkScalarAve(q[0].fY, q[1].fY) },
147 { SkScalarAve(q[1].fX, q[2].fX), SkScalarAve(q[1].fY, q[2].fY) } 147 { SkScalarAve(q[1].fX, q[2].fX), SkScalarAve(q[1].fY, q[2].fY) }
148 }; 148 };
149 SkPoint s = { SkScalarAve(r[0].fX, r[1].fX), SkScalarAve(r[0].fY, r[1].fY) } ; 149 SkPoint s = { SkScalarAve(r[0].fX, r[1].fX), SkScalarAve(r[0].fY, r[1].fY) } ;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 SkPathPriv::FirstDirection dir, 401 SkPathPriv::FirstDirection dir,
402 SkTArray<SkPoint, true>* quads, 402 SkTArray<SkPoint, true>* quads,
403 int sublevel = 0) { 403 int sublevel = 0) {
404 404
405 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in which case it is 405 // Notation: Point a is always p[0]. Point b is p[1] unless p[1] == p[0], in which case it is
406 // p[2]. Point d is always p[3]. Point c is p[2] unless p[2] == p[3], in whi ch case it is p[1]. 406 // p[2]. Point d is always p[3]. Point c is p[2] unless p[2] == p[3], in whi ch case it is p[1].
407 407
408 SkVector ab = p[1] - p[0]; 408 SkVector ab = p[1] - p[0];
409 SkVector dc = p[2] - p[3]; 409 SkVector dc = p[2] - p[3];
410 410
411 if (ab.isZero()) { 411 if (ab.lengthSqd() < SK_ScalarNearlyZero) {
412 if (dc.isZero()) { 412 if (dc.lengthSqd() < SK_ScalarNearlyZero) {
413 SkPoint* degQuad = quads->push_back_n(3); 413 SkPoint* degQuad = quads->push_back_n(3);
414 degQuad[0] = p[0]; 414 degQuad[0] = p[0];
415 degQuad[1] = p[0]; 415 degQuad[1] = p[0];
416 degQuad[2] = p[3]; 416 degQuad[2] = p[3];
417 return; 417 return;
418 } 418 }
419 ab = p[2] - p[0]; 419 ab = p[2] - p[0];
420 } 420 }
421 if (dc.isZero()) { 421 if (dc.lengthSqd() < SK_ScalarNearlyZero) {
422 dc = p[1] - p[3]; 422 dc = p[1] - p[3];
423 } 423 }
424 424
425 // When the ab and cd tangents are degenerate or nearly parallel with vector from d to a the 425 // When the ab and cd tangents are degenerate or nearly parallel with vector from d to a the
426 // constraint that the quad point falls between the tangents becomes hard to enforce and we are 426 // constraint that the quad point falls between the tangents becomes hard to enforce and we are
427 // likely to hit the max subdivision count. However, in this case the cubic is approaching a 427 // likely to hit the max subdivision count. However, in this case the cubic is approaching a
428 // line and the accuracy of the quad point isn't so important. We check if t he two middle cubic 428 // line and the accuracy of the quad point isn't so important. We check if t he two middle cubic
429 // control points are very close to the baseline vector. If so then we just pick quadratic 429 // control points are very close to the baseline vector. If so then we just pick quadratic
430 // points on the control polygon. 430 // points on the control polygon.
431 431
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 set_loop_klm(d, controlK, controlL, controlM); 807 set_loop_klm(d, controlK, controlL, controlM);
808 } else if (kCusp_SkCubicType == cType) { 808 } else if (kCusp_SkCubicType == cType) {
809 SkASSERT(0.f == d[0]); 809 SkASSERT(0.f == d[0]);
810 set_cusp_klm(d, controlK, controlL, controlM); 810 set_cusp_klm(d, controlK, controlL, controlM);
811 } else if (kQuadratic_SkCubicType == cType) { 811 } else if (kQuadratic_SkCubicType == cType) {
812 set_quadratic_klm(d, controlK, controlL, controlM); 812 set_quadratic_klm(d, controlK, controlL, controlM);
813 } 813 }
814 814
815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); 815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]);
816 } 816 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698