| 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 28 matching lines...) Expand all Loading... |
| 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) { |
| 48 return 1; | 48 return 1; |
| 49 } else if (!SkScalarIsFinite(d)) { |
| 50 return MAX_POINTS_PER_CURVE; |
| 49 } else { | 51 } else { |
| 50 // Each time we subdivide, d should be cut in 4. So we need to | 52 // 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 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) |
| 52 // points. | 54 // points. |
| 53 // 2^(log4(x)) = sqrt(x); | 55 // 2^(log4(x)) = sqrt(x); |
| 54 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 56 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); |
| 55 int pow2 = GrNextPow2(temp); | 57 int pow2 = GrNextPow2(temp); |
| 56 // Because of NaNs & INFs we can wind up with a degenerate temp | 58 // Because of NaNs & INFs we can wind up with a degenerate temp |
| 57 // such that pow2 comes out negative. Also, our point generator | 59 // such that pow2 comes out negative. Also, our point generator |
| 58 // will always output at least one pt. | 60 // will always output at least one pt. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 tol = gMinCurveTol; | 96 tol = gMinCurveTol; |
| 95 } | 97 } |
| 96 SkASSERT(tol > 0); | 98 SkASSERT(tol > 0); |
| 97 | 99 |
| 98 SkScalar d = SkTMax( | 100 SkScalar d = SkTMax( |
| 99 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), | 101 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), |
| 100 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); | 102 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); |
| 101 d = SkScalarSqrt(d); | 103 d = SkScalarSqrt(d); |
| 102 if (d <= tol) { | 104 if (d <= tol) { |
| 103 return 1; | 105 return 1; |
| 106 } else if (!SkScalarIsFinite(d)) { |
| 107 return MAX_POINTS_PER_CURVE; |
| 104 } else { | 108 } else { |
| 105 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 109 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); |
| 106 int pow2 = GrNextPow2(temp); | 110 int pow2 = GrNextPow2(temp); |
| 107 // Because of NaNs & INFs we can wind up with a degenerate temp | 111 // Because of NaNs & INFs we can wind up with a degenerate temp |
| 108 // such that pow2 comes out negative. Also, our point generator | 112 // such that pow2 comes out negative. Also, our point generator |
| 109 // will always output at least one pt. | 113 // will always output at least one pt. |
| 110 if (pow2 < 1) { | 114 if (pow2 < 1) { |
| 111 pow2 = 1; | 115 pow2 = 1; |
| 112 } | 116 } |
| 113 return SkTMin(pow2, MAX_POINTS_PER_CURVE); | 117 return SkTMin(pow2, MAX_POINTS_PER_CURVE); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 set_loop_klm(d, controlK, controlL, controlM); | 802 set_loop_klm(d, controlK, controlL, controlM); |
| 799 } else if (kCusp_SkCubicType == cType) { | 803 } else if (kCusp_SkCubicType == cType) { |
| 800 SkASSERT(0.f == d[0]); | 804 SkASSERT(0.f == d[0]); |
| 801 set_cusp_klm(d, controlK, controlL, controlM); | 805 set_cusp_klm(d, controlK, controlL, controlM); |
| 802 } else if (kQuadratic_SkCubicType == cType) { | 806 } else if (kQuadratic_SkCubicType == cType) { |
| 803 set_quadratic_klm(d, controlK, controlL, controlM); | 807 set_quadratic_klm(d, controlK, controlL, controlM); |
| 804 } | 808 } |
| 805 | 809 |
| 806 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 810 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); |
| 807 } | 811 } |
| OLD | NEW |