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