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

Unified Diff: tests/PathOpsBoundsTest.cpp

Issue 12827020: Add base types for path ops (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pathops/SkPathOpsTypes.cpp ('k') | tests/PathOpsDCubicTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PathOpsBoundsTest.cpp
===================================================================
--- tests/PathOpsBoundsTest.cpp (revision 0)
+++ tests/PathOpsBoundsTest.cpp (revision 0)
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsBounds.h"
+#include "Test.h"
+
+static const SkRect sectTests[][2] = {
+ {{2, 0, 4, 1}, {4, 0, 6, 1}},
+ {{2, 0, 4, 1}, {3, 0, 5, 1}},
+ {{2, 0, 4, 1}, {3, 0, 5, 0}},
+ {{2, 0, 4, 1}, {3, 1, 5, 2}},
+ {{2, 1, 4, 2}, {1, 0, 5, 3}},
+ {{2, 1, 5, 3}, {3, 1, 4, 2}},
+ {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
+ {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
+};
+
+static const size_t sectTestsCount = sizeof(sectTests) / sizeof(sectTests[0]);
+
+static const SkRect noSectTests[][2] = {
+ {{2, 0, 4, 1}, {5, 0, 6, 1}},
+ {{2, 0, 4, 1}, {3, 2, 5, 2}},
+};
+
+static const size_t noSectTestsCount = sizeof(noSectTests) / sizeof(noSectTests[0]);
+
+static const SkRect reallyEmpty[] = {
+ {0, 0, 0, 0},
+ {1, 1, 1, 0},
+ {1, 1, 0, 1},
+ {1, 1, 0, 0},
+ {1, 2, 3, SK_ScalarNaN},
+};
+
+static const size_t emptyTestsCount = sizeof(reallyEmpty) / sizeof(reallyEmpty[0]);
+
+static const SkRect notReallyEmpty[] = {
+ {0, 0, 1, 0},
+ {0, 0, 0, 1},
+ {0, 0, 1, 1},
+};
+
+static const size_t notEmptyTestsCount = sizeof(notReallyEmpty) / sizeof(notReallyEmpty[0]);
+
+static void OpBoundsTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < sectTestsCount; ++index) {
+ const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
+ const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
+ bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
+ REPORTER_ASSERT(reporter, touches);
+ }
+ for (size_t index = 0; index < noSectTestsCount; ++index) {
+ const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
+ const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
+ bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
+ REPORTER_ASSERT(reporter, !touches);
+ }
+ SkPathOpsBounds bounds;
+ bounds.setEmpty();
+ bounds.add(1, 2, 3, 4);
+ SkPathOpsBounds expected;
+ expected.set(0, 0, 3, 4);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setEmpty();
+ SkPathOpsBounds ordinal;
+ ordinal.set(1, 2, 3, 4);
+ bounds.add(ordinal);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ SkPoint topLeft = {0, 0};
+ bounds.setPointBounds(topLeft);
+ SkPoint botRight = {3, 4};
+ bounds.add(botRight);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ for (size_t index = 0; index < emptyTestsCount; ++index) {
+ const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(reallyEmpty[index]);
+ bool empty = bounds.isReallyEmpty();
+ REPORTER_ASSERT(reporter, empty);
+ }
+ for (size_t index = 0; index < notEmptyTestsCount; ++index) {
+ const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notReallyEmpty[index]);
+ bool empty = bounds.isReallyEmpty();
+ REPORTER_ASSERT(reporter, !empty);
+ }
+ const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
+ bounds.setLineBounds(curvePts);
+ expected.set(0, 0, 1, 2);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[1])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setQuadBounds(curvePts);
+ expected.set(0, 0, 3, 4);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[2])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setCubicBounds(curvePts);
+ expected.set(0, 0, 5, 6);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[3])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsBounds", PathOpsBoundsClass, OpBoundsTest)
« no previous file with comments | « src/pathops/SkPathOpsTypes.cpp ('k') | tests/PathOpsDCubicTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698