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; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 34 | REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir)); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, closed); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 36 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
caryclark | 4e1a4c9 | 2015-05-18 12:56:57 -0700 | [diff] [blame] | 37 | int pixelDiff = comparePaths(reporter, __FUNCTION__, rectPath, result); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 38 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 39 | |
| 40 | rectPath.reset(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 41 | rectPath.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 42 | rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 43 | builder.add(rectPath, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 45 | REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir)); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, closed); |
| 47 | REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, rectPath == result); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 49 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 50 | builder.add(rectPath, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
| 52 | REPORTER_ASSERT(reporter, result.isEmpty()); |
| 53 | |
| 54 | SkPath rect2, rect3; |
| 55 | rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction); |
| 56 | rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 57 | builder.add(rectPath, kUnion_SkPathOp); |
| 58 | builder.add(rect2, kUnion_SkPathOp); |
| 59 | builder.add(rect3, kUnion_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 61 | REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir)); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, closed); |
| 63 | SkRect expected; |
| 64 | expected.set(0, 1, 5, 3); |
| 65 | REPORTER_ASSERT(reporter, result.getBounds() == expected); |
| 66 | |
| 67 | SkPath circle1, circle2, circle3; |
| 68 | circle1.addCircle(5, 6, 4, SkPath::kCW_Direction); |
| 69 | circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction); |
| 70 | circle3.addCircle(6, 5, 6, SkPath::kCW_Direction); |
| 71 | SkPath opCompare; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 72 | Op(circle1, circle2, kUnion_SkPathOp, &opCompare); |
| 73 | Op(opCompare, circle3, kDifference_SkPathOp, &opCompare); |
| 74 | builder.add(circle1, kUnion_SkPathOp); |
| 75 | builder.add(circle2, kUnion_SkPathOp); |
| 76 | builder.add(circle3, kDifference_SkPathOp); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 77 | REPORTER_ASSERT(reporter, builder.resolve(&result)); |
caryclark | 4e1a4c9 | 2015-05-18 12:56:57 -0700 | [diff] [blame] | 78 | pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 79 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 80 | } |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 81 | |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 82 | DEF_TEST(BuilderIssue3838, reporter) { |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 83 | SkPath path; |
| 84 | path.moveTo(200, 170); |
| 85 | path.lineTo(220, 170); |
| 86 | path.lineTo(220, 230); |
| 87 | path.lineTo(240, 230); |
| 88 | path.lineTo(240, 210); |
| 89 | path.lineTo(180, 210); |
| 90 | path.lineTo(180, 190); |
| 91 | path.lineTo(260, 190); |
| 92 | path.lineTo(260, 250); |
| 93 | path.lineTo(200, 250); |
| 94 | path.lineTo(200, 170); |
| 95 | path.close(); |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 96 | SkPath path2; |
| 97 | SkOpBuilder builder; |
| 98 | builder.add(path, kUnion_SkPathOp); |
| 99 | builder.resolve(&path2); |
caryclark | 4e1a4c9 | 2015-05-18 12:56:57 -0700 | [diff] [blame] | 100 | int pixelDiff = comparePaths(reporter, __FUNCTION__, path, path2); |
caryclark | fba9da7 | 2015-05-14 14:18:13 -0700 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
| 102 | } |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 103 | |
| 104 | DEF_TEST(BuilderIssue3838_2, reporter) { |
| 105 | SkPath path; |
| 106 | path.addCircle(100, 100, 50); |
| 107 | |
| 108 | SkOpBuilder builder; |
| 109 | builder.add(path, kUnion_SkPathOp); |
| 110 | builder.add(path, kUnion_SkPathOp); |
| 111 | |
| 112 | SkPath result; |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 113 | builder.resolve(&result); |
caryclark | 4e1a4c9 | 2015-05-18 12:56:57 -0700 | [diff] [blame] | 114 | int pixelDiff = comparePaths(reporter, __FUNCTION__, path, result); |
| 115 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
| 116 | } |
| 117 | |
| 118 | DEF_TEST(BuilderIssue3838_3, reporter) { |
| 119 | SkPath path; |
| 120 | path.moveTo(40, 10); |
| 121 | path.lineTo(60, 10); |
| 122 | path.lineTo(60, 30); |
| 123 | path.lineTo(40, 30); |
| 124 | path.lineTo(40, 10); |
| 125 | path.moveTo(41, 11); |
| 126 | path.lineTo(41, 29); |
| 127 | path.lineTo(59, 29); |
| 128 | path.lineTo(59, 11); |
| 129 | path.lineTo(41, 11); |
| 130 | |
| 131 | SkOpBuilder builder; |
| 132 | builder.add(path, kUnion_SkPathOp); |
| 133 | SkPath result; |
| 134 | builder.resolve(&result); |
| 135 | int pixelDiff = comparePaths(reporter, __FUNCTION__, path, result); |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, pixelDiff == 0); |
| 137 | } |
caryclark | 218f21a | 2015-06-29 11:41:52 -0700 | [diff] [blame] | 138 | |
| 139 | DEF_TEST(BuilderIssue502792_2, reporter) { |
| 140 | SkPath path, pathB; |
| 141 | path.setFillType(SkPath::kWinding_FillType); |
| 142 | path.addRect(0, 0, 1, 1, SkPath::kCW_Direction); |
| 143 | path.addRect(2, 2, 3, 3, SkPath::kCW_Direction); |
| 144 | pathB.setFillType(SkPath::kEvenOdd_FillType); |
| 145 | pathB.addRect(3, 3, 4, 4, SkPath::kCW_Direction); |
| 146 | pathB.addRect(3, 3, 4, 4, SkPath::kCW_Direction); |
| 147 | SkOpBuilder builder; |
| 148 | builder.add(path, kUnion_SkPathOp); |
| 149 | builder.add(pathB, kDifference_SkPathOp); |
| 150 | SkPath result; |
| 151 | builder.resolve(&result); |
| 152 | } |
caryclark | d434972 | 2015-07-23 12:40:22 -0700 | [diff] [blame] | 153 | |
| 154 | DEF_TEST(Fuzz846, reporter) { |
| 155 | /* |
| 156 | <clipPath id="clip-circle"> |
| 157 | <circle id="circle" cx="60" cy="60" r="50" /> |
| 158 | </clipPath> |
| 159 | <clipPath id="clip-rect"> |
| 160 | <clipPath id="clip-rect"> |
| 161 | <clipPath id="clip-rect"> |
| 162 | <clipPath id="clip-rect"> |
| 163 | <rect x="10" y="30" width="0" height="60" /> |
| 164 | <rect x="10" y="30" width="0" height="60" /> |
| 165 | <rect x="10" y="30" width="100" height="60" /> |
| 166 | <rect x="10" y="30" width="32668" /> |
| 167 | <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 168 | <rect x="10" y="255" width="100" height="60" /> |
| 169 | <rect width="100" height="60" /> |
| 170 | <rect x="10" y="30" width="100" height="60" /> |
| 171 | <rect x="10" y="30" width="100" height="4294967236" /> |
| 172 | <rect x="10" y="30" width="100" height="60" /> |
| 173 | </clipPath> |
| 174 | <rect x="10" y="30" width="0" height="60" /> |
| 175 | <rect x="10" y="30" width="0" height="0.18093252719929986369568203" /> |
| 176 | <rect x="10" y="30" width="100" height="60" /> |
| 177 | <rect x="10" y="30" width="32668" height="60" /> |
| 178 | <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 179 | <rect x="10" y="255" width="100" height="60" /> |
| 180 | <rect x="2147483649" y="30" width="100" height="60" /> |
| 181 | <rect x="10" y="30" width="100" height="60" /> |
| 182 | <rect x="10" y="30" width="100" height="60" /> |
| 183 | <rect x="10" y="30" width="100" height="60" /> |
| 184 | </clipPath> |
| 185 | <rect x="10" y="30" width="0" height="60" /> |
| 186 | <rect x="10" y="30" width="0" height="60" /> |
| 187 | <rect x="10" y="30" width="100" height="60" /> |
| 188 | <rect x="10" y="30" width="32668" height="60" /> |
| 189 | <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 190 | <rect x="10" y="255" width="100" height="60" /> |
| 191 | <rect x="2147483649" y="30" width="100" height="60" /> |
| 192 | <rect x="10" y="30" width="100" height="60" /> |
| 193 | <rect x="10" y="2879753595" width="100" height="60" /> |
| 194 | <rect x="10" y="30" width="100" height="60" /> |
| 195 | </clipPath> |
| 196 | <rect x="10" y="30" width="100" height="60" /> |
| 197 | <rect x="10" y="30" width="0" height="60" /> |
| 198 | <rect x="10" y="30" width="100" height="60" /> |
| 199 | <rect x="10" y="30" width="32668" height="60" /> |
| 200 | <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 201 | <rect x="10" y="255" width="100" height="60" /> |
| 202 | <rect x="2147483649" y="30" width="100" height="60" /> |
| 203 | <rect x="10" y="30" width="100" height="60" /> |
| 204 | <rect x="10" y="30" width="100" height="4294967236" /> |
| 205 | <rect x="10" y="30" width="100" height="4294967236" /> |
| 206 | <rect x="10" y="30" width="100" height="4294967236" /> |
| 207 | <rect x="10" y="30" width="100" height="4294967236" /> |
| 208 | <rect x="10" y="30" width="100" height="60" /> |
| 209 | <rect x="757798030" y="30" width="100" height="60" /> |
| 210 | */ |
| 211 | SkPath clipCircle, clipRect; |
| 212 | SkPath inner; |
| 213 | clipCircle.addCircle(60, 60, 50); // <circle id="circle" cx="60" cy="60" r="50" /> |
| 214 | |
| 215 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 216 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 217 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 218 | inner.addRect(10, 30, 10+32668, 30+0); // <rect x="10" y="30" width="32668" /> |
| 219 | inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 220 | inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" /> |
| 221 | inner.addRect(0, 0, 0+100, 0+60); // <rect width="100" height="60" /> |
| 222 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 223 | inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" /> |
| 224 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 225 | clipRect.addPath(inner); |
| 226 | inner.reset(); |
| 227 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 228 | inner.addRect(10, 30, 10+0, 30+0.18093252719929986369568203f); // <rect x="10" y="30" width="0" height="0.18093252719929986369568203" /> |
| 229 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 230 | inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" /> |
| 231 | inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 232 | inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" /> |
| 233 | inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" /> |
| 234 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 235 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 236 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 237 | clipRect.addPath(inner); |
| 238 | inner.reset(); |
| 239 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 240 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 241 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 242 | inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" /> |
| 243 | inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 244 | inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" /> |
| 245 | inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" /> |
| 246 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 247 | inner.addRect(10, 2879753595.f, 10+100, 30+2879753595.f); // <rect x="10" y="2879753595" width="100" height="60" /> |
| 248 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 249 | clipRect.addPath(inner); |
| 250 | inner.reset(); |
| 251 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 252 | inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" /> |
| 253 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 254 | inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" /> |
| 255 | inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" /> |
| 256 | inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" /> |
| 257 | inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" /> |
| 258 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 259 | inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" /> |
| 260 | inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" /> |
| 261 | inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" /> |
| 262 | inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" /> |
| 263 | inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" /> |
| 264 | inner.addRect(757798030.f, 30, 757798030.f+100, 30+60); // <rect x="757798030" y="30" width="100" height="60" /> |
| 265 | clipRect.addPath(inner); |
| 266 | |
| 267 | SkOpBuilder builder; |
| 268 | builder.add(clipCircle, kUnion_SkPathOp); |
| 269 | builder.add(clipRect, kDifference_SkPathOp); |
| 270 | SkPath result; |
| 271 | builder.resolve(&result); |
| 272 | } |
| 273 | |