OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 SkPath::Direction dir; | 1301 SkPath::Direction dir; |
1302 bool foundDir = copy.cheapComputeDirection(&dir); | 1302 bool foundDir = copy.cheapComputeDirection(&dir); |
1303 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUn
known_Direction) | 1303 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUn
known_Direction) |
1304 ^ foundDir); | 1304 ^ foundDir); |
1305 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection ==
dir); | 1305 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection ==
dir); |
1306 check_convexity(reporter, copy, gRec[i].fExpectedConvexity); | 1306 check_convexity(reporter, copy, gRec[i].fExpectedConvexity); |
1307 } | 1307 } |
1308 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexit
y()); | 1308 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexit
y()); |
1309 check_direction(reporter, path, gRec[i].fExpectedDirection); | 1309 check_direction(reporter, path, gRec[i].fExpectedDirection); |
1310 } | 1310 } |
| 1311 |
| 1312 static const SkPoint nonFinitePts[] = { |
| 1313 { SK_ScalarInfinity, 0 }, |
| 1314 { 0, SK_ScalarInfinity }, |
| 1315 { SK_ScalarInfinity, SK_ScalarInfinity }, |
| 1316 { SK_ScalarNegativeInfinity, 0}, |
| 1317 { 0, SK_ScalarNegativeInfinity }, |
| 1318 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity }, |
| 1319 { SK_ScalarNegativeInfinity, SK_ScalarInfinity }, |
| 1320 { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, |
| 1321 { SK_ScalarNaN, 0 }, |
| 1322 { 0, SK_ScalarNaN }, |
| 1323 { SK_ScalarNaN, SK_ScalarNaN }, |
| 1324 }; |
| 1325 |
| 1326 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[
0]); |
| 1327 |
| 1328 static const SkPoint finitePts[] = { |
| 1329 { SK_ScalarMax, 0 }, |
| 1330 { 0, SK_ScalarMax }, |
| 1331 { SK_ScalarMax, SK_ScalarMax }, |
| 1332 { SK_ScalarMin, 0 }, |
| 1333 { 0, SK_ScalarMin }, |
| 1334 { SK_ScalarMin, SK_ScalarMin }, |
| 1335 }; |
| 1336 |
| 1337 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]); |
| 1338 |
| 1339 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount);
++index) { |
| 1340 int i = (int) (index % nonFinitePtsCount); |
| 1341 int f = (int) (index % finitePtsCount); |
| 1342 int g = (int) ((f + 1) % finitePtsCount); |
| 1343 path.reset(); |
| 1344 switch (index % 13) { |
| 1345 case 0: path.lineTo(nonFinitePts[i]); break; |
| 1346 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break; |
| 1347 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break; |
| 1348 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break; |
| 1349 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); b
reak; |
| 1350 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); b
reak; |
| 1351 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); b
reak; |
| 1352 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f])
; break; |
| 1353 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i])
; break; |
| 1354 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i])
; break; |
| 1355 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts
[i]); break; |
| 1356 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]);
break; |
| 1357 case 12: path.moveTo(nonFinitePts[i]); break; |
| 1358 } |
| 1359 check_convexity(reporter, path, SkPath::kUnknown_Convexity); |
| 1360 } |
| 1361 |
| 1362 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) { |
| 1363 int f = (int) (index % finitePtsCount); |
| 1364 int g = (int) ((f + 1) % finitePtsCount); |
| 1365 path.reset(); |
| 1366 int curveSelect = index % 11; |
| 1367 switch (curveSelect) { |
| 1368 case 0: path.moveTo(finitePts[f]); break; |
| 1369 case 1: path.lineTo(finitePts[f]); break; |
| 1370 case 2: path.quadTo(finitePts[f], finitePts[f]); break; |
| 1371 case 3: path.quadTo(finitePts[f], finitePts[g]); break; |
| 1372 case 4: path.quadTo(finitePts[g], finitePts[f]); break; |
| 1373 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); brea
k; |
| 1374 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); brea
k; |
| 1375 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); brea
k; |
| 1376 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); brea
k; |
| 1377 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); brea
k; |
| 1378 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); bre
ak; |
| 1379 } |
| 1380 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Conve
xity |
| 1381 : SkPath::kUnknown_Convexity); |
| 1382 } |
| 1383 |
1311 } | 1384 } |
1312 | 1385 |
1313 static void test_isLine(skiatest::Reporter* reporter) { | 1386 static void test_isLine(skiatest::Reporter* reporter) { |
1314 SkPath path; | 1387 SkPath path; |
1315 SkPoint pts[2]; | 1388 SkPoint pts[2]; |
1316 const SkScalar value = SkIntToScalar(5); | 1389 const SkScalar value = SkIntToScalar(5); |
1317 | 1390 |
1318 REPORTER_ASSERT(reporter, !path.isLine(NULL)); | 1391 REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
1319 | 1392 |
1320 // set some non-zero values | 1393 // set some non-zero values |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2952 | 3025 |
2953 static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path, | 3026 static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path, |
2954 SkPath::Direction dir) { | 3027 SkPath::Direction dir) { |
2955 REPORTER_ASSERT(reporter, path->isConvex()); | 3028 REPORTER_ASSERT(reporter, path->isConvex()); |
2956 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir)); | 3029 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir)); |
2957 path->setConvexity(SkPath::kUnknown_Convexity); | 3030 path->setConvexity(SkPath::kUnknown_Convexity); |
2958 REPORTER_ASSERT(reporter, path->isConvex()); | 3031 REPORTER_ASSERT(reporter, path->isConvex()); |
2959 path->reset(); | 3032 path->reset(); |
2960 } | 3033 } |
2961 | 3034 |
| 3035 static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath
* path, |
| 3036 SkPath::Direction dir) { |
| 3037 REPORTER_ASSERT(reporter, path->isConvex()); |
| 3038 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir)); |
| 3039 path->setConvexity(SkPath::kUnknown_Convexity); |
| 3040 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity
); |
| 3041 path->reset(); |
| 3042 } |
| 3043 |
2962 static void test_rrect(skiatest::Reporter* reporter) { | 3044 static void test_rrect(skiatest::Reporter* reporter) { |
2963 SkPath p; | 3045 SkPath p; |
2964 SkRRect rr; | 3046 SkRRect rr; |
2965 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; | 3047 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; |
2966 SkRect r = {10, 20, 30, 40}; | 3048 SkRect r = {10, 20, 30, 40}; |
2967 rr.setRectRadii(r, radii); | 3049 rr.setRectRadii(r, radii); |
2968 p.addRRect(rr); | 3050 p.addRRect(rr); |
2969 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); | 3051 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
2970 p.addRRect(rr, SkPath::kCCW_Direction); | 3052 p.addRRect(rr, SkPath::kCCW_Direction); |
2971 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); | 3053 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3007 p.addRRect(rr, SkPath::kCCW_Direction); | 3089 p.addRRect(rr, SkPath::kCCW_Direction); |
3008 REPORTER_ASSERT(reporter, !p.isConvex()); | 3090 REPORTER_ASSERT(reporter, !p.isConvex()); |
3009 p.reset(); | 3091 p.reset(); |
3010 SkRect emptyR = {10, 20, 10, 30}; | 3092 SkRect emptyR = {10, 20, 10, 30}; |
3011 rr.setRectRadii(emptyR, radii); | 3093 rr.setRectRadii(emptyR, radii); |
3012 p.addRRect(rr); | 3094 p.addRRect(rr); |
3013 REPORTER_ASSERT(reporter, p.isEmpty()); | 3095 REPORTER_ASSERT(reporter, p.isEmpty()); |
3014 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax}; | 3096 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax}; |
3015 rr.setRectRadii(largeR, radii); | 3097 rr.setRectRadii(largeR, radii); |
3016 p.addRRect(rr); | 3098 p.addRRect(rr); |
3017 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); | 3099 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction); |
3018 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity}; | 3100 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity}; |
3019 rr.setRectRadii(infR, radii); | 3101 rr.setRectRadii(infR, radii); |
3020 p.addRRect(rr); | 3102 p.addRRect(rr); |
3021 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); | 3103 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction); |
3022 SkRect tinyR = {0, 0, 1e-9f, 1e-9f}; | 3104 SkRect tinyR = {0, 0, 1e-9f, 1e-9f}; |
3023 p.addRoundRect(tinyR, 5e-11f, 5e-11f); | 3105 p.addRoundRect(tinyR, 5e-11f, 5e-11f); |
3024 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); | 3106 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
3025 } | 3107 } |
3026 | 3108 |
3027 static void test_arc(skiatest::Reporter* reporter) { | 3109 static void test_arc(skiatest::Reporter* reporter) { |
3028 SkPath p; | 3110 SkPath p; |
3029 SkRect emptyOval = {10, 20, 30, 20}; | 3111 SkRect emptyOval = {10, 20, 30, 20}; |
3030 REPORTER_ASSERT(reporter, emptyOval.isEmpty()); | 3112 REPORTER_ASSERT(reporter, emptyOval.isEmpty()); |
3031 p.addArc(emptyOval, 1, 2); | 3113 p.addArc(emptyOval, 1, 2); |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3641 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); | 3723 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); |
3642 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); | 3724 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); |
3643 test_conicTo_special_case(reporter); | 3725 test_conicTo_special_case(reporter); |
3644 test_get_point(reporter); | 3726 test_get_point(reporter); |
3645 test_contains(reporter); | 3727 test_contains(reporter); |
3646 PathTest_Private::TestPathTo(reporter); | 3728 PathTest_Private::TestPathTo(reporter); |
3647 PathRefTest_Private::TestPathRef(reporter); | 3729 PathRefTest_Private::TestPathRef(reporter); |
3648 test_dump(reporter); | 3730 test_dump(reporter); |
3649 test_path_crbugskia2820(reporter); | 3731 test_path_crbugskia2820(reporter); |
3650 } | 3732 } |
OLD | NEW |