Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: tests/PathTest.cpp

Issue 24502004: Refactor PathTest.cpp test_isNestedRects and test_isRect. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: add 'f' Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 // passing tests (all moveTo / lineTo... 1274 // passing tests (all moveTo / lineTo...
1275 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; 1275 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1276 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; 1276 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1277 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; 1277 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1278 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; 1278 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1279 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; 1279 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1280 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1280 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1281 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; 1281 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1282 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; 1282 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1283 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1283 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1284 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, 1284 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0} , {.5f, 0}};
1285 {1, 0}, {.5f, 0}}; 1285 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1} , {0, .5f}};
1286 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1},
1287 {0, 1}, {0, .5f}};
1288 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; 1286 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1289 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1287 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1290 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; 1288 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
1291 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}}; 1289 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
1292 1290
1293 // failing tests 1291 // failing tests
1294 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points 1292 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1295 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal 1293 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1296 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps 1294 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1297 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up 1295 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1298 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots 1296 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1299 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots 1297 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1300 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots 1298 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1301 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' 1299 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1302 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps 1300 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1303 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non co linear gap 1301 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non co linear gap
1304 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short 1302 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
1305 1303
1306 // failing, no close 1304 // failing, no close
1307 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match 1305 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1308 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto 1306 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1309 1307
1310 size_t testLen[] = { 1308 struct IsRectTest {
1311 sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6), 1309 SkPoint *fPoints;
1312 sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc), 1310 size_t fPointCount;
1313 sizeof(rd), sizeof(re), sizeof(rf), 1311 bool fClose;
1314 sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6), 1312 bool fIsRect;
1315 sizeof(f7), sizeof(f8), sizeof(f9), sizeof(fa), sizeof(fb), 1313 } tests[] = {
1316 sizeof(c1), sizeof(c2) 1314 { r1, SK_ARRAY_COUNT(r1), true, true },
1315 { r2, SK_ARRAY_COUNT(r2), true, true },
1316 { r3, SK_ARRAY_COUNT(r3), true, true },
1317 { r4, SK_ARRAY_COUNT(r4), true, true },
1318 { r5, SK_ARRAY_COUNT(r5), true, true },
1319 { r6, SK_ARRAY_COUNT(r6), true, true },
1320 { r7, SK_ARRAY_COUNT(r7), true, true },
1321 { r8, SK_ARRAY_COUNT(r8), true, true },
1322 { r9, SK_ARRAY_COUNT(r9), true, true },
1323 { ra, SK_ARRAY_COUNT(ra), true, true },
1324 { rb, SK_ARRAY_COUNT(rb), true, true },
1325 { rc, SK_ARRAY_COUNT(rc), true, true },
1326 { rd, SK_ARRAY_COUNT(rd), true, true },
1327 { re, SK_ARRAY_COUNT(re), true, true },
1328 { rf, SK_ARRAY_COUNT(rf), true, true },
1329
1330 { f1, SK_ARRAY_COUNT(f1), true, false },
1331 { f2, SK_ARRAY_COUNT(f2), true, false },
1332 { f3, SK_ARRAY_COUNT(f3), true, false },
1333 { f4, SK_ARRAY_COUNT(f4), true, false },
1334 { f5, SK_ARRAY_COUNT(f5), true, false },
1335 { f6, SK_ARRAY_COUNT(f6), true, false },
1336 { f7, SK_ARRAY_COUNT(f7), true, false },
1337 { f8, SK_ARRAY_COUNT(f8), true, false },
1338 { f9, SK_ARRAY_COUNT(f9), true, false },
1339 { fa, SK_ARRAY_COUNT(fa), true, false },
1340 { fb, SK_ARRAY_COUNT(fb), true, false },
1341
1342 { c1, SK_ARRAY_COUNT(c1), false, false },
1343 { c2, SK_ARRAY_COUNT(c2), false, false },
1317 }; 1344 };
1318 SkPoint* tests[] = { 1345
1319 r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re, rf, 1346 const size_t testCount = SK_ARRAY_COUNT(tests);
1320 f1, f2, f3, f4, f5, f6, f7, f8, f9, fa, fb,
1321 c1, c2
1322 };
1323 SkPoint* lastPass = rf;
1324 SkPoint* lastClose = fb;
1325 bool fail = false;
1326 bool close = true;
1327 const size_t testCount = sizeof(tests) / sizeof(tests[0]);
1328 size_t index; 1347 size_t index;
1329 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { 1348 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1330 SkPath path; 1349 SkPath path;
1331 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); 1350 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0]. fY);
1332 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++index) { 1351 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1333 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index].fY); 1352 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPo ints[index].fY);
1334 } 1353 }
1335 if (close) { 1354 if (tests[testIndex].fClose) {
1336 path.close(); 1355 path.close();
1337 } 1356 }
1338 REPORTER_ASSERT(reporter, fail ^ path.isRect(0)); 1357 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL)) ;
1339 REPORTER_ASSERT(reporter, fail ^ path.isRect(NULL, NULL)); 1358 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL, NULL));
1340 1359
1341 if (!fail) { 1360 if (tests[testIndex].fIsRect) {
1342 SkRect computed, expected; 1361 SkRect computed, expected;
1343 expected.set(tests[testIndex], testLen[testIndex] / sizeof(SkPoint)) ; 1362 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount) ;
1344 REPORTER_ASSERT(reporter, path.isRect(&computed)); 1363 REPORTER_ASSERT(reporter, path.isRect(&computed));
1345 REPORTER_ASSERT(reporter, expected == computed); 1364 REPORTER_ASSERT(reporter, expected == computed);
1346 1365
1347 bool isClosed; 1366 bool isClosed;
1348 SkPath::Direction direction, cheapDirection; 1367 SkPath::Direction direction, cheapDirection;
1349 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection )); 1368 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection ));
1350 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction)); 1369 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction));
1351 REPORTER_ASSERT(reporter, isClosed == close); 1370 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
1352 REPORTER_ASSERT(reporter, direction == cheapDirection); 1371 REPORTER_ASSERT(reporter, direction == cheapDirection);
1353 } else { 1372 } else {
1354 SkRect computed; 1373 SkRect computed;
1355 computed.set(123, 456, 789, 1011); 1374 computed.set(123, 456, 789, 1011);
1356 REPORTER_ASSERT(reporter, !path.isRect(&computed)); 1375 REPORTER_ASSERT(reporter, !path.isRect(&computed));
1357 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456); 1376 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1358 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011); 1377 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
1359 1378
1360 bool isClosed = (bool) -1; 1379 bool isClosed = (bool) -1;
1361 SkPath::Direction direction = (SkPath::Direction) -1; 1380 SkPath::Direction direction = (SkPath::Direction) -1;
1362 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction)); 1381 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction));
1363 REPORTER_ASSERT(reporter, isClosed == (bool) -1); 1382 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1364 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); 1383 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
1365 } 1384 }
1366
1367 if (tests[testIndex] == lastPass) {
1368 fail = true;
1369 }
1370 if (tests[testIndex] == lastClose) {
1371 close = false;
1372 }
1373 } 1385 }
1374 1386
1375 // fail, close then line 1387 // fail, close then line
1376 SkPath path1; 1388 SkPath path1;
1377 path1.moveTo(r1[0].fX, r1[0].fY); 1389 path1.moveTo(r1[0].fX, r1[0].fY);
1378 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1390 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1379 path1.lineTo(r1[index].fX, r1[index].fY); 1391 path1.lineTo(r1[index].fX, r1[index].fY);
1380 } 1392 }
1381 path1.close(); 1393 path1.close();
1382 path1.lineTo(1, 0); 1394 path1.lineTo(1, 0);
1383 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1395 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
1384 1396
1385 // fail, move in the middle 1397 // fail, move in the middle
1386 path1.reset(); 1398 path1.reset();
1387 path1.moveTo(r1[0].fX, r1[0].fY); 1399 path1.moveTo(r1[0].fX, r1[0].fY);
1388 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1400 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1389 if (index == 2) { 1401 if (index == 2) {
1390 path1.moveTo(1, .5f); 1402 path1.moveTo(1, .5f);
1391 } 1403 }
1392 path1.lineTo(r1[index].fX, r1[index].fY); 1404 path1.lineTo(r1[index].fX, r1[index].fY);
1393 } 1405 }
1394 path1.close(); 1406 path1.close();
1395 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1407 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
1396 1408
1397 // fail, move on the edge 1409 // fail, move on the edge
1398 path1.reset(); 1410 path1.reset();
1399 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1411 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1400 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); 1412 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1401 path1.lineTo(r1[index].fX, r1[index].fY); 1413 path1.lineTo(r1[index].fX, r1[index].fY);
1402 } 1414 }
1403 path1.close(); 1415 path1.close();
1404 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1416 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
1405 1417
1406 // fail, quad 1418 // fail, quad
1407 path1.reset(); 1419 path1.reset();
1408 path1.moveTo(r1[0].fX, r1[0].fY); 1420 path1.moveTo(r1[0].fX, r1[0].fY);
1409 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1421 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1410 if (index == 2) { 1422 if (index == 2) {
1411 path1.quadTo(1, .5f, 1, .5f); 1423 path1.quadTo(1, .5f, 1, .5f);
1412 } 1424 }
1413 path1.lineTo(r1[index].fX, r1[index].fY); 1425 path1.lineTo(r1[index].fX, r1[index].fY);
1414 } 1426 }
1415 path1.close(); 1427 path1.close();
1416 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1428 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
1417 1429
1418 // fail, cubic 1430 // fail, cubic
1419 path1.reset(); 1431 path1.reset();
1420 path1.moveTo(r1[0].fX, r1[0].fY); 1432 path1.moveTo(r1[0].fX, r1[0].fY);
1421 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1433 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1422 if (index == 2) { 1434 if (index == 2) {
1423 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); 1435 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1424 } 1436 }
1425 path1.lineTo(r1[index].fX, r1[index].fY); 1437 path1.lineTo(r1[index].fX, r1[index].fY);
1426 } 1438 }
1427 path1.close(); 1439 path1.close();
1428 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1440 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
1429 } 1441 }
1430 1442
1431 static void test_isNestedRects(skiatest::Reporter* reporter) { 1443 static void test_isNestedRects(skiatest::Reporter* reporter) {
1432 // passing tests (all moveTo / lineTo... 1444 // passing tests (all moveTo / lineTo...
1433 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW 1445 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
1434 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; 1446 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1435 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; 1447 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1436 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; 1448 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1437 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW 1449 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
1438 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1450 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1439 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; 1451 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1440 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; 1452 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1441 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1453 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1442 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, // CCW 1454 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0} , {.5f, 0}}; // CCW
1443 {1, 0}, {.5f, 0}}; 1455 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1} , {0, .5f}}; // CW
1444 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, // CW
1445 {0, 1}, {0, .5f}};
1446 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW 1456 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1447 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW 1457 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1448 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW 1458 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
1449 1459
1450 // failing tests 1460 // failing tests
1451 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points 1461 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1452 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal 1462 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1453 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps 1463 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1454 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up 1464 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1455 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots 1465 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1456 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots 1466 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1457 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots 1467 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1458 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' 1468 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1459 1469
1460 // failing, no close 1470 // failing, no close
1461 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match 1471 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1462 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto 1472 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1463 1473
1464 size_t testLen[] = { 1474 struct IsNestedRectTest {
1465 sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6), 1475 SkPoint *fPoints;
1466 sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc), 1476 size_t fPointCount;
1467 sizeof(rd), sizeof(re), 1477 SkPath::Direction fDirection;
1468 sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6), 1478 bool fClose;
1469 sizeof(f7), sizeof(f8), 1479 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1470 sizeof(c1), sizeof(c2) 1480 } tests[] = {
1481 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1482 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1483 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1484 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1485 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1486 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1487 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1488 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1489 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1490 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1491 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1492 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1493 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1494 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
1495
1496 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1497 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1498 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1499 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1500 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1501 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1502 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1503 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1504
1505 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1506 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1471 }; 1507 };
1472 SkPoint* tests[] = {
1473 r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re,
1474 f1, f2, f3, f4, f5, f6, f7, f8,
1475 c1, c2
1476 };
1477 SkPath::Direction dirs[] = {
1478 SkPath::kCW_Direction, SkPath::kCW_Direction, SkPath::kCW_Direction,
1479 SkPath::kCW_Direction, SkPath::kCCW_Direction, SkPath::kCCW_Direction,
1480 SkPath::kCCW_Direction, SkPath::kCCW_Direction, SkPath::kCCW_Direction,
1481 SkPath::kCCW_Direction, SkPath::kCW_Direction, SkPath::kCW_Direction,
1482 SkPath::kCCW_Direction, SkPath::kCW_Direction, SkPath::kUnknown_Directio n,
1483 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1484 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1485 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1486 };
1487 SkASSERT(SK_ARRAY_COUNT(tests) == SK_ARRAY_COUNT(dirs));
1488 1508
1489 const SkPoint* lastPass = re; 1509 const size_t testCount = SK_ARRAY_COUNT(tests);
1490 const SkPoint* lastClose = f8;
1491 const size_t testCount = sizeof(tests) / sizeof(tests[0]);
1492 size_t index; 1510 size_t index;
1493 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) { 1511 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
1494 bool fail = false;
1495 bool close = true;
1496 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { 1512 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1497 SkPath path; 1513 SkPath path;
1498 if (rectFirst) { 1514 if (rectFirst) {
1499 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1515 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1500 } 1516 }
1501 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); 1517 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints [0].fY);
1502 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++inde x) { 1518 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1503 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index]. fY); 1519 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex] .fPoints[index].fY);
1504 } 1520 }
1505 if (close) { 1521 if (tests[testIndex].fClose) {
1506 path.close(); 1522 path.close();
1507 } 1523 }
1508 if (!rectFirst) { 1524 if (!rectFirst) {
1509 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1525 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1510 } 1526 }
1511 REPORTER_ASSERT(reporter, fail ^ path.isNestedRects(0)); 1527 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isN estedRects(NULL));
1512 if (!fail) { 1528 if (tests[testIndex].fIsNestedRect) {
1513 SkRect expected[2], computed[2]; 1529 SkRect expected[2], computed[2];
1514 SkPath::Direction expectedDirs[2], computedDirs[2]; 1530 SkPath::Direction expectedDirs[2], computedDirs[2];
1515 SkRect testBounds; 1531 SkRect testBounds;
1516 testBounds.set(tests[testIndex], testLen[testIndex] / sizeof(SkP oint)); 1532 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPoint Count);
1517 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2); 1533 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1518 expected[1] = testBounds; 1534 expected[1] = testBounds;
1519 if (rectFirst) { 1535 if (rectFirst) {
1520 expectedDirs[0] = SkPath::kCW_Direction; 1536 expectedDirs[0] = SkPath::kCW_Direction;
1521 } else { 1537 } else {
1522 expectedDirs[0] = SkPath::kCCW_Direction; 1538 expectedDirs[0] = SkPath::kCCW_Direction;
1523 } 1539 }
1524 expectedDirs[1] = dirs[testIndex]; 1540 expectedDirs[1] = tests[testIndex].fDirection;
1525 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedD irs)); 1541 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedD irs));
1526 REPORTER_ASSERT(reporter, expected[0] == computed[0]); 1542 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1527 REPORTER_ASSERT(reporter, expected[1] == computed[1]); 1543 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
1528 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]); 1544 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1529 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]); 1545 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
1530 } 1546 }
1531 if (tests[testIndex] == lastPass) {
1532 fail = true;
1533 }
1534 if (tests[testIndex] == lastClose) {
1535 close = false;
1536 }
1537 } 1547 }
1538 1548
1539 // fail, close then line 1549 // fail, close then line
1540 SkPath path1; 1550 SkPath path1;
1541 if (rectFirst) { 1551 if (rectFirst) {
1542 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1552 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1543 } 1553 }
1544 path1.moveTo(r1[0].fX, r1[0].fY); 1554 path1.moveTo(r1[0].fX, r1[0].fY);
1545 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1555 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1546 path1.lineTo(r1[index].fX, r1[index].fY); 1556 path1.lineTo(r1[index].fX, r1[index].fY);
1547 } 1557 }
1548 path1.close(); 1558 path1.close();
1549 path1.lineTo(1, 0); 1559 path1.lineTo(1, 0);
1550 if (!rectFirst) { 1560 if (!rectFirst) {
1551 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1561 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1552 } 1562 }
1553 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1563 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1554 1564
1555 // fail, move in the middle 1565 // fail, move in the middle
1556 path1.reset(); 1566 path1.reset();
1557 if (rectFirst) { 1567 if (rectFirst) {
1558 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1568 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1559 } 1569 }
1560 path1.moveTo(r1[0].fX, r1[0].fY); 1570 path1.moveTo(r1[0].fX, r1[0].fY);
1561 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1571 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1562 if (index == 2) { 1572 if (index == 2) {
1563 path1.moveTo(1, .5f); 1573 path1.moveTo(1, .5f);
1564 } 1574 }
1565 path1.lineTo(r1[index].fX, r1[index].fY); 1575 path1.lineTo(r1[index].fX, r1[index].fY);
1566 } 1576 }
1567 path1.close(); 1577 path1.close();
1568 if (!rectFirst) { 1578 if (!rectFirst) {
1569 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1579 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1570 } 1580 }
1571 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1581 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1572 1582
1573 // fail, move on the edge 1583 // fail, move on the edge
1574 path1.reset(); 1584 path1.reset();
1575 if (rectFirst) { 1585 if (rectFirst) {
1576 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1586 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1577 } 1587 }
1578 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1588 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1579 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); 1589 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1580 path1.lineTo(r1[index].fX, r1[index].fY); 1590 path1.lineTo(r1[index].fX, r1[index].fY);
1581 } 1591 }
1582 path1.close(); 1592 path1.close();
1583 if (!rectFirst) { 1593 if (!rectFirst) {
1584 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1594 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1585 } 1595 }
1586 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1596 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1587 1597
1588 // fail, quad 1598 // fail, quad
1589 path1.reset(); 1599 path1.reset();
1590 if (rectFirst) { 1600 if (rectFirst) {
1591 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1601 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1592 } 1602 }
1593 path1.moveTo(r1[0].fX, r1[0].fY); 1603 path1.moveTo(r1[0].fX, r1[0].fY);
1594 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1604 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1595 if (index == 2) { 1605 if (index == 2) {
1596 path1.quadTo(1, .5f, 1, .5f); 1606 path1.quadTo(1, .5f, 1, .5f);
1597 } 1607 }
1598 path1.lineTo(r1[index].fX, r1[index].fY); 1608 path1.lineTo(r1[index].fX, r1[index].fY);
1599 } 1609 }
1600 path1.close(); 1610 path1.close();
1601 if (!rectFirst) { 1611 if (!rectFirst) {
1602 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1612 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1603 } 1613 }
1604 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1614 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1605 1615
1606 // fail, cubic 1616 // fail, cubic
1607 path1.reset(); 1617 path1.reset();
1608 if (rectFirst) { 1618 if (rectFirst) {
1609 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1619 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1610 } 1620 }
1611 path1.moveTo(r1[0].fX, r1[0].fY); 1621 path1.moveTo(r1[0].fX, r1[0].fY);
1612 for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { 1622 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
1613 if (index == 2) { 1623 if (index == 2) {
1614 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); 1624 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1615 } 1625 }
1616 path1.lineTo(r1[index].fX, r1[index].fY); 1626 path1.lineTo(r1[index].fX, r1[index].fY);
1617 } 1627 }
1618 path1.close(); 1628 path1.close();
1619 if (!rectFirst) { 1629 if (!rectFirst) {
1620 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1630 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1621 } 1631 }
1622 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1632 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1623 1633
1624 // fail, not nested 1634 // fail, not nested
1625 path1.reset(); 1635 path1.reset();
1626 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction); 1636 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
1627 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction); 1637 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
1628 REPORTER_ASSERT(reporter, fail ^ path1.isNestedRects(0)); 1638 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
1629 } 1639 }
1630 1640
1631 // pass, stroke rect 1641 // pass, stroke rect
1632 SkPath src, dst; 1642 SkPath src, dst;
1633 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction); 1643 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
1634 SkPaint strokePaint; 1644 SkPaint strokePaint;
1635 strokePaint.setStyle(SkPaint::kStroke_Style); 1645 strokePaint.setStyle(SkPaint::kStroke_Style);
1636 strokePaint.setStrokeWidth(2); 1646 strokePaint.setStrokeWidth(2);
1637 strokePaint.getFillPath(src, &dst); 1647 strokePaint.getFillPath(src, &dst);
1638 REPORTER_ASSERT(reporter, dst.isNestedRects(0)); 1648 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
1639 } 1649 }
1640 1650
1641 static void write_and_read_back(skiatest::Reporter* reporter, 1651 static void write_and_read_back(skiatest::Reporter* reporter,
1642 const SkPath& p) { 1652 const SkPath& p) {
1643 SkWriter32 writer(100); 1653 SkWriter32 writer(100);
1644 writer.writePath(p); 1654 writer.writePath(p);
1645 size_t size = writer.size(); 1655 size_t size = writer.size();
1646 SkAutoMalloc storage(size); 1656 SkAutoMalloc storage(size);
1647 writer.flatten(storage.get()); 1657 writer.flatten(storage.get());
1648 SkReader32 reader(storage.get(), size); 1658 SkReader32 reader(storage.get(), size);
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
2542 test_clipped_cubic(); 2552 test_clipped_cubic();
2543 test_crbug_170666(); 2553 test_crbug_170666();
2544 test_bad_cubic_crbug229478(); 2554 test_bad_cubic_crbug229478();
2545 test_bad_cubic_crbug234190(); 2555 test_bad_cubic_crbug234190();
2546 test_android_specific_behavior(reporter); 2556 test_android_specific_behavior(reporter);
2547 test_path_close_issue1474(reporter); 2557 test_path_close_issue1474(reporter);
2548 } 2558 }
2549 2559
2550 #include "TestClassDef.h" 2560 #include "TestClassDef.h"
2551 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) 2561 DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698