| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 size_t index; | 1223 size_t index; |
| 1224 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { | 1224 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 1225 SkPath path; | 1225 SkPath path; |
| 1226 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); | 1226 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); |
| 1227 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++index) { | 1227 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++index) { |
| 1228 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index].fY); | 1228 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index].fY); |
| 1229 } | 1229 } |
| 1230 if (close) { | 1230 if (close) { |
| 1231 path.close(); | 1231 path.close(); |
| 1232 } | 1232 } |
| 1233 REPORTER_ASSERT(reporter, fail ^ path.isRect(0)); | 1233 REPORTER_ASSERT(reporter, fail ^ path.isRect(NULL)); |
| 1234 REPORTER_ASSERT(reporter, fail ^ path.isRect(NULL, NULL)); | |
| 1235 | 1234 |
| 1236 if (!fail) { | 1235 if (!fail) { |
| 1237 SkRect computed, expected; | 1236 SkRect computed, expected; |
| 1238 expected.set(tests[testIndex], testLen[testIndex] / sizeof(SkPoint))
; | 1237 expected.set(tests[testIndex], testLen[testIndex] / sizeof(SkPoint))
; |
| 1239 REPORTER_ASSERT(reporter, path.isRect(&computed)); | 1238 REPORTER_ASSERT(reporter, path.isRect(&computed)); |
| 1240 REPORTER_ASSERT(reporter, expected == computed); | 1239 REPORTER_ASSERT(reporter, expected == computed); |
| 1241 | 1240 |
| 1242 bool isClosed; | 1241 bool isClosed; |
| 1243 SkPath::Direction direction, cheapDirection; | 1242 SkPath::Direction direction, cheapDirection; |
| 1244 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); | 1243 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); |
| 1245 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction)); | 1244 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, &direction)); |
| 1246 REPORTER_ASSERT(reporter, isClosed == close); | 1245 REPORTER_ASSERT(reporter, isClosed == close); |
| 1247 REPORTER_ASSERT(reporter, direction == cheapDirection); | 1246 REPORTER_ASSERT(reporter, direction == cheapDirection); |
| 1248 } else { | 1247 } else { |
| 1249 SkRect computed; | 1248 SkRect computed; |
| 1250 computed.set(123, 456, 789, 1011); | 1249 computed.set(123, 456, 789, 1011); |
| 1251 REPORTER_ASSERT(reporter, !path.isRect(&computed)); | 1250 REPORTER_ASSERT(reporter, !path.isRect(&computed)); |
| 1252 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); | 1251 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); |
| 1253 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); | 1252 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); |
| 1254 | 1253 |
| 1255 bool isClosed = (bool) -1; | 1254 bool isClosed = (bool) -1; |
| 1256 SkPath::Direction direction = (SkPath::Direction) -1; | 1255 SkPath::Direction direction = (SkPath::Direction) -1; |
| 1257 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction)); | 1256 REPORTER_ASSERT(reporter, !path.isRect(NULL, &isClosed, &direction))
; |
| 1258 REPORTER_ASSERT(reporter, isClosed == (bool) -1); | 1257 REPORTER_ASSERT(reporter, isClosed == (bool) -1); |
| 1259 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); | 1258 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
| 1260 } | 1259 } |
| 1261 | 1260 |
| 1262 if (tests[testIndex] == lastPass) { | 1261 if (tests[testIndex] == lastPass) { |
| 1263 fail = true; | 1262 fail = true; |
| 1264 } | 1263 } |
| 1265 if (tests[testIndex] == lastClose) { | 1264 if (tests[testIndex] == lastClose) { |
| 1266 close = false; | 1265 close = false; |
| 1267 } | 1266 } |
| 1268 } | 1267 } |
| 1269 | 1268 |
| 1270 // fail, close then line | 1269 // fail, close then line |
| 1271 SkPath path1; | 1270 SkPath path1; |
| 1272 path1.moveTo(r1[0].fX, r1[0].fY); | 1271 path1.moveTo(r1[0].fX, r1[0].fY); |
| 1273 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { | 1272 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 1274 path1.lineTo(r1[index].fX, r1[index].fY); | 1273 path1.lineTo(r1[index].fX, r1[index].fY); |
| 1275 } | 1274 } |
| 1276 path1.close(); | 1275 path1.close(); |
| 1277 path1.lineTo(1, 0); | 1276 path1.lineTo(1, 0); |
| 1278 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); | 1277 REPORTER_ASSERT(reporter, fail ^ path1.isRect(NULL)); |
| 1279 | 1278 |
| 1280 // fail, move in the middle | 1279 // fail, move in the middle |
| 1281 path1.reset(); | 1280 path1.reset(); |
| 1282 path1.moveTo(r1[0].fX, r1[0].fY); | 1281 path1.moveTo(r1[0].fX, r1[0].fY); |
| 1283 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { | 1282 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 1284 if (index == 2) { | 1283 if (index == 2) { |
| 1285 path1.moveTo(1, .5f); | 1284 path1.moveTo(1, .5f); |
| 1286 } | 1285 } |
| 1287 path1.lineTo(r1[index].fX, r1[index].fY); | 1286 path1.lineTo(r1[index].fX, r1[index].fY); |
| 1288 } | 1287 } |
| 1289 path1.close(); | 1288 path1.close(); |
| 1290 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); | 1289 REPORTER_ASSERT(reporter, fail ^ path1.isRect(NULL)); |
| 1291 | 1290 |
| 1292 // fail, move on the edge | 1291 // fail, move on the edge |
| 1293 path1.reset(); | 1292 path1.reset(); |
| 1294 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { | 1293 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 1295 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); | 1294 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 1296 path1.lineTo(r1[index].fX, r1[index].fY); | 1295 path1.lineTo(r1[index].fX, r1[index].fY); |
| 1297 } | 1296 } |
| 1298 path1.close(); | 1297 path1.close(); |
| 1299 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); | 1298 REPORTER_ASSERT(reporter, fail ^ path1.isRect(NULL)); |
| 1300 | 1299 |
| 1301 // fail, quad | 1300 // fail, quad |
| 1302 path1.reset(); | 1301 path1.reset(); |
| 1303 path1.moveTo(r1[0].fX, r1[0].fY); | 1302 path1.moveTo(r1[0].fX, r1[0].fY); |
| 1304 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { | 1303 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 1305 if (index == 2) { | 1304 if (index == 2) { |
| 1306 path1.quadTo(1, .5f, 1, .5f); | 1305 path1.quadTo(1, .5f, 1, .5f); |
| 1307 } | 1306 } |
| 1308 path1.lineTo(r1[index].fX, r1[index].fY); | 1307 path1.lineTo(r1[index].fX, r1[index].fY); |
| 1309 } | 1308 } |
| 1310 path1.close(); | 1309 path1.close(); |
| 1311 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); | 1310 REPORTER_ASSERT(reporter, fail ^ path1.isRect(NULL)); |
| 1312 | 1311 |
| 1313 // fail, cubic | 1312 // fail, cubic |
| 1314 path1.reset(); | 1313 path1.reset(); |
| 1315 path1.moveTo(r1[0].fX, r1[0].fY); | 1314 path1.moveTo(r1[0].fX, r1[0].fY); |
| 1316 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { | 1315 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 1317 if (index == 2) { | 1316 if (index == 2) { |
| 1318 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); | 1317 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 1319 } | 1318 } |
| 1320 path1.lineTo(r1[index].fX, r1[index].fY); | 1319 path1.lineTo(r1[index].fX, r1[index].fY); |
| 1321 } | 1320 } |
| 1322 path1.close(); | 1321 path1.close(); |
| 1323 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); | 1322 REPORTER_ASSERT(reporter, fail ^ path1.isRect(NULL)); |
| 1324 } | 1323 } |
| 1325 | 1324 |
| 1326 static void test_isNestedRects(skiatest::Reporter* reporter) { | 1325 static void test_isNestedRects(skiatest::Reporter* reporter) { |
| 1327 // passing tests (all moveTo / lineTo... | 1326 // passing tests (all moveTo / lineTo... |
| 1328 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW | 1327 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW |
| 1329 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; | 1328 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1330 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; | 1329 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 1331 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; | 1330 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| 1332 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW | 1331 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW |
| 1333 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; | 1332 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2396 REPORTER_ASSERT(reporter, p.isRect(NULL)); | 2395 REPORTER_ASSERT(reporter, p.isRect(NULL)); |
| 2397 bounds2.setEmpty(); | 2396 bounds2.setEmpty(); |
| 2398 REPORTER_ASSERT(reporter, p.isRect(&bounds2)); | 2397 REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
| 2399 REPORTER_ASSERT(reporter, bounds == bounds2); | 2398 REPORTER_ASSERT(reporter, bounds == bounds2); |
| 2400 | 2399 |
| 2401 // now force p to not be a rect | 2400 // now force p to not be a rect |
| 2402 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); | 2401 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
| 2403 p.addRect(bounds); | 2402 p.addRect(bounds); |
| 2404 REPORTER_ASSERT(reporter, !p.isRect(NULL)); | 2403 REPORTER_ASSERT(reporter, !p.isRect(NULL)); |
| 2405 | 2404 |
| 2405 // test isRect for a trailing moveTo |
| 2406 { |
| 2407 SkRect r; |
| 2408 p.reset(); |
| 2409 p.addRect(bounds); |
| 2410 REPORTER_ASSERT(reporter, p.isRect(&r)); |
| 2411 REPORTER_ASSERT(reporter, r == bounds); |
| 2412 // add a moveTo outside of our bounds |
| 2413 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10); |
| 2414 REPORTER_ASSERT(reporter, p.isRect(&r)); |
| 2415 REPORTER_ASSERT(reporter, r == bounds); |
| 2416 } |
| 2417 |
| 2406 test_isLine(reporter); | 2418 test_isLine(reporter); |
| 2407 test_isRect(reporter); | 2419 test_isRect(reporter); |
| 2408 test_isNestedRects(reporter); | 2420 test_isNestedRects(reporter); |
| 2409 test_zero_length_paths(reporter); | 2421 test_zero_length_paths(reporter); |
| 2410 test_direction(reporter); | 2422 test_direction(reporter); |
| 2411 test_convexity(reporter); | 2423 test_convexity(reporter); |
| 2412 test_convexity2(reporter); | 2424 test_convexity2(reporter); |
| 2413 test_conservativelyContains(reporter); | 2425 test_conservativelyContains(reporter); |
| 2414 test_close(reporter); | 2426 test_close(reporter); |
| 2415 test_segment_masks(reporter); | 2427 test_segment_masks(reporter); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2429 test_addrect_isfinite(reporter); | 2441 test_addrect_isfinite(reporter); |
| 2430 test_tricky_cubic(); | 2442 test_tricky_cubic(); |
| 2431 test_clipped_cubic(); | 2443 test_clipped_cubic(); |
| 2432 test_crbug_170666(); | 2444 test_crbug_170666(); |
| 2433 test_bad_cubic_crbug229478(); | 2445 test_bad_cubic_crbug229478(); |
| 2434 test_bad_cubic_crbug234190(); | 2446 test_bad_cubic_crbug234190(); |
| 2435 } | 2447 } |
| 2436 | 2448 |
| 2437 #include "TestClassDef.h" | 2449 #include "TestClassDef.h" |
| 2438 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) | 2450 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |
| OLD | NEW |