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

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

Issue 853223002: new files for pathops geometric intersection (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove visualizer tool so cl contains only pure adds Created 5 years, 11 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
« no previous file with comments | « no previous file | src/pathops/SkOpCoincidence.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkMatrix.h"
9 #include "SkPath.h"
10 #include "SkPathOps.h"
11
12 void SkOpBuilder::add(const SkPath& path, SkPathOp op) {
13 if (0 == fOps.count() && op != kUnion_PathOp) {
14 fPathRefs.push_back() = SkPath();
15 *fOps.append() = kUnion_PathOp;
16 }
17 fPathRefs.push_back() = path;
18 *fOps.append() = op;
19 }
20
21 void SkOpBuilder::reset() {
22 fPathRefs.reset();
23 fOps.reset();
24 }
25
26 /* OPTIMIZATION: Union doesn't need to be all-or-nothing. A run of three or more convex
27 paths with union ops could be locally resolved and still improve over doing t he
28 ops one at a time. */
29 bool SkOpBuilder::resolve(SkPath* result) {
30 int count = fOps.count();
31 bool allUnion = true;
32 SkPath::Direction firstDir;
33 for (int index = 0; index < count; ++index) {
34 SkPath* test = &fPathRefs[index];
35 if (kUnion_PathOp != fOps[index] || test->isInverseFillType()) {
36 allUnion = false;
37 break;
38 }
39 // If all paths are convex, track direction, reversing as needed.
40 if (test->isConvex()) {
41 SkPath::Direction dir;
42 if (!test->cheapComputeDirection(&dir)) {
43 allUnion = false;
44 break;
45 }
46 if (index == 0) {
47 firstDir = dir;
48 } else if (firstDir != dir) {
49 SkPath temp;
50 temp.reverseAddPath(*test);
51 *test = temp;
52 }
53 continue;
54 }
55 // If the path is not convex but its bounds do not intersect the others, simplify is enough.
56 const SkRect& testBounds = test->getBounds();
57 for (int inner = 0; inner < index; ++inner) {
58 // OPTIMIZE: check to see if the contour bounds do not intersect oth er contour bounds?
59 if (SkRect::Intersects(fPathRefs[inner].getBounds(), testBounds)) {
60 allUnion = false;
61 break;
62 }
63 }
64 }
65 if (!allUnion) {
66 *result = fPathRefs[0];
67 for (int index = 1; index < count; ++index) {
68 if (!Op(*result, fPathRefs[index], fOps[index], result)) {
69 reset();
70 return false;
71 }
72 }
73 reset();
74 return true;
75 }
76 SkPath sum;
77 for (int index = 0; index < count; ++index) {
78 if (!Simplify(fPathRefs[index], &fPathRefs[index])) {
79 reset();
80 return false;
81 }
82 sum.addPath(fPathRefs[index]);
83 }
84 reset();
85 return Simplify(sum, result);
86 }
OLDNEW
« no previous file with comments | « no previous file | src/pathops/SkOpCoincidence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698