Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 37 static const SkScalar gMinCurveTol = 0.0001f; | 37 static const SkScalar gMinCurveTol = 0.0001f; |
| 38 | 38 |
| 39 uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[], | 39 uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[], |
| 40 SkScalar tol) { | 40 SkScalar tol) { |
| 41 if (tol < gMinCurveTol) { | 41 if (tol < gMinCurveTol) { |
| 42 tol = gMinCurveTol; | 42 tol = gMinCurveTol; |
| 43 } | 43 } |
| 44 SkASSERT(tol > 0); | 44 SkASSERT(tol > 0); |
| 45 | 45 |
| 46 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); | 46 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); |
| 47 if (d <= tol) { | 47 if (d <= tol || !SkScalarIsFinite(d)) { |
|
jvanverth1
2015/01/30 20:48:02
Is this an issue? When are we getting a distance o
Stephen White
2015/01/30 21:36:47
There's an assert which triggers in GrNextPow2() b
| |
| 48 return 1; | 48 return 1; |
| 49 } else { | 49 } else { |
| 50 // Each time we subdivide, d should be cut in 4. So we need to | 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) | 51 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) |
| 52 // points. | 52 // points. |
| 53 // 2^(log4(x)) = sqrt(x); | 53 // 2^(log4(x)) = sqrt(x); |
| 54 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 54 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); |
| 55 int pow2 = GrNextPow2(temp); | 55 int pow2 = GrNextPow2(temp); |
| 56 // Because of NaNs & INFs we can wind up with a degenerate 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 | 57 // such that pow2 comes out negative. Also, our point generator |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 SkScalar tol) { | 92 SkScalar tol) { |
| 93 if (tol < gMinCurveTol) { | 93 if (tol < gMinCurveTol) { |
| 94 tol = gMinCurveTol; | 94 tol = gMinCurveTol; |
| 95 } | 95 } |
| 96 SkASSERT(tol > 0); | 96 SkASSERT(tol > 0); |
| 97 | 97 |
| 98 SkScalar d = SkTMax( | 98 SkScalar d = SkTMax( |
| 99 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), | 99 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), |
| 100 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); | 100 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); |
| 101 d = SkScalarSqrt(d); | 101 d = SkScalarSqrt(d); |
| 102 if (d <= tol) { | 102 if (d <= tol || !SkScalarIsFinite(d)) { |
| 103 return 1; | 103 return 1; |
| 104 } else { | 104 } else { |
| 105 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 105 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); |
| 106 int pow2 = GrNextPow2(temp); | 106 int pow2 = GrNextPow2(temp); |
| 107 // Because of NaNs & INFs we can wind up with a degenerate 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 | 108 // such that pow2 comes out negative. Also, our point generator |
| 109 // will always output at least one pt. | 109 // will always output at least one pt. |
| 110 if (pow2 < 1) { | 110 if (pow2 < 1) { |
| 111 pow2 = 1; | 111 pow2 = 1; |
| 112 } | 112 } |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 set_loop_klm(d, controlK, controlL, controlM); | 798 set_loop_klm(d, controlK, controlL, controlM); |
| 799 } else if (kCusp_SkCubicType == cType) { | 799 } else if (kCusp_SkCubicType == cType) { |
| 800 SkASSERT(0.f == d[0]); | 800 SkASSERT(0.f == d[0]); |
| 801 set_cusp_klm(d, controlK, controlL, controlM); | 801 set_cusp_klm(d, controlK, controlL, controlM); |
| 802 } else if (kQuadratic_SkCubicType == cType) { | 802 } else if (kQuadratic_SkCubicType == cType) { |
| 803 set_quadratic_klm(d, controlK, controlL, controlM); | 803 set_quadratic_klm(d, controlK, controlL, controlM); |
| 804 } | 804 } |
| 805 | 805 |
| 806 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 806 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); |
| 807 } | 807 } |
| OLD | NEW |