caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | */ |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 7 | #include "PathOpsTestCommon.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 8 | #include "SkPathOpsBounds.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | static const SkRect sectTests[][2] = { |
| 12 | {{2, 0, 4, 1}, {4, 0, 6, 1}}, |
| 13 | {{2, 0, 4, 1}, {3, 0, 5, 1}}, |
| 14 | {{2, 0, 4, 1}, {3, 0, 5, 0}}, |
| 15 | {{2, 0, 4, 1}, {3, 1, 5, 2}}, |
| 16 | {{2, 1, 4, 2}, {1, 0, 5, 3}}, |
| 17 | {{2, 1, 5, 3}, {3, 1, 4, 2}}, |
| 18 | {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK |
| 19 | {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK |
| 20 | }; |
| 21 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 22 | static const size_t sectTestsCount = SK_ARRAY_COUNT(sectTests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 23 | |
| 24 | static const SkRect noSectTests[][2] = { |
| 25 | {{2, 0, 4, 1}, {5, 0, 6, 1}}, |
| 26 | {{2, 0, 4, 1}, {3, 2, 5, 2}}, |
| 27 | }; |
| 28 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 29 | static const size_t noSectTestsCount = SK_ARRAY_COUNT(noSectTests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | |
| 31 | static const SkRect reallyEmpty[] = { |
| 32 | {0, 0, 0, 0}, |
| 33 | {1, 1, 1, 0}, |
| 34 | {1, 1, 0, 1}, |
| 35 | {1, 1, 0, 0}, |
| 36 | {1, 2, 3, SK_ScalarNaN}, |
| 37 | }; |
| 38 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 39 | static const size_t emptyTestsCount = SK_ARRAY_COUNT(reallyEmpty); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 40 | |
| 41 | static const SkRect notReallyEmpty[] = { |
| 42 | {0, 0, 1, 0}, |
| 43 | {0, 0, 0, 1}, |
| 44 | {0, 0, 1, 1}, |
| 45 | }; |
| 46 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 47 | static const size_t notEmptyTestsCount = SK_ARRAY_COUNT(notReallyEmpty); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 48 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 49 | static void PathOpsBoundsTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 50 | for (size_t index = 0; index < sectTestsCount; ++index) { |
| 51 | const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 52 | SkASSERT(ValidBounds(bounds1)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 53 | const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 54 | SkASSERT(ValidBounds(bounds2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 55 | bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 56 | REPORTER_ASSERT(reporter, touches); |
| 57 | } |
| 58 | for (size_t index = 0; index < noSectTestsCount; ++index) { |
| 59 | const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 60 | SkASSERT(ValidBounds(bounds1)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 61 | const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 62 | SkASSERT(ValidBounds(bounds2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 63 | bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 64 | REPORTER_ASSERT(reporter, !touches); |
| 65 | } |
| 66 | SkPathOpsBounds bounds; |
| 67 | bounds.setEmpty(); |
| 68 | bounds.add(1, 2, 3, 4); |
| 69 | SkPathOpsBounds expected; |
| 70 | expected.set(0, 0, 3, 4); |
| 71 | REPORTER_ASSERT(reporter, bounds == expected); |
| 72 | bounds.setEmpty(); |
| 73 | SkPathOpsBounds ordinal; |
| 74 | ordinal.set(1, 2, 3, 4); |
| 75 | bounds.add(ordinal); |
| 76 | REPORTER_ASSERT(reporter, bounds == expected); |
| 77 | SkPoint topLeft = {0, 0}; |
| 78 | bounds.setPointBounds(topLeft); |
| 79 | SkPoint botRight = {3, 4}; |
| 80 | bounds.add(botRight); |
| 81 | REPORTER_ASSERT(reporter, bounds == expected); |
| 82 | for (size_t index = 0; index < emptyTestsCount; ++index) { |
| 83 | const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(reallyEmpty[index]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 84 | // SkASSERT(ValidBounds(bounds)); // don't check because test may contain nan |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 85 | bool empty = bounds.isReallyEmpty(); |
| 86 | REPORTER_ASSERT(reporter, empty); |
| 87 | } |
| 88 | for (size_t index = 0; index < notEmptyTestsCount; ++index) { |
| 89 | const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notReallyEmpty[index]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 90 | SkASSERT(ValidBounds(bounds)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 91 | bool empty = bounds.isReallyEmpty(); |
| 92 | REPORTER_ASSERT(reporter, !empty); |
| 93 | } |
| 94 | const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; |
| 95 | bounds.setLineBounds(curvePts); |
| 96 | expected.set(0, 0, 1, 2); |
| 97 | REPORTER_ASSERT(reporter, bounds == expected); |
| 98 | (bounds.*SetCurveBounds[1])(curvePts); |
| 99 | REPORTER_ASSERT(reporter, bounds == expected); |
| 100 | bounds.setQuadBounds(curvePts); |
| 101 | expected.set(0, 0, 3, 4); |
| 102 | REPORTER_ASSERT(reporter, bounds == expected); |
| 103 | (bounds.*SetCurveBounds[2])(curvePts); |
| 104 | REPORTER_ASSERT(reporter, bounds == expected); |
| 105 | bounds.setCubicBounds(curvePts); |
| 106 | expected.set(0, 0, 5, 6); |
| 107 | REPORTER_ASSERT(reporter, bounds == expected); |
| 108 | (bounds.*SetCurveBounds[3])(curvePts); |
| 109 | REPORTER_ASSERT(reporter, bounds == expected); |
| 110 | } |
| 111 | |
| 112 | #include "TestClassDef.h" |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 113 | DEFINE_TESTCLASS_SHORT(PathOpsBoundsTest) |