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" |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 9 | #include "SkPathOpsCurve.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 10 | #include "Test.h" |
| 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 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 32 | DEF_TEST(PathOpsBounds, reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 33 | for (size_t index = 0; index < sectTestsCount; ++index) { |
| 34 | const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 35 | SkASSERT(ValidBounds(bounds1)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 36 | const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 37 | SkASSERT(ValidBounds(bounds2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 38 | bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 39 | REPORTER_ASSERT(reporter, touches); |
| 40 | } |
| 41 | for (size_t index = 0; index < noSectTestsCount; ++index) { |
| 42 | const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 43 | SkASSERT(ValidBounds(bounds1)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 44 | const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 45 | SkASSERT(ValidBounds(bounds2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 46 | bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2); |
| 47 | REPORTER_ASSERT(reporter, !touches); |
| 48 | } |
| 49 | SkPathOpsBounds bounds; |
| 50 | bounds.setEmpty(); |
| 51 | bounds.add(1, 2, 3, 4); |
| 52 | SkPathOpsBounds expected; |
| 53 | expected.set(0, 0, 3, 4); |
| 54 | REPORTER_ASSERT(reporter, bounds == expected); |
| 55 | bounds.setEmpty(); |
| 56 | SkPathOpsBounds ordinal; |
| 57 | ordinal.set(1, 2, 3, 4); |
| 58 | bounds.add(ordinal); |
| 59 | REPORTER_ASSERT(reporter, bounds == expected); |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 60 | bounds.setEmpty(); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 61 | SkDPoint botRight = {3, 4}; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 62 | bounds.add(botRight); |
| 63 | REPORTER_ASSERT(reporter, bounds == expected); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 64 | const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}}; |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 65 | SkDCurve curve; |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 66 | curve.fQuad.set(curvePts); |
| 67 | curve.setQuadBounds(curvePts, 1, 0, 1, &bounds); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 68 | expected.set(0, 0, 3, 4); |
| 69 | REPORTER_ASSERT(reporter, bounds == expected); |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 70 | curve.fCubic.set(curvePts); |
| 71 | curve.setCubicBounds(curvePts, 1, 0, 1, &bounds); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 72 | expected.set(0, 0, 5, 6); |
| 73 | REPORTER_ASSERT(reporter, bounds == expected); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 74 | } |