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 "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]; |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 static int horizontal_line(const SkDQuad& quad, SkDQuad& reduction) { | 31 static int horizontal_line(const SkDQuad& quad, SkDQuad& reduction) { |
32 reduction[0] = quad[0]; | 32 reduction[0] = quad[0]; |
33 reduction[1] = quad[2]; | 33 reduction[1] = quad[2]; |
34 return reductionLineCount(reduction); | 34 return reductionLineCount(reduction); |
35 } | 35 } |
36 | 36 |
37 static int check_linear(const SkDQuad& quad, | 37 static int check_linear(const SkDQuad& quad, |
38 int minX, int maxX, int minY, int maxY, SkDQuad& reduction) { | 38 int minX, int maxX, int minY, int maxY, SkDQuad& reduction) { |
39 int startIndex = 0; | 39 if (!quad.isLinear(0, 2)) { |
40 int endIndex = 2; | |
41 while (quad[startIndex].approximatelyEqual(quad[endIndex])) { | |
42 --endIndex; | |
43 if (endIndex == 0) { | |
44 SkDebugf("%s shouldn't get here if all four points are about equal",
__FUNCTION__); | |
45 SkASSERT(0); | |
46 } | |
47 } | |
48 if (!quad.isLinear(startIndex, endIndex)) { | |
49 return 0; | 40 return 0; |
50 } | 41 } |
51 // four are colinear: return line formed by outside | 42 // four are colinear: return line formed by outside |
52 reduction[0] = quad[0]; | 43 reduction[0] = quad[0]; |
53 reduction[1] = quad[2]; | 44 reduction[1] = quad[2]; |
54 return reductionLineCount(reduction); | 45 return reductionLineCount(reduction); |
55 } | 46 } |
56 | 47 |
57 // reduce to a quadratic or smaller | 48 // reduce to a quadratic or smaller |
58 // look for identical points | 49 // look for identical points |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 140 } |
150 reduction[0] = cubic[0]; | 141 reduction[0] = cubic[0]; |
151 reduction[1].fX = midX; | 142 reduction[1].fX = midX; |
152 reduction[1].fY = midY; | 143 reduction[1].fY = midY; |
153 reduction[2] = cubic[3]; | 144 reduction[2] = cubic[3]; |
154 return 3; | 145 return 3; |
155 } | 146 } |
156 | 147 |
157 static int check_linear(const SkDCubic& cubic, | 148 static int check_linear(const SkDCubic& cubic, |
158 int minX, int maxX, int minY, int maxY, SkDCubic& reduction) { | 149 int minX, int maxX, int minY, int maxY, SkDCubic& reduction) { |
159 int startIndex = 0; | 150 if (!cubic.isLinear(0, 3)) { |
160 int endIndex = 3; | |
161 while (cubic[startIndex].approximatelyEqual(cubic[endIndex])) { | |
162 --endIndex; | |
163 if (endIndex == 0) { | |
164 endIndex = 3; | |
165 break; | |
166 } | |
167 } | |
168 if (!cubic.isLinear(startIndex, endIndex)) { | |
169 return 0; | 151 return 0; |
170 } | 152 } |
171 // four are colinear: return line formed by outside | 153 // four are colinear: return line formed by outside |
172 reduction[0] = cubic[0]; | 154 reduction[0] = cubic[0]; |
173 reduction[1] = cubic[3]; | 155 reduction[1] = cubic[3]; |
174 return reductionLineCount(reduction); | 156 return reductionLineCount(reduction); |
175 } | 157 } |
176 | 158 |
177 /* food for thought: | 159 /* food for thought: |
178 http://objectmix.com/graphics/132906-fast-precision-driven-cubic-quadratic-piece
wise-degree-reduction-algos-2-a.html | 160 http://objectmix.com/graphics/132906-fast-precision-driven-cubic-quadratic-piece
wise-degree-reduction-algos-2-a.html |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 cubic.set(a); | 271 cubic.set(a); |
290 SkReduceOrder reducer; | 272 SkReduceOrder reducer; |
291 int order = reducer.reduce(cubic, kAllow_Quadratics); | 273 int order = reducer.reduce(cubic, kAllow_Quadratics); |
292 if (order == 2 || order == 3) { // cubic became line or quad | 274 if (order == 2 || order == 3) { // cubic became line or quad |
293 for (int index = 0; index < order; ++index) { | 275 for (int index = 0; index < order; ++index) { |
294 *reducePts++ = reducer.fQuad[index].asSkPoint(); | 276 *reducePts++ = reducer.fQuad[index].asSkPoint(); |
295 } | 277 } |
296 } | 278 } |
297 return SkPathOpsPointsToVerb(order - 1); | 279 return SkPathOpsPointsToVerb(order - 1); |
298 } | 280 } |
OLD | NEW |