OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
| 7 #include "PathOpsTestCommon.h" |
7 #include "SkPathOpsBounds.h" | 8 #include "SkPathOpsBounds.h" |
8 #include "Test.h" | 9 #include "Test.h" |
9 | 10 |
10 static const SkRect sectTests[][2] = { | 11 static const SkRect sectTests[][2] = { |
11 {{2, 0, 4, 1}, {4, 0, 6, 1}}, | 12 {{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, 1}}, |
13 {{2, 0, 4, 1}, {3, 0, 5, 0}}, | 14 {{2, 0, 4, 1}, {3, 0, 5, 0}}, |
14 {{2, 0, 4, 1}, {3, 1, 5, 2}}, | 15 {{2, 0, 4, 1}, {3, 1, 5, 2}}, |
15 {{2, 1, 4, 2}, {1, 0, 5, 3}}, | 16 {{2, 1, 4, 2}, {1, 0, 5, 3}}, |
16 {{2, 1, 5, 3}, {3, 1, 4, 2}}, | 17 {{2, 1, 5, 3}, {3, 1, 4, 2}}, |
(...skipping 24 matching lines...) Expand all Loading... |
41 {0, 0, 1, 0}, | 42 {0, 0, 1, 0}, |
42 {0, 0, 0, 1}, | 43 {0, 0, 0, 1}, |
43 {0, 0, 1, 1}, | 44 {0, 0, 1, 1}, |
44 }; | 45 }; |
45 | 46 |
46 static const size_t notEmptyTestsCount = SK_ARRAY_COUNT(notReallyEmpty); | 47 static const size_t notEmptyTestsCount = SK_ARRAY_COUNT(notReallyEmpty); |
47 | 48 |
48 static void PathOpsBoundsTest(skiatest::Reporter* reporter) { | 49 static void PathOpsBoundsTest(skiatest::Reporter* reporter) { |
49 for (size_t index = 0; index < sectTestsCount; ++index) { | 50 for (size_t index = 0; index < sectTestsCount; ++index) { |
50 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][0]); | 51 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][0]); |
| 52 SkASSERT(ValidBounds(bounds1)); |
51 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][1]); | 53 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sec
tTests[index][1]); |
| 54 SkASSERT(ValidBounds(bounds2)); |
52 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); | 55 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
53 REPORTER_ASSERT(reporter, touches); | 56 REPORTER_ASSERT(reporter, touches); |
54 } | 57 } |
55 for (size_t index = 0; index < noSectTestsCount; ++index) { | 58 for (size_t index = 0; index < noSectTestsCount; ++index) { |
56 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][0]); | 59 const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][0]); |
| 60 SkASSERT(ValidBounds(bounds1)); |
57 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][1]); | 61 const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noS
ectTests[index][1]); |
| 62 SkASSERT(ValidBounds(bounds2)); |
58 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); | 63 bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
59 REPORTER_ASSERT(reporter, !touches); | 64 REPORTER_ASSERT(reporter, !touches); |
60 } | 65 } |
61 SkPathOpsBounds bounds; | 66 SkPathOpsBounds bounds; |
62 bounds.setEmpty(); | 67 bounds.setEmpty(); |
63 bounds.add(1, 2, 3, 4); | 68 bounds.add(1, 2, 3, 4); |
64 SkPathOpsBounds expected; | 69 SkPathOpsBounds expected; |
65 expected.set(0, 0, 3, 4); | 70 expected.set(0, 0, 3, 4); |
66 REPORTER_ASSERT(reporter, bounds == expected); | 71 REPORTER_ASSERT(reporter, bounds == expected); |
67 bounds.setEmpty(); | 72 bounds.setEmpty(); |
68 SkPathOpsBounds ordinal; | 73 SkPathOpsBounds ordinal; |
69 ordinal.set(1, 2, 3, 4); | 74 ordinal.set(1, 2, 3, 4); |
70 bounds.add(ordinal); | 75 bounds.add(ordinal); |
71 REPORTER_ASSERT(reporter, bounds == expected); | 76 REPORTER_ASSERT(reporter, bounds == expected); |
72 SkPoint topLeft = {0, 0}; | 77 SkPoint topLeft = {0, 0}; |
73 bounds.setPointBounds(topLeft); | 78 bounds.setPointBounds(topLeft); |
74 SkPoint botRight = {3, 4}; | 79 SkPoint botRight = {3, 4}; |
75 bounds.add(botRight); | 80 bounds.add(botRight); |
76 REPORTER_ASSERT(reporter, bounds == expected); | 81 REPORTER_ASSERT(reporter, bounds == expected); |
77 for (size_t index = 0; index < emptyTestsCount; ++index) { | 82 for (size_t index = 0; index < emptyTestsCount; ++index) { |
78 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(real
lyEmpty[index]); | 83 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(real
lyEmpty[index]); |
| 84 // SkASSERT(ValidBounds(bounds)); // don't check because test may conta
in nan |
79 bool empty = bounds.isReallyEmpty(); | 85 bool empty = bounds.isReallyEmpty(); |
80 REPORTER_ASSERT(reporter, empty); | 86 REPORTER_ASSERT(reporter, empty); |
81 } | 87 } |
82 for (size_t index = 0; index < notEmptyTestsCount; ++index) { | 88 for (size_t index = 0; index < notEmptyTestsCount; ++index) { |
83 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notR
eallyEmpty[index]); | 89 const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notR
eallyEmpty[index]); |
| 90 SkASSERT(ValidBounds(bounds)); |
84 bool empty = bounds.isReallyEmpty(); | 91 bool empty = bounds.isReallyEmpty(); |
85 REPORTER_ASSERT(reporter, !empty); | 92 REPORTER_ASSERT(reporter, !empty); |
86 } | 93 } |
87 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; | 94 const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; |
88 bounds.setLineBounds(curvePts); | 95 bounds.setLineBounds(curvePts); |
89 expected.set(0, 0, 1, 2); | 96 expected.set(0, 0, 1, 2); |
90 REPORTER_ASSERT(reporter, bounds == expected); | 97 REPORTER_ASSERT(reporter, bounds == expected); |
91 (bounds.*SetCurveBounds[1])(curvePts); | 98 (bounds.*SetCurveBounds[1])(curvePts); |
92 REPORTER_ASSERT(reporter, bounds == expected); | 99 REPORTER_ASSERT(reporter, bounds == expected); |
93 bounds.setQuadBounds(curvePts); | 100 bounds.setQuadBounds(curvePts); |
94 expected.set(0, 0, 3, 4); | 101 expected.set(0, 0, 3, 4); |
95 REPORTER_ASSERT(reporter, bounds == expected); | 102 REPORTER_ASSERT(reporter, bounds == expected); |
96 (bounds.*SetCurveBounds[2])(curvePts); | 103 (bounds.*SetCurveBounds[2])(curvePts); |
97 REPORTER_ASSERT(reporter, bounds == expected); | 104 REPORTER_ASSERT(reporter, bounds == expected); |
98 bounds.setCubicBounds(curvePts); | 105 bounds.setCubicBounds(curvePts); |
99 expected.set(0, 0, 5, 6); | 106 expected.set(0, 0, 5, 6); |
100 REPORTER_ASSERT(reporter, bounds == expected); | 107 REPORTER_ASSERT(reporter, bounds == expected); |
101 (bounds.*SetCurveBounds[3])(curvePts); | 108 (bounds.*SetCurveBounds[3])(curvePts); |
102 REPORTER_ASSERT(reporter, bounds == expected); | 109 REPORTER_ASSERT(reporter, bounds == expected); |
103 } | 110 } |
104 | 111 |
105 #include "TestClassDef.h" | 112 #include "TestClassDef.h" |
106 DEFINE_TESTCLASS_SHORT(PathOpsBoundsTest) | 113 DEFINE_TESTCLASS_SHORT(PathOpsBoundsTest) |
OLD | NEW |