OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
8 #include "SkPathOpsBounds.h" | 8 #include "SkPathOpsBounds.h" |
9 #include "SkPathOpsCubic.h" | 9 #include "SkPathOpsCubic.h" |
10 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 double tStart = 0; | 22 double tStart = 0; |
23 for (int i1 = 0; i1 <= ts.count(); ++i1) { | 23 for (int i1 = 0; i1 <= ts.count(); ++i1) { |
24 const double tEnd = i1 < ts.count() ? ts[i1] : 1; | 24 const double tEnd = i1 < ts.count() ? ts[i1] : 1; |
25 SkDCubic part = cubic.subDivide(tStart, tEnd); | 25 SkDCubic part = cubic.subDivide(tStart, tEnd); |
26 SkDQuad quad = part.toQuad(); | 26 SkDQuad quad = part.toQuad(); |
27 quads.push_back(quad); | 27 quads.push_back(quad); |
28 tStart = tEnd; | 28 tStart = tEnd; |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
| 32 void CubicPathToQuads(const SkPath& cubicPath, SkPath* quadPath) { |
| 33 quadPath->reset(); |
| 34 SkDCubic cubic; |
| 35 SkTArray<SkDQuad, true> quads; |
| 36 SkPath::RawIter iter(cubicPath); |
| 37 uint8_t verb; |
| 38 SkPoint pts[4]; |
| 39 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 40 switch (verb) { |
| 41 case SkPath::kMove_Verb: |
| 42 quadPath->moveTo(pts[0].fX, pts[0].fY); |
| 43 continue; |
| 44 case SkPath::kLine_Verb: |
| 45 quadPath->lineTo(pts[1].fX, pts[1].fY); |
| 46 break; |
| 47 case SkPath::kQuad_Verb: |
| 48 quadPath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY); |
| 49 break; |
| 50 case SkPath::kCubic_Verb: |
| 51 quads.reset(); |
| 52 cubic.set(pts); |
| 53 CubicToQuads(cubic, cubic.calcPrecision(), quads); |
| 54 for (int index = 0; index < quads.count(); ++index) { |
| 55 SkPoint qPts[2] = { |
| 56 quads[index][1].asSkPoint(), |
| 57 quads[index][2].asSkPoint() |
| 58 }; |
| 59 quadPath->quadTo(qPts[0].fX, qPts[0].fY, qPts[1].fX, qPts[1]
.fY); |
| 60 } |
| 61 break; |
| 62 case SkPath::kClose_Verb: |
| 63 quadPath->close(); |
| 64 break; |
| 65 default: |
| 66 SkDEBUGFAIL("bad verb"); |
| 67 return; |
| 68 } |
| 69 } |
| 70 } |
| 71 |
| 72 void CubicPathToSimple(const SkPath& cubicPath, SkPath* simplePath) { |
| 73 simplePath->reset(); |
| 74 SkDCubic cubic; |
| 75 SkPath::RawIter iter(cubicPath); |
| 76 uint8_t verb; |
| 77 SkPoint pts[4]; |
| 78 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 79 switch (verb) { |
| 80 case SkPath::kMove_Verb: |
| 81 simplePath->moveTo(pts[0].fX, pts[0].fY); |
| 82 continue; |
| 83 case SkPath::kLine_Verb: |
| 84 simplePath->lineTo(pts[1].fX, pts[1].fY); |
| 85 break; |
| 86 case SkPath::kQuad_Verb: |
| 87 simplePath->quadTo(pts[1].fX, pts[1].fY, pts[2].fX, pts[2].fY); |
| 88 break; |
| 89 case SkPath::kCubic_Verb: { |
| 90 cubic.set(pts); |
| 91 double tInflects[2]; |
| 92 int inflections = cubic.findInflections(tInflects); |
| 93 if (inflections > 1 && tInflects[0] > tInflects[1]) { |
| 94 SkTSwap(tInflects[0], tInflects[1]); |
| 95 } |
| 96 double lo = 0; |
| 97 for (int index = 0; index <= inflections; ++index) { |
| 98 double hi = index < inflections ? tInflects[index] : 1; |
| 99 SkDCubic part = cubic.subDivide(lo, hi); |
| 100 SkPoint cPts[3]; |
| 101 cPts[0] = part[1].asSkPoint(); |
| 102 cPts[1] = part[2].asSkPoint(); |
| 103 cPts[2] = part[3].asSkPoint(); |
| 104 simplePath->cubicTo(cPts[0].fX, cPts[0].fY, cPts[1].fX, cPts
[1].fY, |
| 105 cPts[2].fX, cPts[2].fY); |
| 106 lo = hi; |
| 107 } |
| 108 break; |
| 109 } |
| 110 case SkPath::kClose_Verb: |
| 111 simplePath->close(); |
| 112 break; |
| 113 default: |
| 114 SkDEBUGFAIL("bad verb"); |
| 115 return; |
| 116 } |
| 117 } |
| 118 } |
| 119 |
32 static bool SkDoubleIsNaN(double x) { | 120 static bool SkDoubleIsNaN(double x) { |
33 return x != x; | 121 return x != x; |
34 } | 122 } |
35 | 123 |
36 bool ValidBounds(const SkPathOpsBounds& bounds) { | 124 bool ValidBounds(const SkPathOpsBounds& bounds) { |
37 if (SkScalarIsNaN(bounds.fLeft)) { | 125 if (SkScalarIsNaN(bounds.fLeft)) { |
38 return false; | 126 return false; |
39 } | 127 } |
40 if (SkScalarIsNaN(bounds.fTop)) { | 128 if (SkScalarIsNaN(bounds.fTop)) { |
41 return false; | 129 return false; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 188 } |
101 return true; | 189 return true; |
102 } | 190 } |
103 | 191 |
104 bool ValidVector(const SkDVector& v) { | 192 bool ValidVector(const SkDVector& v) { |
105 if (SkDoubleIsNaN(v.fX)) { | 193 if (SkDoubleIsNaN(v.fX)) { |
106 return false; | 194 return false; |
107 } | 195 } |
108 return !SkDoubleIsNaN(v.fY); | 196 return !SkDoubleIsNaN(v.fY); |
109 } | 197 } |
OLD | NEW |