aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-02-02 17:45:56 -0800
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-03 15:19:05 +0000
commit0d7dac8fb8c404cada8d46646a980772b9dc55d6 (patch)
tree3aebab340b2369c39a02dbd50de770bdd2722c90 /tests
parent113628d76176a1ab3e6719c59efff23cd10ab213 (diff)
experimental tight-bounds
not sure about api -- perhaps it could just return the bounds, and make them 0,0,0,0 if the path is empty -- the caller can trivially know if the path is empty themselves. BUG=skia: Change-Id: I2dbb861e8d981b27c5a6833643977f5bd6802217 Reviewed-on: https://skia-review.googlesource.com/7989 Reviewed-by: Cary Clark <caryclark@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/PathTest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 7515d3e261..38bac25ba7 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -4700,3 +4700,55 @@ DEF_TEST(conservatively_contains_rect, reporter) {
// this guy should not assert
path.conservativelyContainsRect({ -211747, 12.1115f, -197893, 25.0321f });
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+static void rand_path(SkPath* path, SkRandom& rand, SkPath::Verb verb, int n) {
+ for (int i = 0; i < n; ++i) {
+ switch (verb) {
+ case SkPath::kLine_Verb:
+ path->lineTo(rand.nextF()*100, rand.nextF()*100);
+ break;
+ case SkPath::kQuad_Verb:
+ path->quadTo(rand.nextF()*100, rand.nextF()*100,
+ rand.nextF()*100, rand.nextF()*100);
+ break;
+ case SkPath::kConic_Verb:
+ path->conicTo(rand.nextF()*100, rand.nextF()*100,
+ rand.nextF()*100, rand.nextF()*100, rand.nextF()*10);
+ break;
+ case SkPath::kCubic_Verb:
+ path->cubicTo(rand.nextF()*100, rand.nextF()*100,
+ rand.nextF()*100, rand.nextF()*100,
+ rand.nextF()*100, rand.nextF()*100);
+ break;
+ default:
+ SkASSERT(false);
+ }
+ }
+}
+
+#include "SkPathOps.h"
+DEF_TEST(path_tight_bounds, reporter) {
+ SkRandom rand;
+
+ const SkPath::Verb verbs[] = {
+ SkPath::kLine_Verb, SkPath::kQuad_Verb, SkPath::kConic_Verb, SkPath::kCubic_Verb,
+ };
+ for (int i = 0; i < 1000; ++i) {
+ for (int n = 1; n <= 10; n += 9) {
+ for (SkPath::Verb verb : verbs) {
+ SkPath path;
+ rand_path(&path, rand, verb, n);
+ SkRect bounds = path.getBounds();
+ SkRect tight;
+ SkPathPriv::ComputeTightBounds(path, &tight);
+ REPORTER_ASSERT(reporter, bounds.contains(tight));
+
+ SkRect tight2;
+ TightBounds(path, &tight2);
+ REPORTER_ASSERT(reporter, nearly_equal(tight, tight2));
+ }
+ }
+ }
+}