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 "SkGeometry.h" |
7 #include "SkReduceOrder.h" | 8 #include "SkReduceOrder.h" |
8 | 9 |
9 int SkReduceOrder::reduce(const SkDLine& line) { | 10 int SkReduceOrder::reduce(const SkDLine& line) { |
10 fLine[0] = line[0]; | 11 fLine[0] = line[0]; |
11 int different = line[0] != line[1]; | 12 int different = line[0] != line[1]; |
12 fLine[1] = line[different]; | 13 fLine[1] = line[different]; |
13 return 1 + different; | 14 return 1 + different; |
14 } | 15 } |
15 | 16 |
16 static int coincident_line(const SkDQuad& quad, SkDQuad& reduction) { | 17 static int coincident_line(const SkDQuad& quad, SkDQuad& reduction) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 SkReduceOrder reducer; | 249 SkReduceOrder reducer; |
249 int order = reducer.reduce(quad); | 250 int order = reducer.reduce(quad); |
250 if (order == 2) { // quad became line | 251 if (order == 2) { // quad became line |
251 for (int index = 0; index < order; ++index) { | 252 for (int index = 0; index < order; ++index) { |
252 *reducePts++ = reducer.fLine[index].asSkPoint(); | 253 *reducePts++ = reducer.fLine[index].asSkPoint(); |
253 } | 254 } |
254 } | 255 } |
255 return SkPathOpsPointsToVerb(order - 1); | 256 return SkPathOpsPointsToVerb(order - 1); |
256 } | 257 } |
257 | 258 |
258 SkPath::Verb SkReduceOrder::Conic(const SkPoint a[3], SkScalar weight, SkPoint*
reducePts) { | 259 SkPath::Verb SkReduceOrder::Conic(const SkConic& c, SkPoint* reducePts) { |
259 SkPath::Verb verb = SkReduceOrder::Quad(a, reducePts); | 260 SkPath::Verb verb = SkReduceOrder::Quad(c.fPts, reducePts); |
260 if (verb > SkPath::kLine_Verb && weight == 1) { | 261 if (verb > SkPath::kLine_Verb && c.fW == 1) { |
261 return SkPath::kQuad_Verb; | 262 return SkPath::kQuad_Verb; |
262 } | 263 } |
263 return verb == SkPath::kQuad_Verb ? SkPath::kConic_Verb : verb; | 264 return verb == SkPath::kQuad_Verb ? SkPath::kConic_Verb : verb; |
264 } | 265 } |
265 | 266 |
266 SkPath::Verb SkReduceOrder::Cubic(const SkPoint a[4], SkPoint* reducePts) { | 267 SkPath::Verb SkReduceOrder::Cubic(const SkPoint a[4], SkPoint* reducePts) { |
267 if (SkDPoint::ApproximatelyEqual(a[0], a[1]) && SkDPoint::ApproximatelyEqual
(a[0], a[2]) | 268 if (SkDPoint::ApproximatelyEqual(a[0], a[1]) && SkDPoint::ApproximatelyEqual
(a[0], a[2]) |
268 && SkDPoint::ApproximatelyEqual(a[0], a[3])) { | 269 && SkDPoint::ApproximatelyEqual(a[0], a[3])) { |
269 reducePts[0] = a[0]; | 270 reducePts[0] = a[0]; |
270 return SkPath::kMove_Verb; | 271 return SkPath::kMove_Verb; |
271 } | 272 } |
272 SkDCubic cubic; | 273 SkDCubic cubic; |
273 cubic.set(a); | 274 cubic.set(a); |
274 SkReduceOrder reducer; | 275 SkReduceOrder reducer; |
275 int order = reducer.reduce(cubic, kAllow_Quadratics); | 276 int order = reducer.reduce(cubic, kAllow_Quadratics); |
276 if (order == 2 || order == 3) { // cubic became line or quad | 277 if (order == 2 || order == 3) { // cubic became line or quad |
277 for (int index = 0; index < order; ++index) { | 278 for (int index = 0; index < order; ++index) { |
278 *reducePts++ = reducer.fQuad[index].asSkPoint(); | 279 *reducePts++ = reducer.fQuad[index].asSkPoint(); |
279 } | 280 } |
280 } | 281 } |
281 return SkPathOpsPointsToVerb(order - 1); | 282 return SkPathOpsPointsToVerb(order - 1); |
282 } | 283 } |
OLD | NEW |