caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 "SkPathOpsCubic.h" |
| 9 | #include "SkPathOpsLine.h" |
| 10 | #include "SkPathOpsQuad.h" |
| 11 | #include "SkPathOpsRect.h" |
| 12 | #include "Test.h" |
| 13 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 14 | static const QuadPts quadTests[] = { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 15 | {{{1, 1}, {2, 1}, {0, 2}}}, |
| 16 | {{{0, 0}, {1, 1}, {3, 1}}}, |
| 17 | {{{2, 0}, {1, 1}, {2, 2}}}, |
| 18 | {{{4, 0}, {0, 1}, {4, 2}}}, |
| 19 | {{{0, 0}, {0, 1}, {1, 1}}}, |
| 20 | }; |
| 21 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 22 | static const CubicPts cubicTests[] = { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 23 | {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}}, |
| 24 | {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}}, |
| 25 | {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}}, |
| 26 | }; |
| 27 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 28 | static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests); |
| 29 | static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 30 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 31 | static void setRawBounds(const SkDQuad& quad, SkDRect* rect) { |
| 32 | rect->set(quad[0]); |
| 33 | rect->add(quad[1]); |
| 34 | rect->add(quad[2]); |
| 35 | } |
| 36 | |
| 37 | static void setRawBounds(const SkDCubic& cubic, SkDRect* rect) { |
| 38 | rect->set(cubic[0]); |
| 39 | rect->add(cubic[1]); |
| 40 | rect->add(cubic[2]); |
| 41 | rect->add(cubic[3]); |
| 42 | } |
| 43 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 44 | DEF_TEST(PathOpsDRect, reporter) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 45 | size_t index; |
| 46 | SkDRect rect, rect2; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 47 | for (index = 0; index < quadTests_count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 48 | const QuadPts& q = quadTests[index]; |
| 49 | SkDQuad quad; |
| 50 | quad.debugSet(q.fPts); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 51 | SkASSERT(ValidQuad(quad)); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 52 | setRawBounds(quad, &rect); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 53 | rect2.setBounds(quad); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, rect.intersects(rect2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 55 | // FIXME: add a recursive box subdivision method to verify that tight bounds is correct |
| 56 | SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 57 | REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 58 | SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 59 | REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 60 | } |
| 61 | for (index = 0; index < cubicTests_count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 62 | const CubicPts& c = cubicTests[index]; |
| 63 | SkDCubic cubic; |
| 64 | cubic.debugSet(c.fPts); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 65 | SkASSERT(ValidCubic(cubic)); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 66 | setRawBounds(cubic, &rect); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 67 | rect2.setBounds(cubic); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, rect.intersects(rect2)); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | // FIXME: add a recursive box subdivision method to verify that tight bounds is correct |
| 70 | SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; |
| 71 | REPORTER_ASSERT(reporter, rect.contains(leftTop)); |
| 72 | SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; |
| 73 | REPORTER_ASSERT(reporter, rect.contains(rightBottom)); |
| 74 | } |
| 75 | } |