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); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame^] | 36 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
| 37 | SkBitmap bitmap; |
| 38 | int pixelDiff = comparePaths(reporter, __FUNCTION__, rectPath, result, bitmap); |
| 39 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 40 | |
| 41 | rectPath.reset(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 42 | rectPath.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 43 | rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 44 | builder.add(rectPath, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 45 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 46 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 47 | REPORTER_ASSERT(reporter, closed); |
| 48 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame^] | 49 | REPORTER_ASSERT(reporter, rectPath == result); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 50 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 51 | builder.add(rectPath, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 53 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 54 | |
| 55 | SkPath rect2, rect3; |
| 56 | rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); |
| 57 | rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 58 | builder.add(rectPath, kUnion_SkPathOp); |
| 59 | builder.add(rect2, kUnion_SkPathOp); |
| 60 | builder.add(rect3, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 62 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 63 | REPORTER_ASSERT(reporter, closed); |
| 64 | SkRect expected; |
| 65 | expected.set(0, 1, 5, 3); |
| 66 | REPORTER_ASSERT(reporter, result.getBounds() == expected); |
| 67 | |
| 68 | SkPath circle1, circle2, circle3; |
| 69 | circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); |
| 70 | circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); |
| 71 | circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); |
| 72 | SkPath opCompare; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 73 | Op(circle1, circle2, kUnion_SkPathOp, &opCompare); |
| 74 | Op(opCompare, circle3, kDifference_SkPathOp, &opCompare); |
| 75 | builder.add(circle1, kUnion_SkPathOp); |
| 76 | builder.add(circle2, kUnion_SkPathOp); |
| 77 | builder.add(circle3, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 78 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame^] | 79 | pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result, bitmap); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 80 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 81 | } |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 82 | |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame^] | 83 | DEF_TEST(BuilderIssue3838, reporter) { |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 84 | SkPath path; |
| 85 | path.moveTo(200, 170); |
| 86 | path.lineTo(220, 170); |
| 87 | path.lineTo(220, 230); |
| 88 | path.lineTo(240, 230); |
| 89 | path.lineTo(240, 210); |
| 90 | path.lineTo(180, 210); |
| 91 | path.lineTo(180, 190); |
| 92 | path.lineTo(260, 190); |
| 93 | path.lineTo(260, 250); |
| 94 | path.lineTo(200, 250); |
| 95 | path.lineTo(200, 170); |
| 96 | path.close(); |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 97 | SkPath path2; |
| 98 | SkOpBuilder builder; |
| 99 | builder.add(path, kUnion_SkPathOp); |
| 100 | builder.resolve(&path2); |
| 101 | SkBitmap bitmap; |
| 102 | int pixelDiff = comparePaths(reporter, __FUNCTION__, path, path2, bitmap); |
| 103 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
| 104 | } |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame^] | 105 | |
| 106 | DEF_TEST(BuilderIssue3838_2, reporter) { |
| 107 | SkPath path; |
| 108 | path.addCircle(100, 100, 50); |
| 109 | |
| 110 | SkOpBuilder builder; |
| 111 | builder.add(path, kUnion_SkPathOp); |
| 112 | builder.add(path, kUnion_SkPathOp); |
| 113 | |
| 114 | SkPath result; |
| 115 | SkBitmap bitmap; |
| 116 | builder.resolve(&result); |
| 117 | int pixelDiff = comparePaths(reporter, __FUNCTION__, path, result, bitmap); |
| 118 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
| 119 | } |