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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkPathOpsTypes.cpp ('k') | tests/PathOpsDCubicTest.cpp » ('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 2013 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 #include "SkPathOpsBounds.h"
8 #include "Test.h"
9
10 static const SkRect sectTests[][2] = {
11 {{2, 0, 4, 1}, {4, 0, 6, 1}},
12 {{2, 0, 4, 1}, {3, 0, 5, 1}},
13 {{2, 0, 4, 1}, {3, 0, 5, 0}},
14 {{2, 0, 4, 1}, {3, 1, 5, 2}},
15 {{2, 1, 4, 2}, {1, 0, 5, 3}},
16 {{2, 1, 5, 3}, {3, 1, 4, 2}},
17 {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
18 {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
19 };
20
21 static const size_t sectTestsCount = sizeof(sectTests) / sizeof(sectTests[0]);
22
23 static const SkRect noSectTests[][2] = {
24 {{2, 0, 4, 1}, {5, 0, 6, 1}},
25 {{2, 0, 4, 1}, {3, 2, 5, 2}},
26 };
27
28 static const size_t noSectTestsCount = sizeof(noSectTests) / sizeof(noSectTests[ 0]);
29
30 static const SkRect reallyEmpty[] = {
31 {0, 0, 0, 0},
32 {1, 1, 1, 0},
33 {1, 1, 0, 1},
34 {1, 1, 0, 0},
35 {1, 2, 3, SK_ScalarNaN},
36 };
37
38 static const size_t emptyTestsCount = sizeof(reallyEmpty) / sizeof(reallyEmpty[0 ]);
39
40 static const SkRect notReallyEmpty[] = {
41 {0, 0, 1, 0},
42 {0, 0, 0, 1},
43 {0, 0, 1, 1},
44 };
45
46 static const size_t notEmptyTestsCount = sizeof(notReallyEmpty) / sizeof(notReal lyEmpty[0]);
47
48 static void OpBoundsTest(skiatest::Reporter* reporter) {
49 for (size_t index = 0; index < sectTestsCount; ++index) {
50 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sec tTests[index][0]);
51 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sec tTests[index][1]);
52 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
53 REPORTER_ASSERT(reporter, touches);
54 }
55 for (size_t index = 0; index < noSectTestsCount; ++index) {
56 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noS ectTests[index][0]);
57 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noS ectTests[index][1]);
58 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
59 REPORTER_ASSERT(reporter, !touches);
60 }
61 SkPathOpsBounds bounds;
62 bounds.setEmpty();
63 bounds.add(1, 2, 3, 4);
64 SkPathOpsBounds expected;
65 expected.set(0, 0, 3, 4);
66 REPORTER_ASSERT(reporter, bounds == expected);
67 bounds.setEmpty();
68 SkPathOpsBounds ordinal;
69 ordinal.set(1, 2, 3, 4);
70 bounds.add(ordinal);
71 REPORTER_ASSERT(reporter, bounds == expected);
72 SkPoint topLeft = {0, 0};
73 bounds.setPointBounds(topLeft);
74 SkPoint botRight = {3, 4};
75 bounds.add(botRight);
76 REPORTER_ASSERT(reporter, bounds == expected);
77 for (size_t index = 0; index < emptyTestsCount; ++index) {
78 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(real lyEmpty[index]);
79 bool empty = bounds.isReallyEmpty();
80 REPORTER_ASSERT(reporter, empty);
81 }
82 for (size_t index = 0; index < notEmptyTestsCount; ++index) {
83 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notR eallyEmpty[index]);
84 bool empty = bounds.isReallyEmpty();
85 REPORTER_ASSERT(reporter, !empty);
86 }
87 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
88 bounds.setLineBounds(curvePts);
89 expected.set(0, 0, 1, 2);
90 REPORTER_ASSERT(reporter, bounds == expected);
91 (bounds.*SetCurveBounds[1])(curvePts);
92 REPORTER_ASSERT(reporter, bounds == expected);
93 bounds.setQuadBounds(curvePts);
94 expected.set(0, 0, 3, 4);
95 REPORTER_ASSERT(reporter, bounds == expected);
96 (bounds.*SetCurveBounds[2])(curvePts);
97 REPORTER_ASSERT(reporter, bounds == expected);
98 bounds.setCubicBounds(curvePts);
99 expected.set(0, 0, 5, 6);
100 REPORTER_ASSERT(reporter, bounds == expected);
101 (bounds.*SetCurveBounds[3])(curvePts);
102 REPORTER_ASSERT(reporter, bounds == expected);
103 }
104
105 #include "TestClassDef.h"
106 DEFINE_TESTCLASS("PathOpsBounds", PathOpsBoundsClass, OpBoundsTest)
OLDNEW
« 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