OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
| 7 |
| 8 #include "PathOpsExtendedTest.h" |
7 #include "PathOpsTestCommon.h" | 9 #include "PathOpsTestCommon.h" |
| 10 #include "SkBitmap.h" |
8 #include "Test.h" | 11 #include "Test.h" |
9 | 12 |
10 DEF_TEST(PathOpsBuilder, reporter) { | 13 DEF_TEST(PathOpsBuilder, reporter) { |
11 SkOpBuilder builder; | 14 SkOpBuilder builder; |
12 SkPath result; | 15 SkPath result; |
13 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 16 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
14 REPORTER_ASSERT(reporter, result.isEmpty()); | 17 REPORTER_ASSERT(reporter, result.isEmpty()); |
15 | 18 |
16 builder.add(result, kDifference_PathOp); | 19 builder.add(result, kDifference_SkPathOp); |
17 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 20 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
18 REPORTER_ASSERT(reporter, result.isEmpty()); | 21 REPORTER_ASSERT(reporter, result.isEmpty()); |
19 | 22 |
20 builder.add(result, kUnion_PathOp); | 23 builder.add(result, kUnion_SkPathOp); |
21 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 24 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
22 REPORTER_ASSERT(reporter, result.isEmpty()); | 25 REPORTER_ASSERT(reporter, result.isEmpty()); |
23 | 26 |
24 SkPath rectPath; | 27 SkPath rectPath; |
| 28 rectPath.setFillType(SkPath::kEvenOdd_FillType); |
25 rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction); | 29 rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction); |
26 builder.add(rectPath, kUnion_PathOp); | 30 builder.add(rectPath, kUnion_SkPathOp); |
27 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 31 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
28 bool closed; | 32 bool closed; |
29 SkPath::Direction dir; | 33 SkPath::Direction dir; |
30 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); | 34 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
31 REPORTER_ASSERT(reporter, closed); | 35 REPORTER_ASSERT(reporter, closed); |
32 REPORTER_ASSERT(reporter, dir == SkPath::kCW_Direction); | 36 REPORTER_ASSERT(reporter, dir == SkPath::kCW_Direction); |
33 REPORTER_ASSERT(reporter, rectPath == result); | 37 REPORTER_ASSERT(reporter, rectPath == result); |
34 | 38 |
35 rectPath.reset(); | 39 rectPath.reset(); |
| 40 rectPath.setFillType(SkPath::kEvenOdd_FillType); |
36 rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); | 41 rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); |
37 builder.add(rectPath, kUnion_PathOp); | 42 builder.add(rectPath, kUnion_SkPathOp); |
38 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 43 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
39 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); | 44 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
40 REPORTER_ASSERT(reporter, closed); | 45 REPORTER_ASSERT(reporter, closed); |
41 REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); | 46 REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
42 REPORTER_ASSERT(reporter, rectPath == result); | 47 REPORTER_ASSERT(reporter, rectPath == result); |
43 | 48 |
44 builder.add(rectPath, kDifference_PathOp); | 49 builder.add(rectPath, kDifference_SkPathOp); |
45 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 50 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
46 REPORTER_ASSERT(reporter, result.isEmpty()); | 51 REPORTER_ASSERT(reporter, result.isEmpty()); |
47 | 52 |
48 SkPath rect2, rect3; | 53 SkPath rect2, rect3; |
49 rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); | 54 rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); |
50 rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); | 55 rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); |
51 builder.add(rectPath, kUnion_PathOp); | 56 builder.add(rectPath, kUnion_SkPathOp); |
52 builder.add(rect2, kUnion_PathOp); | 57 builder.add(rect2, kUnion_SkPathOp); |
53 builder.add(rect3, kUnion_PathOp); | 58 builder.add(rect3, kUnion_SkPathOp); |
54 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 59 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
55 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); | 60 REPORTER_ASSERT(reporter, result.isRect(NULL, &closed, &dir)); |
56 REPORTER_ASSERT(reporter, closed); | 61 REPORTER_ASSERT(reporter, closed); |
57 SkRect expected; | 62 SkRect expected; |
58 expected.set(0, 1, 5, 3); | 63 expected.set(0, 1, 5, 3); |
59 REPORTER_ASSERT(reporter, result.getBounds() == expected); | 64 REPORTER_ASSERT(reporter, result.getBounds() == expected); |
60 | 65 |
61 SkPath circle1, circle2, circle3; | 66 SkPath circle1, circle2, circle3; |
62 circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); | 67 circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); |
63 circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); | 68 circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); |
64 circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); | 69 circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); |
65 SkPath opCompare; | 70 SkPath opCompare; |
66 Op(circle1, circle2, kUnion_PathOp, &opCompare); | 71 Op(circle1, circle2, kUnion_SkPathOp, &opCompare); |
67 Op(opCompare, circle3, kDifference_PathOp, &opCompare); | 72 Op(opCompare, circle3, kDifference_SkPathOp, &opCompare); |
68 builder.add(circle1, kUnion_PathOp); | 73 builder.add(circle1, kUnion_SkPathOp); |
69 builder.add(circle2, kUnion_PathOp); | 74 builder.add(circle2, kUnion_SkPathOp); |
70 builder.add(circle3, kDifference_PathOp); | 75 builder.add(circle3, kDifference_SkPathOp); |
71 REPORTER_ASSERT(reporter, builder.resolve(&result)); | 76 REPORTER_ASSERT(reporter, builder.resolve(&result)); |
72 REPORTER_ASSERT(reporter, opCompare == result); | 77 SkBitmap bitmap; |
| 78 int pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result, bitm
ap); |
| 79 REPORTER_ASSERT(reporter, pixelDiff == 0); |
73 } | 80 } |
OLD | NEW |