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

Side by Side Diff: src/pathops/SkDCubicToQuads.cpp

Issue 16951017: convert pathops to use SkSTArray where possible. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: pathops use SkTArray Created 7 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkDCubicIntersection.cpp ('k') | src/pathops/SkDQuadIntersection.cpp » ('j') | 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 http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points -of-a-cubic-curve-to-the-single-control-poi 2 http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points -of-a-cubic-curve-to-the-single-control-poi
3 */ 3 */
4 4
5 /* 5 /*
6 Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2. 6 Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2.
7 Then for degree elevation, the equations are: 7 Then for degree elevation, the equations are:
8 8
9 Q0 = P0 9 Q0 = P0
10 Q1 = 1/3 P0 + 2/3 P1 10 Q1 = 1/3 P0 + 2/3 P1
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html 42 http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html
43 // maybe in turn derived from http://www.cccg.ca/proceedings/2004/36.pdf 43 // maybe in turn derived from http://www.cccg.ca/proceedings/2004/36.pdf
44 // also stored at http://www.cis.usouthal.edu/~hain/general/Publications/Bezier/ bezier%20cccg04%20paper.pdf 44 // also stored at http://www.cis.usouthal.edu/~hain/general/Publications/Bezier/ bezier%20cccg04%20paper.pdf
45 45
46 */ 46 */
47 47
48 #include "SkPathOpsCubic.h" 48 #include "SkPathOpsCubic.h"
49 #include "SkPathOpsLine.h" 49 #include "SkPathOpsLine.h"
50 #include "SkPathOpsQuad.h" 50 #include "SkPathOpsQuad.h"
51 #include "SkReduceOrder.h" 51 #include "SkReduceOrder.h"
52 #include "SkTDArray.h" 52 #include "SkTArray.h"
53 #include "SkTSort.h" 53 #include "SkTSort.h"
54 54
55 #define USE_CUBIC_END_POINTS 1 55 #define USE_CUBIC_END_POINTS 1
56 56
57 static double calc_t_div(const SkDCubic& cubic, double precision, double start) { 57 static double calc_t_div(const SkDCubic& cubic, double precision, double start) {
58 const double adjust = sqrt(3.) / 36; 58 const double adjust = sqrt(3.) / 36;
59 SkDCubic sub; 59 SkDCubic sub;
60 const SkDCubic* cPtr; 60 const SkDCubic* cPtr;
61 if (start == 0) { 61 if (start == 0) {
62 cPtr = &cubic; 62 cPtr = &cubic;
(...skipping 18 matching lines...) Expand all
81 SkDQuad quad; 81 SkDQuad quad;
82 quad[0] = fPts[0]; 82 quad[0] = fPts[0];
83 const SkDPoint fromC1 = {(3 * fPts[1].fX - fPts[0].fX) / 2, (3 * fPts[1].fY - fPts[0].fY) / 2}; 83 const SkDPoint fromC1 = {(3 * fPts[1].fX - fPts[0].fX) / 2, (3 * fPts[1].fY - fPts[0].fY) / 2};
84 const SkDPoint fromC2 = {(3 * fPts[2].fX - fPts[3].fX) / 2, (3 * fPts[2].fY - fPts[3].fY) / 2}; 84 const SkDPoint fromC2 = {(3 * fPts[2].fX - fPts[3].fX) / 2, (3 * fPts[2].fY - fPts[3].fY) / 2};
85 quad[1].fX = (fromC1.fX + fromC2.fX) / 2; 85 quad[1].fX = (fromC1.fX + fromC2.fX) / 2;
86 quad[1].fY = (fromC1.fY + fromC2.fY) / 2; 86 quad[1].fY = (fromC1.fY + fromC2.fY) / 2;
87 quad[2] = fPts[3]; 87 quad[2] = fPts[3];
88 return quad; 88 return quad;
89 } 89 }
90 90
91 static bool add_simple_ts(const SkDCubic& cubic, double precision, SkTDArray<dou ble>* ts) { 91 static bool add_simple_ts(const SkDCubic& cubic, double precision, SkTArray<doub le, true>* ts) {
92 double tDiv = calc_t_div(cubic, precision, 0); 92 double tDiv = calc_t_div(cubic, precision, 0);
93 if (tDiv >= 1) { 93 if (tDiv >= 1) {
94 return true; 94 return true;
95 } 95 }
96 if (tDiv >= 0.5) { 96 if (tDiv >= 0.5) {
97 *ts->append() = 0.5; 97 ts->push_back(0.5);
98 return true; 98 return true;
99 } 99 }
100 return false; 100 return false;
101 } 101 }
102 102
103 static void addTs(const SkDCubic& cubic, double precision, double start, double end, 103 static void addTs(const SkDCubic& cubic, double precision, double start, double end,
104 SkTDArray<double>* ts) { 104 SkTArray<double, true>* ts) {
105 double tDiv = calc_t_div(cubic, precision, 0); 105 double tDiv = calc_t_div(cubic, precision, 0);
106 double parts = ceil(1.0 / tDiv); 106 double parts = ceil(1.0 / tDiv);
107 for (double index = 0; index < parts; ++index) { 107 for (double index = 0; index < parts; ++index) {
108 double newT = start + (index / parts) * (end - start); 108 double newT = start + (index / parts) * (end - start);
109 if (newT > 0 && newT < 1) { 109 if (newT > 0 && newT < 1) {
110 *ts->append() = newT; 110 ts->push_back(newT);
111 } 111 }
112 } 112 }
113 } 113 }
114 114
115 // flavor that returns T values only, deferring computing the quads until they a re needed 115 // flavor that returns T values only, deferring computing the quads until they a re needed
116 // FIXME: when called from recursive intersect 2, this could take the original c ubic 116 // FIXME: when called from recursive intersect 2, this could take the original c ubic
117 // and do a more precise job when calling chop at and sub divide by computing th e fractional ts. 117 // and do a more precise job when calling chop at and sub divide by computing th e fractional ts.
118 // it would still take the prechopped cubic for reduce order and find cubic infl ections 118 // it would still take the prechopped cubic for reduce order and find cubic infl ections
119 void SkDCubic::toQuadraticTs(double precision, SkTDArray<double>* ts) const { 119 void SkDCubic::toQuadraticTs(double precision, SkTArray<double, true>* ts) const {
120 SkReduceOrder reducer; 120 SkReduceOrder reducer;
121 int order = reducer.reduce(*this, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style); 121 int order = reducer.reduce(*this, SkReduceOrder::kAllow_Quadratics, SkReduce Order::kFill_Style);
122 if (order < 3) { 122 if (order < 3) {
123 return; 123 return;
124 } 124 }
125 double inflectT[5]; 125 double inflectT[5];
126 int inflections = findInflections(inflectT); 126 int inflections = findInflections(inflectT);
127 SkASSERT(inflections <= 2); 127 SkASSERT(inflections <= 2);
128 if (!endsAreExtremaInXOrY()) { 128 if (!endsAreExtremaInXOrY()) {
129 inflections += findMaxCurvature(&inflectT[inflections]); 129 inflections += findMaxCurvature(&inflectT[inflections]);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for (int idx = 0; idx < last; ++idx) { 181 for (int idx = 0; idx < last; ++idx) {
182 part = subDivide(inflectT[idx], inflectT[idx + 1]); 182 part = subDivide(inflectT[idx], inflectT[idx + 1]);
183 addTs(part, precision, inflectT[idx], inflectT[idx + 1], ts); 183 addTs(part, precision, inflectT[idx], inflectT[idx + 1], ts);
184 } 184 }
185 part = subDivide(inflectT[last], 1); 185 part = subDivide(inflectT[last], 1);
186 addTs(part, precision, inflectT[last], 1, ts); 186 addTs(part, precision, inflectT[last], 1, ts);
187 return; 187 return;
188 } 188 }
189 addTs(*this, precision, 0, 1, ts); 189 addTs(*this, precision, 0, 1, ts);
190 } 190 }
OLDNEW
« no previous file with comments | « src/pathops/SkDCubicIntersection.cpp ('k') | src/pathops/SkDQuadIntersection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698