aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkPathOpsTightBounds.cpp
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2014-06-24 07:55:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-24 07:55:12 -0700
commita8d2ffb1c2e245ae06bdd1c20f34995ab8311cf6 (patch)
tree984b13bc13e5295edf0173b0d61adb630cb4f053 /src/pathops/SkPathOpsTightBounds.cpp
parent9ea53f93e79ba312c4b3943923450a8b4aa57c82 (diff)
add pathops tight bounds; conform path ops' gyp to unit tests
Implement path tight bounds using path ops machinery. This is not as efficient as it could be; for instance, internally, it creates a path ops structure more suited to intersection. If this shows up as a performance bottleneck, it could be improved. Fix path ops gyp files, which have fallen out of sync with other tests. R=mtklein@google.com, bsalomon@google.com TBR=mtklein BUG=skia:1712 Author: caryclark@google.com Review URL: https://codereview.chromium.org/348343002
Diffstat (limited to 'src/pathops/SkPathOpsTightBounds.cpp')
-rw-r--r--src/pathops/SkPathOpsTightBounds.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/pathops/SkPathOpsTightBounds.cpp b/src/pathops/SkPathOpsTightBounds.cpp
new file mode 100644
index 0000000000..0f63f396e7
--- /dev/null
+++ b/src/pathops/SkPathOpsTightBounds.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkOpEdgeBuilder.h"
+#include "SkPathOpsCommon.h"
+
+bool TightBounds(const SkPath& path, SkRect* result) {
+ // turn path into list of segments
+ SkTArray<SkOpContour> contours;
+ SkOpEdgeBuilder builder(path, contours);
+ if (!builder.finish()) {
+ return false;
+ }
+ SkTArray<SkOpContour*, true> contourList;
+ MakeContourList(contours, contourList, false, false);
+ SkOpContour** currentPtr = contourList.begin();
+ result->setEmpty();
+ if (!currentPtr) {
+ return true;
+ }
+ SkOpContour** listEnd = contourList.end();
+ SkOpContour* current = *currentPtr++;
+ SkPathOpsBounds bounds = current->bounds();
+ while (currentPtr != listEnd) {
+ current = *currentPtr++;
+ bounds.add(current->bounds());
+ }
+ *result = bounds;
+ return true;
+}