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