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 | */ |
| 7 | #include "PathOpsTestCommon.h" |
| 8 | #include "Test.h" |
| 9 | |
| 10 | DEF_TEST(PathOpsBuilder, reporter) { |
| 11 | SkOpBuilder builder; |
| 12 | SkPath result; |
| 13 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 14 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 15 | |
| 16 | builder.add(result, kDifference_PathOp); |
| 17 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 18 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 19 | |
| 20 | builder.add(result, kUnion_PathOp); |
| 21 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 22 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 23 | |
| 24 | SkPath rectPath; |
| 25 | rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction); |
| 26 | builder.add(rectPath, kUnion_PathOp); |
| 27 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 28 | bool closed; |
| 29 | SkPath::Direction dir; |
| 30 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 31 | REPORTER_ASSERT(reporter, closed); |
| 32 | REPORTER_ASSERT(reporter, dir == SkPath::kCW_Direction); |
| 33 | REPORTER_ASSERT(reporter, rectPath == result); |
| 34 | |
| 35 | rectPath.reset(); |
| 36 | rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); |
| 37 | builder.add(rectPath, kUnion_PathOp); |
| 38 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 39 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 40 | REPORTER_ASSERT(reporter, closed); |
| 41 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
| 42 | REPORTER_ASSERT(reporter, rectPath == result); |
| 43 | |
| 44 | builder.add(rectPath, kDifference_PathOp); |
| 45 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 46 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 47 | |
| 48 | SkPath rect2, rect3; |
| 49 | rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); |
| 50 | rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); |
| 51 | builder.add(rectPath, kUnion_PathOp); |
| 52 | builder.add(rect2, kUnion_PathOp); |
| 53 | builder.add(rect3, kUnion_PathOp); |
| 54 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 55 | REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
| 56 | REPORTER_ASSERT(reporter, closed); |
| 57 | SkRect expected; |
| 58 | expected.set(0, 1, 5, 3); |
| 59 | REPORTER_ASSERT(reporter, result.getBounds() == expected); |
| 60 | |
| 61 | SkPath circle1, circle2, circle3; |
| 62 | circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); |
| 63 | circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); |
| 64 | circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); |
| 65 | SkPath opCompare; |
| 66 | Op(circle1, circle2, kUnion_PathOp, &opCompare); |
| 67 | Op(opCompare, circle3, kDifference_PathOp, &opCompare); |
| 68 | builder.add(circle1, kUnion_PathOp); |
| 69 | builder.add(circle2, kUnion_PathOp); |
| 70 | builder.add(circle3, kDifference_PathOp); |
| 71 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 72 | REPORTER_ASSERT(reporter, opCompare == result); |
| 73 | } |