caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 7 | |
| 8 | #include "PathOpsExtendedTest.h" |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 9 | #include "PathOpsTestCommon.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 10 | #include "SkBitmap.h" |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 11 | #include "Test.h" |
| 12 | |
| 13 | DEF_TEST(PathOpsBuilder, reporter) { |
| 14 | SkOpBuilder builder; |
| 15 | SkPath result; |
| 16 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 17 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 18 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 19 | builder.add(result, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 20 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 21 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 22 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 23 | builder.add(result, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 24 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 25 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 26 | |
| 27 | SkPath rectPath; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 28 | rectPath.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 29 | rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 30 | builder.add(rectPath, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 31 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 32 | bool closed; |
| 33 | SkPath::Direction dir; |
| 34 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 35 | REPORTER_ASSERT(reporter, closed); |
| 36 | REPORTER_ASSERT(reporter, dir == SkPath::kCW_Direction); |
| 37 | REPORTER_ASSERT(reporter, rectPath == result); |
| 38 | |
| 39 | rectPath.reset(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 40 | rectPath.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 41 | rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 42 | builder.add(rectPath, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 44 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 45 | REPORTER_ASSERT(reporter, closed); |
| 46 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 47 | REPORTER_ASSERT(reporter, rectPath == result); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 48 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 49 | builder.add(rectPath, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 51 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 52 | |
| 53 | SkPath rect2, rect3; |
| 54 | rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); |
| 55 | rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 56 | builder.add(rectPath, kUnion_SkPathOp); |
| 57 | builder.add(rect2, kUnion_SkPathOp); |
| 58 | builder.add(rect3, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 59 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 60 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 61 | REPORTER_ASSERT(reporter, closed); |
| 62 | SkRect expected; |
| 63 | expected.set(0, 1, 5, 3); |
| 64 | REPORTER_ASSERT(reporter, result.getBounds() == expected); |
| 65 | |
| 66 | SkPath circle1, circle2, circle3; |
| 67 | circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); |
| 68 | circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); |
| 69 | circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); |
| 70 | SkPath opCompare; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 71 | Op(circle1, circle2, kUnion_SkPathOp, &opCompare); |
| 72 | Op(opCompare, circle3, kDifference_SkPathOp, &opCompare); |
| 73 | builder.add(circle1, kUnion_SkPathOp); |
| 74 | builder.add(circle2, kUnion_SkPathOp); |
| 75 | builder.add(circle3, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame^] | 77 | SkBitmap bitmap; |
| 78 | int pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result, bitmap); |
| 79 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 80 | } |