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/SkReduceOrder.cpp

Issue 85763002: remove unused reduce order code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkReduceOrder.h ('k') | tests/PathOpsCubicIntersectionTest.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 * 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 "SkReduceOrder.h" 7 #include "SkReduceOrder.h"
8 8
9 int SkReduceOrder::reduce(const SkDLine& line) { 9 int SkReduceOrder::reduce(const SkDLine& line) {
10 fLine[0] = line[0]; 10 fLine[0] = line[0];
11 int different = line[0] != line[1]; 11 int different = line[0] != line[1];
12 fLine[1] = line[different]; 12 fLine[1] = line[different];
13 return 1 + different; 13 return 1 + different;
14 } 14 }
15 15
16 static double interp_quad_coords(double a, double b, double c, double t) {
17 double ab = SkDInterp(a, b, t);
18 double bc = SkDInterp(b, c, t);
19 return SkDInterp(ab, bc, t);
20 }
21
22 static int coincident_line(const SkDQuad& quad, SkDQuad& reduction) { 16 static int coincident_line(const SkDQuad& quad, SkDQuad& reduction) {
23 reduction[0] = reduction[1] = quad[0]; 17 reduction[0] = reduction[1] = quad[0];
24 return 1; 18 return 1;
25 } 19 }
26 20
27 static int reductionLineCount(const SkDQuad& reduction) { 21 static int reductionLineCount(const SkDQuad& reduction) {
28 return 1 + !reduction[0].approximatelyEqual(reduction[1]); 22 return 1 + !reduction[0].approximatelyEqual(reduction[1]);
29 } 23 }
30 24
31 static int vertical_line(const SkDQuad& quad, SkReduceOrder::Style reduceStyle, 25 static int vertical_line(const SkDQuad& quad, SkDQuad& reduction) {
32 SkDQuad& reduction) {
33 double tValue;
34 reduction[0] = quad[0]; 26 reduction[0] = quad[0];
35 reduction[1] = quad[2]; 27 reduction[1] = quad[2];
36 if (reduceStyle == SkReduceOrder::kFill_Style) {
37 return reductionLineCount(reduction);
38 }
39 int smaller = reduction[1].fY > reduction[0].fY;
40 int larger = smaller ^ 1;
41 if (SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValue)) {
42 double yExtrema = interp_quad_coords(quad[0].fY, quad[1].fY, quad[2].fY, tValue);
43 if (reduction[smaller].fY > yExtrema) {
44 reduction[smaller].fY = yExtrema;
45 } else if (reduction[larger].fY < yExtrema) {
46 reduction[larger].fY = yExtrema;
47 }
48 }
49 return reductionLineCount(reduction); 28 return reductionLineCount(reduction);
50 } 29 }
51 30
52 static int horizontal_line(const SkDQuad& quad, SkReduceOrder::Style reduceStyle , 31 static int horizontal_line(const SkDQuad& quad, SkDQuad& reduction) {
53 SkDQuad& reduction) {
54 double tValue;
55 reduction[0] = quad[0]; 32 reduction[0] = quad[0];
56 reduction[1] = quad[2]; 33 reduction[1] = quad[2];
57 if (reduceStyle == SkReduceOrder::kFill_Style) {
58 return reductionLineCount(reduction);
59 }
60 int smaller = reduction[1].fX > reduction[0].fX;
61 int larger = smaller ^ 1;
62 if (SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, &tValue)) {
63 double xExtrema = interp_quad_coords(quad[0].fX, quad[1].fX, quad[2].fX, tValue);
64 if (reduction[smaller].fX > xExtrema) {
65 reduction[smaller].fX = xExtrema;
66 } else if (reduction[larger].fX < xExtrema) {
67 reduction[larger].fX = xExtrema;
68 }
69 }
70 return reductionLineCount(reduction); 34 return reductionLineCount(reduction);
71 } 35 }
72 36
73 static int check_linear(const SkDQuad& quad, SkReduceOrder::Style reduceStyle, 37 static int check_linear(const SkDQuad& quad,
74 int minX, int maxX, int minY, int maxY, SkDQuad& reduction) { 38 int minX, int maxX, int minY, int maxY, SkDQuad& reduction) {
75 int startIndex = 0; 39 int startIndex = 0;
76 int endIndex = 2; 40 int endIndex = 2;
77 while (quad[startIndex].approximatelyEqual(quad[endIndex])) { 41 while (quad[startIndex].approximatelyEqual(quad[endIndex])) {
78 --endIndex; 42 --endIndex;
79 if (endIndex == 0) { 43 if (endIndex == 0) {
80 SkDebugf("%s shouldn't get here if all four points are about equal", __FUNCTION__); 44 SkDebugf("%s shouldn't get here if all four points are about equal", __FUNCTION__);
81 SkASSERT(0); 45 SkASSERT(0);
82 } 46 }
83 } 47 }
84 if (!quad.isLinear(startIndex, endIndex)) { 48 if (!quad.isLinear(startIndex, endIndex)) {
85 return 0; 49 return 0;
86 } 50 }
87 // four are colinear: return line formed by outside 51 // four are colinear: return line formed by outside
88 reduction[0] = quad[0]; 52 reduction[0] = quad[0];
89 reduction[1] = quad[2]; 53 reduction[1] = quad[2];
90 if (reduceStyle == SkReduceOrder::kFill_Style) {
91 return reductionLineCount(reduction);
92 }
93 int sameSide;
94 bool useX = quad[maxX].fX - quad[minX].fX >= quad[maxY].fY - quad[minY].fY;
95 if (useX) {
96 sameSide = SkDSign(quad[0].fX - quad[1].fX) + SkDSign(quad[2].fX - quad[ 1].fX);
97 } else {
98 sameSide = SkDSign(quad[0].fY - quad[1].fY) + SkDSign(quad[2].fY - quad[ 1].fY);
99 }
100 if ((sameSide & 3) != 2) {
101 return reductionLineCount(reduction);
102 }
103 double tValue;
104 int root;
105 if (useX) {
106 root = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, &tValue) ;
107 } else {
108 root = SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValue) ;
109 }
110 if (root) {
111 SkDPoint extrema;
112 extrema.fX = interp_quad_coords(quad[0].fX, quad[1].fX, quad[2].fX, tVal ue);
113 extrema.fY = interp_quad_coords(quad[0].fY, quad[1].fY, quad[2].fY, tVal ue);
114 // sameSide > 0 means mid is smaller than either [0] or [2], so replace smaller
115 int replace;
116 if (useX) {
117 if ((extrema.fX < quad[0].fX) ^ (extrema.fX < quad[2].fX)) {
118 return reductionLineCount(reduction);
119 }
120 replace = ((extrema.fX < quad[0].fX) | (extrema.fX < quad[2].fX))
121 ^ (quad[0].fX < quad[2].fX);
122 } else {
123 if ((extrema.fY < quad[0].fY) ^ (extrema.fY < quad[2].fY)) {
124 return reductionLineCount(reduction);
125 }
126 replace = ((extrema.fY < quad[0].fY) | (extrema.fY < quad[2].fY))
127 ^ (quad[0].fY < quad[2].fY);
128 }
129 reduction[replace] = extrema;
130 }
131 return reductionLineCount(reduction); 54 return reductionLineCount(reduction);
132 } 55 }
133 56
134 // reduce to a quadratic or smaller 57 // reduce to a quadratic or smaller
135 // look for identical points 58 // look for identical points
136 // look for all four points in a line 59 // look for all four points in a line
137 // note that three points in a line doesn't simplify a cubic 60 // note that three points in a line doesn't simplify a cubic
138 // look for approximation with single quadratic 61 // look for approximation with single quadratic
139 // save approximation with multiple quadratics for later 62 // save approximation with multiple quadratics for later
140 int SkReduceOrder::reduce(const SkDQuad& quad, Style reduceStyle) { 63 int SkReduceOrder::reduce(const SkDQuad& quad) {
141 int index, minX, maxX, minY, maxY; 64 int index, minX, maxX, minY, maxY;
142 int minXSet, minYSet; 65 int minXSet, minYSet;
143 minX = maxX = minY = maxY = 0; 66 minX = maxX = minY = maxY = 0;
144 minXSet = minYSet = 0; 67 minXSet = minYSet = 0;
145 for (index = 1; index < 3; ++index) { 68 for (index = 1; index < 3; ++index) {
146 if (quad[minX].fX > quad[index].fX) { 69 if (quad[minX].fX > quad[index].fX) {
147 minX = index; 70 minX = index;
148 } 71 }
149 if (quad[minY].fY > quad[index].fY) { 72 if (quad[minY].fY > quad[index].fY) {
150 minY = index; 73 minY = index;
(...skipping 10 matching lines...) Expand all
161 minXSet |= 1 << index; 84 minXSet |= 1 << index;
162 } 85 }
163 if (AlmostEqualUlps(quad[index].fY, quad[minY].fY)) { 86 if (AlmostEqualUlps(quad[index].fY, quad[minY].fY)) {
164 minYSet |= 1 << index; 87 minYSet |= 1 << index;
165 } 88 }
166 } 89 }
167 if (minXSet == 0x7) { // test for vertical line 90 if (minXSet == 0x7) { // test for vertical line
168 if (minYSet == 0x7) { // return 1 if all four are coincident 91 if (minYSet == 0x7) { // return 1 if all four are coincident
169 return coincident_line(quad, fQuad); 92 return coincident_line(quad, fQuad);
170 } 93 }
171 return vertical_line(quad, reduceStyle, fQuad); 94 return vertical_line(quad, fQuad);
172 } 95 }
173 if (minYSet == 0xF) { // test for horizontal line 96 if (minYSet == 0xF) { // test for horizontal line
174 return horizontal_line(quad, reduceStyle, fQuad); 97 return horizontal_line(quad, fQuad);
175 } 98 }
176 int result = check_linear(quad, reduceStyle, minX, maxX, minY, maxY, fQuad); 99 int result = check_linear(quad, minX, maxX, minY, maxY, fQuad);
177 if (result) { 100 if (result) {
178 return result; 101 return result;
179 } 102 }
180 fQuad = quad; 103 fQuad = quad;
181 return 3; 104 return 3;
182 } 105 }
183 106
184 //////////////////////////////////////////////////////////////////////////////// //// 107 //////////////////////////////////////////////////////////////////////////////// ////
185 108
186 static double interp_cubic_coords(const double* src, double t) {
187 double ab = SkDInterp(src[0], src[2], t);
188 double bc = SkDInterp(src[2], src[4], t);
189 double cd = SkDInterp(src[4], src[6], t);
190 double abc = SkDInterp(ab, bc, t);
191 double bcd = SkDInterp(bc, cd, t);
192 return SkDInterp(abc, bcd, t);
193 }
194
195 static int coincident_line(const SkDCubic& cubic, SkDCubic& reduction) { 109 static int coincident_line(const SkDCubic& cubic, SkDCubic& reduction) {
196 reduction[0] = reduction[1] = cubic[0]; 110 reduction[0] = reduction[1] = cubic[0];
197 return 1; 111 return 1;
198 } 112 }
199 113
200 static int reductionLineCount(const SkDCubic& reduction) { 114 static int reductionLineCount(const SkDCubic& reduction) {
201 return 1 + !reduction[0].approximatelyEqual(reduction[1]); 115 return 1 + !reduction[0].approximatelyEqual(reduction[1]);
202 } 116 }
203 117
204 static int vertical_line(const SkDCubic& cubic, SkReduceOrder::Style reduceStyle , 118 static int vertical_line(const SkDCubic& cubic, SkDCubic& reduction) {
205 SkDCubic& reduction) {
206 double tValues[2];
207 reduction[0] = cubic[0]; 119 reduction[0] = cubic[0];
208 reduction[1] = cubic[3]; 120 reduction[1] = cubic[3];
209 if (reduceStyle == SkReduceOrder::kFill_Style) {
210 return reductionLineCount(reduction);
211 }
212 int smaller = reduction[1].fY > reduction[0].fY;
213 int larger = smaller ^ 1;
214 int roots = SkDCubic::FindExtrema(cubic[0].fY, cubic[1].fY, cubic[2].fY, cub ic[3].fY, tValues);
215 for (int index = 0; index < roots; ++index) {
216 double yExtrema = interp_cubic_coords(&cubic[0].fY, tValues[index]);
217 if (reduction[smaller].fY > yExtrema) {
218 reduction[smaller].fY = yExtrema;
219 continue;
220 }
221 if (reduction[larger].fY < yExtrema) {
222 reduction[larger].fY = yExtrema;
223 }
224 }
225 return reductionLineCount(reduction); 121 return reductionLineCount(reduction);
226 } 122 }
227 123
228 static int horizontal_line(const SkDCubic& cubic, SkReduceOrder::Style reduceSty le, 124 static int horizontal_line(const SkDCubic& cubic, SkDCubic& reduction) {
229 SkDCubic& reduction) {
230 double tValues[2];
231 reduction[0] = cubic[0]; 125 reduction[0] = cubic[0];
232 reduction[1] = cubic[3]; 126 reduction[1] = cubic[3];
233 if (reduceStyle == SkReduceOrder::kFill_Style) {
234 return reductionLineCount(reduction);
235 }
236 int smaller = reduction[1].fX > reduction[0].fX;
237 int larger = smaller ^ 1;
238 int roots = SkDCubic::FindExtrema(cubic[0].fX, cubic[1].fX, cubic[2].fX, cub ic[3].fX, tValues);
239 for (int index = 0; index < roots; ++index) {
240 double xExtrema = interp_cubic_coords(&cubic[0].fX, tValues[index]);
241 if (reduction[smaller].fX > xExtrema) {
242 reduction[smaller].fX = xExtrema;
243 continue;
244 }
245 if (reduction[larger].fX < xExtrema) {
246 reduction[larger].fX = xExtrema;
247 }
248 }
249 return reductionLineCount(reduction); 127 return reductionLineCount(reduction);
250 } 128 }
251 129
252 // check to see if it is a quadratic or a line 130 // check to see if it is a quadratic or a line
253 static int check_quadratic(const SkDCubic& cubic, SkDCubic& reduction) { 131 static int check_quadratic(const SkDCubic& cubic, SkDCubic& reduction) {
254 double dx10 = cubic[1].fX - cubic[0].fX; 132 double dx10 = cubic[1].fX - cubic[0].fX;
255 double dx23 = cubic[2].fX - cubic[3].fX; 133 double dx23 = cubic[2].fX - cubic[3].fX;
256 double midX = cubic[0].fX + dx10 * 3 / 2; 134 double midX = cubic[0].fX + dx10 * 3 / 2;
257 double sideAx = midX - cubic[3].fX; 135 double sideAx = midX - cubic[3].fX;
258 double sideBx = dx23 * 3 / 2; 136 double sideBx = dx23 * 3 / 2;
(...skipping 10 matching lines...) Expand all
269 : !AlmostEqualUlps(sideAy, sideBy)) { 147 : !AlmostEqualUlps(sideAy, sideBy)) {
270 return 0; 148 return 0;
271 } 149 }
272 reduction[0] = cubic[0]; 150 reduction[0] = cubic[0];
273 reduction[1].fX = midX; 151 reduction[1].fX = midX;
274 reduction[1].fY = midY; 152 reduction[1].fY = midY;
275 reduction[2] = cubic[3]; 153 reduction[2] = cubic[3];
276 return 3; 154 return 3;
277 } 155 }
278 156
279 static int check_linear(const SkDCubic& cubic, SkReduceOrder::Style reduceStyle, 157 static int check_linear(const SkDCubic& cubic,
280 int minX, int maxX, int minY, int maxY, SkDCubic& reduction) { 158 int minX, int maxX, int minY, int maxY, SkDCubic& reduction) {
281 int startIndex = 0; 159 int startIndex = 0;
282 int endIndex = 3; 160 int endIndex = 3;
283 while (cubic[startIndex].approximatelyEqual(cubic[endIndex])) { 161 while (cubic[startIndex].approximatelyEqual(cubic[endIndex])) {
284 --endIndex; 162 --endIndex;
285 if (endIndex == 0) { 163 if (endIndex == 0) {
286 SkDebugf("%s shouldn't get here if all four points are about equal\n ", __FUNCTION__); 164 SkDebugf("%s shouldn't get here if all four points are about equal\n ", __FUNCTION__);
287 SkASSERT(0); 165 SkASSERT(0);
288 } 166 }
289 } 167 }
290 if (!cubic.isLinear(startIndex, endIndex)) { 168 if (!cubic.isLinear(startIndex, endIndex)) {
291 return 0; 169 return 0;
292 } 170 }
293 // four are colinear: return line formed by outside 171 // four are colinear: return line formed by outside
294 reduction[0] = cubic[0]; 172 reduction[0] = cubic[0];
295 reduction[1] = cubic[3]; 173 reduction[1] = cubic[3];
296 if (reduceStyle == SkReduceOrder::kFill_Style) {
297 return reductionLineCount(reduction);
298 }
299 int sameSide1;
300 int sameSide2;
301 bool useX = cubic[maxX].fX - cubic[minX].fX >= cubic[maxY].fY - cubic[minY]. fY;
302 if (useX) {
303 sameSide1 = SkDSign(cubic[0].fX - cubic[1].fX) + SkDSign(cubic[3].fX - c ubic[1].fX);
304 sameSide2 = SkDSign(cubic[0].fX - cubic[2].fX) + SkDSign(cubic[3].fX - c ubic[2].fX);
305 } else {
306 sameSide1 = SkDSign(cubic[0].fY - cubic[1].fY) + SkDSign(cubic[3].fY - c ubic[1].fY);
307 sameSide2 = SkDSign(cubic[0].fY - cubic[2].fY) + SkDSign(cubic[3].fY - c ubic[2].fY);
308 }
309 if (sameSide1 == sameSide2 && (sameSide1 & 3) != 2) {
310 return reductionLineCount(reduction);
311 }
312 double tValues[2];
313 int roots;
314 if (useX) {
315 roots = SkDCubic::FindExtrema(cubic[0].fX, cubic[1].fX, cubic[2].fX, cub ic[3].fX, tValues);
316 } else {
317 roots = SkDCubic::FindExtrema(cubic[0].fY, cubic[1].fY, cubic[2].fY, cub ic[3].fY, tValues);
318 }
319 for (int index = 0; index < roots; ++index) {
320 SkDPoint extrema;
321 extrema.fX = interp_cubic_coords(&cubic[0].fX, tValues[index]);
322 extrema.fY = interp_cubic_coords(&cubic[0].fY, tValues[index]);
323 // sameSide > 0 means mid is smaller than either [0] or [3], so replace smaller
324 int replace;
325 if (useX) {
326 if ((extrema.fX < cubic[0].fX) ^ (extrema.fX < cubic[3].fX)) {
327 continue;
328 }
329 replace = ((extrema.fX < cubic[0].fX) | (extrema.fX < cubic[3].fX))
330 ^ (cubic[0].fX < cubic[3].fX);
331 } else {
332 if ((extrema.fY < cubic[0].fY) ^ (extrema.fY < cubic[3].fY)) {
333 continue;
334 }
335 replace = ((extrema.fY < cubic[0].fY) | (extrema.fY < cubic[3].fY))
336 ^ (cubic[0].fY < cubic[3].fY);
337 }
338 reduction[replace] = extrema;
339 }
340 return reductionLineCount(reduction); 174 return reductionLineCount(reduction);
341 } 175 }
342 176
343 /* food for thought: 177 /* food for thought:
344 http://objectmix.com/graphics/132906-fast-precision-driven-cubic-quadratic-piece wise-degree-reduction-algos-2-a.html 178 http://objectmix.com/graphics/132906-fast-precision-driven-cubic-quadratic-piece wise-degree-reduction-algos-2-a.html
345 179
346 Given points c1, c2, c3 and c4 of a cubic Bezier, the points of the 180 Given points c1, c2, c3 and c4 of a cubic Bezier, the points of the
347 corresponding quadratic Bezier are (given in convex combinations of 181 corresponding quadratic Bezier are (given in convex combinations of
348 points): 182 points):
349 183
350 q1 = (11/13)c1 + (3/13)c2 -(3/13)c3 + (2/13)c4 184 q1 = (11/13)c1 + (3/13)c2 -(3/13)c3 + (2/13)c4
351 q2 = -c1 + (3/2)c2 + (3/2)c3 - c4 185 q2 = -c1 + (3/2)c2 + (3/2)c3 - c4
352 q3 = (2/13)c1 - (3/13)c2 + (3/13)c3 + (11/13)c4 186 q3 = (2/13)c1 - (3/13)c2 + (3/13)c3 + (11/13)c4
353 187
354 Of course, this curve does not interpolate the end-points, but it would 188 Of course, this curve does not interpolate the end-points, but it would
355 be interesting to see the behaviour of such a curve in an applet. 189 be interesting to see the behaviour of such a curve in an applet.
356 190
357 -- 191 --
358 Kalle Rutanen 192 Kalle Rutanen
359 http://kaba.hilvi.org 193 http://kaba.hilvi.org
360 194
361 */ 195 */
362 196
363 // reduce to a quadratic or smaller 197 // reduce to a quadratic or smaller
364 // look for identical points 198 // look for identical points
365 // look for all four points in a line 199 // look for all four points in a line
366 // note that three points in a line doesn't simplify a cubic 200 // note that three points in a line doesn't simplify a cubic
367 // look for approximation with single quadratic 201 // look for approximation with single quadratic
368 // save approximation with multiple quadratics for later 202 // save approximation with multiple quadratics for later
369 int SkReduceOrder::reduce(const SkDCubic& cubic, Quadratics allowQuadratics, 203 int SkReduceOrder::reduce(const SkDCubic& cubic, Quadratics allowQuadratics) {
370 Style reduceStyle) {
371 int index, minX, maxX, minY, maxY; 204 int index, minX, maxX, minY, maxY;
372 int minXSet, minYSet; 205 int minXSet, minYSet;
373 minX = maxX = minY = maxY = 0; 206 minX = maxX = minY = maxY = 0;
374 minXSet = minYSet = 0; 207 minXSet = minYSet = 0;
375 for (index = 1; index < 4; ++index) { 208 for (index = 1; index < 4; ++index) {
376 if (cubic[minX].fX > cubic[index].fX) { 209 if (cubic[minX].fX > cubic[index].fX) {
377 minX = index; 210 minX = index;
378 } 211 }
379 if (cubic[minY].fY > cubic[index].fY) { 212 if (cubic[minY].fY > cubic[index].fY) {
380 minY = index; 213 minY = index;
(...skipping 20 matching lines...) Expand all
401 minXSet |= 1 << index; 234 minXSet |= 1 << index;
402 } 235 }
403 if (approximately_equal_half(cy * inv, cubic[minY].fY * inv)) { 236 if (approximately_equal_half(cy * inv, cubic[minY].fY * inv)) {
404 minYSet |= 1 << index; 237 minYSet |= 1 << index;
405 } 238 }
406 } 239 }
407 if (minXSet == 0xF) { // test for vertical line 240 if (minXSet == 0xF) { // test for vertical line
408 if (minYSet == 0xF) { // return 1 if all four are coincident 241 if (minYSet == 0xF) { // return 1 if all four are coincident
409 return coincident_line(cubic, fCubic); 242 return coincident_line(cubic, fCubic);
410 } 243 }
411 return vertical_line(cubic, reduceStyle, fCubic); 244 return vertical_line(cubic, fCubic);
412 } 245 }
413 if (minYSet == 0xF) { // test for horizontal line 246 if (minYSet == 0xF) { // test for horizontal line
414 return horizontal_line(cubic, reduceStyle, fCubic); 247 return horizontal_line(cubic, fCubic);
415 } 248 }
416 int result = check_linear(cubic, reduceStyle, minX, maxX, minY, maxY, fCubic ); 249 int result = check_linear(cubic, minX, maxX, minY, maxY, fCubic);
417 if (result) { 250 if (result) {
418 return result; 251 return result;
419 } 252 }
420 if (allowQuadratics == SkReduceOrder::kAllow_Quadratics 253 if (allowQuadratics == SkReduceOrder::kAllow_Quadratics
421 && (result = check_quadratic(cubic, fCubic))) { 254 && (result = check_quadratic(cubic, fCubic))) {
422 return result; 255 return result;
423 } 256 }
424 fCubic = cubic; 257 fCubic = cubic;
425 return 4; 258 return 4;
426 } 259 }
427 260
428 SkPath::Verb SkReduceOrder::Quad(const SkPoint a[3], SkPoint* reducePts) { 261 SkPath::Verb SkReduceOrder::Quad(const SkPoint a[3], SkPoint* reducePts) {
429 SkDQuad quad; 262 SkDQuad quad;
430 quad.set(a); 263 quad.set(a);
431 SkReduceOrder reducer; 264 SkReduceOrder reducer;
432 int order = reducer.reduce(quad, kFill_Style); 265 int order = reducer.reduce(quad);
433 if (order == 2) { // quad became line 266 if (order == 2) { // quad became line
434 for (int index = 0; index < order; ++index) { 267 for (int index = 0; index < order; ++index) {
435 *reducePts++ = reducer.fLine[index].asSkPoint(); 268 *reducePts++ = reducer.fLine[index].asSkPoint();
436 } 269 }
437 } 270 }
438 return SkPathOpsPointsToVerb(order - 1); 271 return SkPathOpsPointsToVerb(order - 1);
439 } 272 }
440 273
441 SkPath::Verb SkReduceOrder::Cubic(const SkPoint a[4], SkPoint* reducePts) { 274 SkPath::Verb SkReduceOrder::Cubic(const SkPoint a[4], SkPoint* reducePts) {
442 SkDCubic cubic; 275 SkDCubic cubic;
443 cubic.set(a); 276 cubic.set(a);
444 SkReduceOrder reducer; 277 SkReduceOrder reducer;
445 int order = reducer.reduce(cubic, kAllow_Quadratics, kFill_Style); 278 int order = reducer.reduce(cubic, kAllow_Quadratics);
446 if (order == 2 || order == 3) { // cubic became line or quad 279 if (order == 2 || order == 3) { // cubic became line or quad
447 for (int index = 0; index < order; ++index) { 280 for (int index = 0; index < order; ++index) {
448 *reducePts++ = reducer.fQuad[index].asSkPoint(); 281 *reducePts++ = reducer.fQuad[index].asSkPoint();
449 } 282 }
450 } 283 }
451 return SkPathOpsPointsToVerb(order - 1); 284 return SkPathOpsPointsToVerb(order - 1);
452 } 285 }
OLDNEW
« no previous file with comments | « src/pathops/SkReduceOrder.h ('k') | tests/PathOpsCubicIntersectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698