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 "Test.h" | 8 #include "Test.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 350 |
351 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000)); | 351 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000)); |
352 | 352 |
353 build_path_simple_170666(path); | 353 build_path_simple_170666(path); |
354 surface->getCanvas()->drawPath(path, paint); | 354 surface->getCanvas()->drawPath(path, paint); |
355 | 355 |
356 build_path_170666(path); | 356 build_path_170666(path); |
357 surface->getCanvas()->drawPath(path, paint); | 357 surface->getCanvas()->drawPath(path, paint); |
358 } | 358 } |
359 | 359 |
| 360 static void test_addrect(skiatest::Reporter* reporter) { |
| 361 SkPath path; |
| 362 path.lineTo(0, 0); |
| 363 path.addRect(SkRect::MakeWH(50, 100)); |
| 364 REPORTER_ASSERT(reporter, path.isRect(NULL)); |
| 365 |
| 366 path.reset(); |
| 367 path.lineTo(FLT_EPSILON, FLT_EPSILON); |
| 368 path.addRect(SkRect::MakeWH(50, 100)); |
| 369 REPORTER_ASSERT(reporter, !path.isRect(NULL)); |
| 370 |
| 371 path.reset(); |
| 372 path.quadTo(0, 0, 0, 0); |
| 373 path.addRect(SkRect::MakeWH(50, 100)); |
| 374 REPORTER_ASSERT(reporter, !path.isRect(NULL)); |
| 375 |
| 376 path.reset(); |
| 377 path.conicTo(0, 0, 0, 0, 0.5f); |
| 378 path.addRect(SkRect::MakeWH(50, 100)); |
| 379 REPORTER_ASSERT(reporter, !path.isRect(NULL)); |
| 380 |
| 381 path.reset(); |
| 382 path.cubicTo(0, 0, 0, 0, 0, 0); |
| 383 path.addRect(SkRect::MakeWH(50, 100)); |
| 384 REPORTER_ASSERT(reporter, !path.isRect(NULL)); |
| 385 } |
| 386 |
360 // Make sure we stay non-finite once we get there (unless we reset or rewind). | 387 // Make sure we stay non-finite once we get there (unless we reset or rewind). |
361 static void test_addrect_isfinite(skiatest::Reporter* reporter) { | 388 static void test_addrect_isfinite(skiatest::Reporter* reporter) { |
362 SkPath path; | 389 SkPath path; |
363 | 390 |
364 path.addRect(SkRect::MakeWH(50, 100)); | 391 path.addRect(SkRect::MakeWH(50, 100)); |
365 REPORTER_ASSERT(reporter, path.isFinite()); | 392 REPORTER_ASSERT(reporter, path.isFinite()); |
366 | 393 |
367 path.moveTo(0, 0); | 394 path.moveTo(0, 0); |
368 path.lineTo(SK_ScalarInfinity, 42); | 395 path.lineTo(SK_ScalarInfinity, 42); |
369 REPORTER_ASSERT(reporter, !path.isFinite()); | 396 REPORTER_ASSERT(reporter, !path.isFinite()); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 | 831 |
805 #ifdef SK_SCALAR_IS_FLOAT | 832 #ifdef SK_SCALAR_IS_FLOAT |
806 // triangle with one point really far from the origin. | 833 // triangle with one point really far from the origin. |
807 path.reset(); | 834 path.reset(); |
808 // the first point is roughly 1.05e10, 1.05e10 | 835 // the first point is roughly 1.05e10, 1.05e10 |
809 path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBit
s2Float(0x501c7652))); | 836 path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBit
s2Float(0x501c7652))); |
810 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1); | 837 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1); |
811 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1); | 838 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1); |
812 check_direction(reporter, path, SkPath::kCCW_Direction); | 839 check_direction(reporter, path, SkPath::kCCW_Direction); |
813 #endif | 840 #endif |
| 841 |
| 842 path.reset(); |
| 843 path.conicTo(20, 0, 20, 20, 0.5f); |
| 844 path.close(); |
| 845 check_direction(reporter, path, SkPath::kCW_Direction); |
| 846 |
| 847 path.reset(); |
| 848 path.lineTo(1, 1e7f); |
| 849 path.lineTo(1e7f, 2e7f); |
| 850 path.close(); |
| 851 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity()); |
| 852 check_direction(reporter, path, SkPath::kCCW_Direction); |
814 } | 853 } |
815 | 854 |
816 static void add_rect(SkPath* path, const SkRect& r) { | 855 static void add_rect(SkPath* path, const SkRect& r) { |
817 path->moveTo(r.fLeft, r.fTop); | 856 path->moveTo(r.fLeft, r.fTop); |
818 path->lineTo(r.fRight, r.fTop); | 857 path->lineTo(r.fRight, r.fTop); |
819 path->lineTo(r.fRight, r.fBottom); | 858 path->lineTo(r.fRight, r.fBottom); |
820 path->lineTo(r.fLeft, r.fBottom); | 859 path->lineTo(r.fLeft, r.fBottom); |
821 path->close(); | 860 path->close(); |
822 } | 861 } |
823 | 862 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction }, | 1178 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction }, |
1140 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir }, | 1179 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir }, |
1141 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direc
tion }, | 1180 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direc
tion }, |
1142 }; | 1181 }; |
1143 | 1182 |
1144 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { | 1183 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
1145 SkPath path; | 1184 SkPath path; |
1146 setFromString(&path, gRec[i].fPathStr); | 1185 setFromString(&path, gRec[i].fPathStr); |
1147 check_convexity(reporter, path, gRec[i].fExpectedConvexity); | 1186 check_convexity(reporter, path, gRec[i].fExpectedConvexity); |
1148 check_direction(reporter, path, gRec[i].fExpectedDirection); | 1187 check_direction(reporter, path, gRec[i].fExpectedDirection); |
| 1188 // check after setting the initial convex and direction |
| 1189 if (kDontCheckDir != gRec[i].fExpectedDirection) { |
| 1190 SkPath copy(path); |
| 1191 SkPath::Direction dir; |
| 1192 bool foundDir = copy.cheapComputeDirection(&dir); |
| 1193 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUn
known_Direction) |
| 1194 ^ foundDir); |
| 1195 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection ==
dir); |
| 1196 check_convexity(reporter, copy, gRec[i].fExpectedConvexity); |
| 1197 } |
| 1198 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexit
y()); |
| 1199 check_direction(reporter, path, gRec[i].fExpectedDirection); |
1149 } | 1200 } |
1150 } | 1201 } |
1151 | 1202 |
1152 static void test_isLine(skiatest::Reporter* reporter) { | 1203 static void test_isLine(skiatest::Reporter* reporter) { |
1153 SkPath path; | 1204 SkPath path; |
1154 SkPoint pts[2]; | 1205 SkPoint pts[2]; |
1155 const SkScalar value = SkIntToScalar(5); | 1206 const SkScalar value = SkIntToScalar(5); |
1156 | 1207 |
1157 REPORTER_ASSERT(reporter, !path.isLine(NULL)); | 1208 REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
1158 | 1209 |
1159 // set some non-zero values | 1210 // set some non-zero values |
1160 pts[0].set(value, value); | 1211 pts[0].set(value, value); |
1161 pts[1].set(value, value); | 1212 pts[1].set(value, value); |
1162 REPORTER_ASSERT(reporter, !path.isLine(pts)); | 1213 REPORTER_ASSERT(reporter, !path.isLine(pts)); |
1163 // check that pts was untouched | 1214 // check that pts was untouched |
1164 REPORTER_ASSERT(reporter, pts[0].equals(value, value)); | 1215 REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
1165 REPORTER_ASSERT(reporter, pts[1].equals(value, value)); | 1216 REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
1166 | 1217 |
1167 const SkScalar moveX = SkIntToScalar(1); | 1218 const SkScalar moveX = SkIntToScalar(1); |
1168 const SkScalar moveY = SkIntToScalar(2); | 1219 const SkScalar moveY = SkIntToScalar(2); |
1169 SkASSERT(value != moveX && value != moveY); | 1220 REPORTER_ASSERT(reporter, value != moveX && value != moveY); |
1170 | 1221 |
1171 path.moveTo(moveX, moveY); | 1222 path.moveTo(moveX, moveY); |
1172 REPORTER_ASSERT(reporter, !path.isLine(NULL)); | 1223 REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
1173 REPORTER_ASSERT(reporter, !path.isLine(pts)); | 1224 REPORTER_ASSERT(reporter, !path.isLine(pts)); |
1174 // check that pts was untouched | 1225 // check that pts was untouched |
1175 REPORTER_ASSERT(reporter, pts[0].equals(value, value)); | 1226 REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
1176 REPORTER_ASSERT(reporter, pts[1].equals(value, value)); | 1227 REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
1177 | 1228 |
1178 const SkScalar lineX = SkIntToScalar(2); | 1229 const SkScalar lineX = SkIntToScalar(2); |
1179 const SkScalar lineY = SkIntToScalar(2); | 1230 const SkScalar lineY = SkIntToScalar(2); |
1180 SkASSERT(value != lineX && value != lineY); | 1231 REPORTER_ASSERT(reporter, value != lineX && value != lineY); |
1181 | 1232 |
1182 path.lineTo(lineX, lineY); | 1233 path.lineTo(lineX, lineY); |
1183 REPORTER_ASSERT(reporter, path.isLine(NULL)); | 1234 REPORTER_ASSERT(reporter, path.isLine(NULL)); |
1184 | 1235 |
1185 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY)); | 1236 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY)); |
1186 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY)); | 1237 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY)); |
1187 REPORTER_ASSERT(reporter, path.isLine(pts)); | 1238 REPORTER_ASSERT(reporter, path.isLine(pts)); |
1188 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); | 1239 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
1189 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); | 1240 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
1190 | 1241 |
1191 path.lineTo(0, 0); // too many points/verbs | 1242 path.lineTo(0, 0); // too many points/verbs |
1192 REPORTER_ASSERT(reporter, !path.isLine(NULL)); | 1243 REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
1193 REPORTER_ASSERT(reporter, !path.isLine(pts)); | 1244 REPORTER_ASSERT(reporter, !path.isLine(pts)); |
1194 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); | 1245 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
1195 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); | 1246 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 1247 |
| 1248 path.reset(); |
| 1249 path.quadTo(1, 1, 2, 2); |
| 1250 REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
1196 } | 1251 } |
1197 | 1252 |
1198 static void test_conservativelyContains(skiatest::Reporter* reporter) { | 1253 static void test_conservativelyContains(skiatest::Reporter* reporter) { |
1199 SkPath path; | 1254 SkPath path; |
1200 | 1255 |
1201 // kBaseRect is used to construct most our test paths: a rect, a circle, and
a round-rect. | 1256 // kBaseRect is used to construct most our test paths: a rect, a circle, and
a round-rect. |
1202 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToSc
alar(100)); | 1257 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToSc
alar(100)); |
1203 | 1258 |
1204 // A circle that bounds kBaseRect (with a significant amount of slop) | 1259 // A circle that bounds kBaseRect (with a significant amount of slop) |
1205 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height()); | 1260 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height()); |
1206 circleR = SkScalarMul(circleR, SkFloatToScalar(1.75f)) / 2; | 1261 circleR = SkScalarMul(circleR, 1.75f) / 2; |
1207 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()}; | 1262 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()}; |
1208 | 1263 |
1209 // round-rect radii | 1264 // round-rect radii |
1210 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)}; | 1265 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)}; |
1211 | 1266 |
1212 static const struct SUPPRESS_VISIBILITY_WARNING { | 1267 static const struct SUPPRESS_VISIBILITY_WARNING { |
1213 SkRect fQueryRect; | 1268 SkRect fQueryRect; |
1214 bool fInRect; | 1269 bool fInRect; |
1215 bool fInCircle; | 1270 bool fInCircle; |
1216 bool fInRR; | 1271 bool fInRR; |
| 1272 bool fInCubicRR; |
1217 } kQueries[] = { | 1273 } kQueries[] = { |
1218 {kBaseRect, true, true, false}, | 1274 {kBaseRect, true, true, false, false}, |
1219 | 1275 |
1220 // rect well inside of kBaseRect | 1276 // rect well inside of kBaseRect |
1221 {SkRect::MakeLTRB(kBaseRect.fLeft + SkFloatToScalar(0.25f)*kBaseRect.wid
th(), | 1277 {SkRect::MakeLTRB(kBaseRect.fLeft + SkFloatToScalar(0.25f)*kBaseRect.wid
th(), |
1222 kBaseRect.fTop + SkFloatToScalar(0.25f)*kBaseRect.heig
ht(), | 1278 kBaseRect.fTop + SkFloatToScalar(0.25f)*kBaseRect.heig
ht(), |
1223 kBaseRect.fRight - SkFloatToScalar(0.25f)*kBaseRect.wi
dth(), | 1279 kBaseRect.fRight - SkFloatToScalar(0.25f)*kBaseRect.wi
dth(), |
1224 kBaseRect.fBottom - SkFloatToScalar(0.25f)*kBaseRect.h
eight()), | 1280 kBaseRect.fBottom - SkFloatToScalar(0.25f)*kBaseRect.h
eight()), |
1225 true, true, true}, | 1281 true, true, true, true}, |
1226 | 1282 |
1227 // rects with edges off by one from kBaseRect's edges | 1283 // rects with edges off by one from kBaseRect's edges |
1228 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, | 1284 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
1229 kBaseRect.width(), kBaseRect.height() + 1), | 1285 kBaseRect.width(), kBaseRect.height() + 1), |
1230 false, true, false}, | 1286 false, true, false, false}, |
1231 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, | 1287 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
1232 kBaseRect.width() + 1, kBaseRect.height()), | 1288 kBaseRect.width() + 1, kBaseRect.height()), |
1233 false, true, false}, | 1289 false, true, false, false}, |
1234 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, | 1290 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
1235 kBaseRect.width() + 1, kBaseRect.height() + 1), | 1291 kBaseRect.width() + 1, kBaseRect.height() + 1), |
1236 false, true, false}, | 1292 false, true, false, false}, |
1237 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, | 1293 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
1238 kBaseRect.width(), kBaseRect.height()), | 1294 kBaseRect.width(), kBaseRect.height()), |
1239 false, true, false}, | 1295 false, true, false, false}, |
1240 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, | 1296 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
1241 kBaseRect.width(), kBaseRect.height()), | 1297 kBaseRect.width(), kBaseRect.height()), |
1242 false, true, false}, | 1298 false, true, false, false}, |
1243 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, | 1299 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
1244 kBaseRect.width() + 2, kBaseRect.height()), | 1300 kBaseRect.width() + 2, kBaseRect.height()), |
1245 false, true, false}, | 1301 false, true, false, false}, |
1246 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, | 1302 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
1247 kBaseRect.width() + 2, kBaseRect.height()), | 1303 kBaseRect.width() + 2, kBaseRect.height()), |
1248 false, true, false}, | 1304 false, true, false, false}, |
1249 | 1305 |
1250 // zero-w/h rects at each corner of kBaseRect | 1306 // zero-w/h rects at each corner of kBaseRect |
1251 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, fa
lse}, | 1307 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, fa
lse, false}, |
1252 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, f
alse}, | 1308 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, f
alse, true}, |
1253 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true,
false}, | 1309 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true,
false, true}, |
1254 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true
, false}, | 1310 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true
, false, true}, |
1255 | 1311 |
1256 // far away rect | 1312 // far away rect |
1257 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom, | 1313 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom, |
1258 SkIntToScalar(10), SkIntToScalar(10)), | 1314 SkIntToScalar(10), SkIntToScalar(10)), |
1259 false, false, false}, | 1315 false, false, false, false}, |
1260 | 1316 |
1261 // very large rect containing kBaseRect | 1317 // very large rect containing kBaseRect |
1262 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(), | 1318 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(), |
1263 kBaseRect.fTop - 5 * kBaseRect.height(), | 1319 kBaseRect.fTop - 5 * kBaseRect.height(), |
1264 11 * kBaseRect.width(), 11 * kBaseRect.height()), | 1320 11 * kBaseRect.width(), 11 * kBaseRect.height()), |
1265 false, false, false}, | 1321 false, false, false, false}, |
1266 | 1322 |
1267 // skinny rect that spans same y-range as kBaseRect | 1323 // skinny rect that spans same y-range as kBaseRect |
1268 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, | 1324 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
1269 SkIntToScalar(1), kBaseRect.height()), | 1325 SkIntToScalar(1), kBaseRect.height()), |
1270 true, true, true}, | 1326 true, true, true, true}, |
1271 | 1327 |
1272 // short rect that spans same x-range as kBaseRect | 1328 // short rect that spans same x-range as kBaseRect |
1273 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(
), SkScalar(1)), | 1329 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(
), SkScalar(1)), |
1274 true, true, true}, | 1330 true, true, true, true}, |
1275 | 1331 |
1276 // skinny rect that spans slightly larger y-range than kBaseRect | 1332 // skinny rect that spans slightly larger y-range than kBaseRect |
1277 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, | 1333 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
1278 SkIntToScalar(1), kBaseRect.height() + 1), | 1334 SkIntToScalar(1), kBaseRect.height() + 1), |
1279 false, true, false}, | 1335 false, true, false, false}, |
1280 | 1336 |
1281 // short rect that spans slightly larger x-range than kBaseRect | 1337 // short rect that spans slightly larger x-range than kBaseRect |
1282 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), | 1338 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), |
1283 kBaseRect.width() + 1, SkScalar(1)), | 1339 kBaseRect.width() + 1, SkScalar(1)), |
1284 false, true, false}, | 1340 false, true, false, false}, |
1285 }; | 1341 }; |
1286 | 1342 |
1287 for (int inv = 0; inv < 4; ++inv) { | 1343 for (int inv = 0; inv < 4; ++inv) { |
1288 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) { | 1344 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) { |
1289 SkRect qRect = kQueries[q].fQueryRect; | 1345 SkRect qRect = kQueries[q].fQueryRect; |
1290 if (inv & 0x1) { | 1346 if (inv & 0x1) { |
1291 SkTSwap(qRect.fLeft, qRect.fRight); | 1347 SkTSwap(qRect.fLeft, qRect.fRight); |
1292 } | 1348 } |
1293 if (inv & 0x2) { | 1349 if (inv & 0x2) { |
1294 SkTSwap(qRect.fTop, qRect.fBottom); | 1350 SkTSwap(qRect.fTop, qRect.fBottom); |
1295 } | 1351 } |
1296 for (int d = 0; d < 2; ++d) { | 1352 for (int d = 0; d < 2; ++d) { |
1297 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; | 1353 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW
_Direction; |
1298 path.reset(); | 1354 path.reset(); |
1299 path.addRect(kBaseRect, dir); | 1355 path.addRect(kBaseRect, dir); |
1300 REPORTER_ASSERT(reporter, kQueries[q].fInRect == | 1356 REPORTER_ASSERT(reporter, kQueries[q].fInRect == |
1301 path.conservativelyContainsRect(qRect)
); | 1357 path.conservativelyContainsRect(qRect)
); |
1302 | 1358 |
1303 path.reset(); | 1359 path.reset(); |
1304 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir); | 1360 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir); |
1305 REPORTER_ASSERT(reporter, kQueries[q].fInCircle == | 1361 REPORTER_ASSERT(reporter, kQueries[q].fInCircle == |
1306 path.conservativelyContainsRect(qRect)
); | 1362 path.conservativelyContainsRect(qRect)
); |
1307 | 1363 |
1308 path.reset(); | 1364 path.reset(); |
1309 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir); | 1365 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir); |
1310 REPORTER_ASSERT(reporter, kQueries[q].fInRR == | 1366 REPORTER_ASSERT(reporter, kQueries[q].fInRR == |
1311 path.conservativelyContainsRect(qRect)
); | 1367 path.conservativelyContainsRect(qRect)
); |
| 1368 |
| 1369 path.reset(); |
| 1370 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop); |
| 1371 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop, |
| 1372 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2, |
| 1373 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]); |
| 1374 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom); |
| 1375 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom); |
| 1376 path.lineTo(kBaseRect.fRight, kBaseRect.fTop); |
| 1377 path.close(); |
| 1378 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR == |
| 1379 path.conservativelyContainsRect(qRect)
); |
| 1380 |
1312 } | 1381 } |
1313 // Slightly non-convex shape, shouldn't contain any rects. | 1382 // Slightly non-convex shape, shouldn't contain any rects. |
1314 path.reset(); | 1383 path.reset(); |
1315 path.moveTo(0, 0); | 1384 path.moveTo(0, 0); |
1316 path.lineTo(SkIntToScalar(50), SkFloatToScalar(0.05f)); | 1385 path.lineTo(SkIntToScalar(50), SkFloatToScalar(0.05f)); |
1317 path.lineTo(SkIntToScalar(100), 0); | 1386 path.lineTo(SkIntToScalar(100), 0); |
1318 path.lineTo(SkIntToScalar(100), SkIntToScalar(100)); | 1387 path.lineTo(SkIntToScalar(100), SkIntToScalar(100)); |
1319 path.lineTo(0, SkIntToScalar(100)); | 1388 path.lineTo(0, SkIntToScalar(100)); |
1320 path.close(); | 1389 path.close(); |
1321 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect)); | 1390 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 path.reset(); | 1423 path.reset(); |
1355 path.moveTo(100, 100); | 1424 path.moveTo(100, 100); |
1356 path.moveTo(0, 0); | 1425 path.moveTo(0, 0); |
1357 path.lineTo(SkIntToScalar(100), 0); | 1426 path.lineTo(SkIntToScalar(100), 0); |
1358 path.lineTo(0, SkIntToScalar(100)); | 1427 path.lineTo(0, SkIntToScalar(100)); |
1359 | 1428 |
1360 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(S
kIntToScalar(50), 0, | 1429 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(S
kIntToScalar(50), 0, |
1361 S
kIntToScalar(10), | 1430 S
kIntToScalar(10), |
1362 S
kIntToScalar(10)))); | 1431 S
kIntToScalar(10)))); |
1363 | 1432 |
| 1433 path.reset(); |
| 1434 path.lineTo(100, 100); |
| 1435 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(
0, 0, 1, 1))); |
1364 } | 1436 } |
1365 | 1437 |
1366 static void test_isRect_open_close(skiatest::Reporter* reporter) { | 1438 static void test_isRect_open_close(skiatest::Reporter* reporter) { |
1367 SkPath path; | 1439 SkPath path; |
1368 bool isClosed; | 1440 bool isClosed; |
1369 | 1441 |
1370 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); | 1442 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
1371 | 1443 |
1372 if (false) { | 1444 if (false) { |
1373 // I think these should pass, but isRect() doesn't behave | 1445 // I think these should pass, but isRect() doesn't behave |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 char buffer[1024]; | 1883 char buffer[1024]; |
1812 size_t size1 = p.writeToMemory(NULL); | 1884 size_t size1 = p.writeToMemory(NULL); |
1813 size_t size2 = p.writeToMemory(buffer); | 1885 size_t size2 = p.writeToMemory(buffer); |
1814 REPORTER_ASSERT(reporter, size1 == size2); | 1886 REPORTER_ASSERT(reporter, size1 == size2); |
1815 | 1887 |
1816 SkPath p2; | 1888 SkPath p2; |
1817 size_t size3 = p2.readFromMemory(buffer, 1024); | 1889 size_t size3 = p2.readFromMemory(buffer, 1024); |
1818 REPORTER_ASSERT(reporter, size1 == size3); | 1890 REPORTER_ASSERT(reporter, size1 == size3); |
1819 REPORTER_ASSERT(reporter, p == p2); | 1891 REPORTER_ASSERT(reporter, p == p2); |
1820 | 1892 |
| 1893 size3 = p2.readFromMemory(buffer, 0); |
| 1894 REPORTER_ASSERT(reporter, !size3); |
| 1895 |
| 1896 SkPath tooShort; |
| 1897 size3 = tooShort.readFromMemory(buffer, size1 - 1); |
| 1898 REPORTER_ASSERT(reporter, tooShort.isEmpty()); |
| 1899 |
1821 char buffer2[1024]; | 1900 char buffer2[1024]; |
1822 size3 = p2.writeToMemory(buffer2); | 1901 size3 = p2.writeToMemory(buffer2); |
1823 REPORTER_ASSERT(reporter, size1 == size3); | 1902 REPORTER_ASSERT(reporter, size1 == size3); |
1824 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); | 1903 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); |
1825 | 1904 |
1826 // test persistence of the oval flag & convexity | 1905 // test persistence of the oval flag & convexity |
1827 { | 1906 { |
1828 SkPath oval; | 1907 SkPath oval; |
1829 SkRect rect = SkRect::MakeWH(10, 10); | 1908 SkRect rect = SkRect::MakeWH(10, 10); |
1830 oval.addOval(rect); | 1909 oval.addOval(rect); |
1831 | 1910 |
1832 write_and_read_back(reporter, oval); | 1911 write_and_read_back(reporter, oval); |
1833 } | 1912 } |
1834 } | 1913 } |
1835 | 1914 |
1836 static void test_transform(skiatest::Reporter* reporter) { | 1915 static void test_transform(skiatest::Reporter* reporter) { |
1837 SkPath p, p1; | 1916 SkPath p, p1; |
1838 | 1917 |
| 1918 #define CONIC_PERSPECTIVE_BUG_FIXED 0 |
1839 static const SkPoint pts[] = { | 1919 static const SkPoint pts[] = { |
1840 { 0, 0 }, | 1920 { 0, 0 }, // move |
1841 { SkIntToScalar(10), SkIntToScalar(10) }, | 1921 { SkIntToScalar(10), SkIntToScalar(10) }, // line |
1842 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, | 1922 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, //
quad |
1843 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10
) } | 1923 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10
) }, // cubic |
| 1924 #if CONIC_PERSPECTIVE_BUG_FIXED |
| 1925 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic |
| 1926 #endif |
1844 }; | 1927 }; |
| 1928 const int kPtCount = SK_ARRAY_COUNT(pts); |
1845 p.moveTo(pts[0]); | 1929 p.moveTo(pts[0]); |
1846 p.lineTo(pts[1]); | 1930 p.lineTo(pts[1]); |
1847 p.quadTo(pts[2], pts[3]); | 1931 p.quadTo(pts[2], pts[3]); |
1848 p.cubicTo(pts[4], pts[5], pts[6]); | 1932 p.cubicTo(pts[4], pts[5], pts[6]); |
1849 | 1933 #if CONIC_PERSPECTIVE_BUG_FIXED |
| 1934 p.conicTo(pts[4], pts[5], 0.5f); |
| 1935 #endif |
| 1936 p.close(); |
1850 SkMatrix matrix; | 1937 SkMatrix matrix; |
1851 matrix.reset(); | 1938 matrix.reset(); |
1852 p.transform(matrix, &p1); | 1939 p.transform(matrix, &p1); |
1853 REPORTER_ASSERT(reporter, p == p1); | 1940 REPORTER_ASSERT(reporter, p == p1); |
1854 | 1941 |
1855 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); | 1942 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); |
1856 p.transform(matrix, &p1); | 1943 p.transform(matrix, &p1); |
1857 SkPoint pts1[7]; | 1944 SkPoint pts1[kPtCount]; |
1858 int count = p1.getPoints(pts1, 7); | 1945 int count = p1.getPoints(pts1, kPtCount); |
1859 REPORTER_ASSERT(reporter, 7 == count); | 1946 REPORTER_ASSERT(reporter, kPtCount == count); |
1860 for (int i = 0; i < count; ++i) { | 1947 for (int i = 0; i < count; ++i) { |
1861 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); | 1948 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); |
1862 REPORTER_ASSERT(reporter, newPt == pts1[i]); | 1949 REPORTER_ASSERT(reporter, newPt == pts1[i]); |
1863 } | 1950 } |
| 1951 matrix.reset(); |
| 1952 matrix.setPerspX(SkScalarToPersp(4)); |
| 1953 p.transform(matrix, &p1); |
| 1954 REPORTER_ASSERT(reporter, matrix.invert(&matrix)); |
| 1955 p1.transform(matrix, NULL); |
| 1956 SkRect pBounds = p.getBounds(); |
| 1957 SkRect p1Bounds = p1.getBounds(); |
| 1958 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft)
); |
| 1959 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop)); |
| 1960 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRigh
t)); |
| 1961 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBot
tom)); |
| 1962 |
| 1963 matrix.reset(); |
| 1964 p.reset(); |
| 1965 p.addCircle(0, 0, 1, SkPath::kCW_Direction); |
| 1966 p.transform(matrix, &p1); |
| 1967 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction)); |
| 1968 matrix.setScaleX(-1); |
| 1969 p.transform(matrix, &p1); |
| 1970 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction)); |
| 1971 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1); |
| 1972 p.transform(matrix, &p1); |
| 1973 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction)); |
1864 } | 1974 } |
1865 | 1975 |
1866 static void test_zero_length_paths(skiatest::Reporter* reporter) { | 1976 static void test_zero_length_paths(skiatest::Reporter* reporter) { |
1867 SkPath p; | 1977 SkPath p; |
1868 uint8_t verbs[32]; | 1978 uint8_t verbs[32]; |
1869 | 1979 |
1870 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { | 1980 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { |
1871 const char* testPath; | 1981 const char* testPath; |
1872 const size_t numResultPts; | 1982 const size_t numResultPts; |
1873 const SkRect resultBound; | 1983 const SkRect resultBound; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 int j = 0, l = 0; | 2167 int j = 0, l = 0; |
2058 do { | 2168 do { |
2059 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegene
rates) == gIterTests[i].resultVerbs[j]); | 2169 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegene
rates) == gIterTests[i].resultVerbs[j]); |
2060 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k)
{ | 2170 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k)
{ |
2061 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]
); | 2171 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]
); |
2062 } | 2172 } |
2063 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb); | 2173 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb); |
2064 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs); | 2174 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs); |
2065 } | 2175 } |
2066 | 2176 |
| 2177 p.reset(); |
| 2178 iter.setPath(p, false); |
| 2179 REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2180 p.lineTo(1, 1); |
| 2181 p.close(); |
| 2182 iter.setPath(p, false); |
| 2183 REPORTER_ASSERT(reporter, iter.isClosedContour()); |
| 2184 p.reset(); |
| 2185 iter.setPath(p, true); |
| 2186 REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2187 p.lineTo(1, 1); |
| 2188 iter.setPath(p, true); |
| 2189 REPORTER_ASSERT(reporter, iter.isClosedContour()); |
| 2190 p.moveTo(0, 0); |
| 2191 p.lineTo(2, 2); |
| 2192 iter.setPath(p, false); |
| 2193 REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2194 |
| 2195 // this checks to see if the NaN logic is executed in SkPath::autoClose(), b
ut does not |
| 2196 // check to see if the result is correct. |
| 2197 for (int setNaN = 0; setNaN < 4; ++setNaN) { |
| 2198 p.reset(); |
| 2199 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0)
; |
| 2200 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1)
; |
| 2201 iter.setPath(p, true); |
| 2202 iter.next(pts, false); |
| 2203 iter.next(pts, false); |
| 2204 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false)); |
| 2205 } |
| 2206 |
| 2207 p.reset(); |
| 2208 p.quadTo(0, 0, 0, 0); |
| 2209 iter.setPath(p, false); |
| 2210 iter.next(pts, false); |
| 2211 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false)); |
| 2212 iter.setPath(p, false); |
| 2213 iter.next(pts, false); |
| 2214 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 2215 |
| 2216 p.reset(); |
| 2217 p.conicTo(0, 0, 0, 0, 0.5f); |
| 2218 iter.setPath(p, false); |
| 2219 iter.next(pts, false); |
| 2220 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false)); |
| 2221 iter.setPath(p, false); |
| 2222 iter.next(pts, false); |
| 2223 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 2224 |
| 2225 p.reset(); |
| 2226 p.cubicTo(0, 0, 0, 0, 0, 0); |
| 2227 iter.setPath(p, false); |
| 2228 iter.next(pts, false); |
| 2229 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false)); |
| 2230 iter.setPath(p, false); |
| 2231 iter.next(pts, false); |
| 2232 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 2233 |
| 2234 p.moveTo(1, 1); // add a trailing moveto |
| 2235 iter.setPath(p, false); |
| 2236 iter.next(pts, false); |
| 2237 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false)); |
| 2238 iter.setPath(p, false); |
| 2239 iter.next(pts, false); |
| 2240 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 2241 |
2067 // The GM degeneratesegments.cpp test is more extensive | 2242 // The GM degeneratesegments.cpp test is more extensive |
2068 } | 2243 } |
2069 | 2244 |
2070 static void test_raw_iter(skiatest::Reporter* reporter) { | 2245 static void test_raw_iter(skiatest::Reporter* reporter) { |
2071 SkPath p; | 2246 SkPath p; |
2072 SkPoint pts[4]; | 2247 SkPoint pts[4]; |
2073 | 2248 |
2074 // Test an iterator with no path | 2249 // Test an iterator with no path |
2075 SkPath::RawIter noPathIter; | 2250 SkPath::RawIter noPathIter; |
2076 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); | 2251 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2316 SkPath::Direction dir) { | 2491 SkPath::Direction dir) { |
2317 SkPath tmp; | 2492 SkPath tmp; |
2318 | 2493 |
2319 SkMatrix m; | 2494 SkMatrix m; |
2320 m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); | 2495 m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); |
2321 path.transform(m, &tmp); | 2496 path.transform(m, &tmp); |
2322 // this matrix reverses the direction. | 2497 // this matrix reverses the direction. |
2323 if (SkPath::kCCW_Direction == dir) { | 2498 if (SkPath::kCCW_Direction == dir) { |
2324 dir = SkPath::kCW_Direction; | 2499 dir = SkPath::kCW_Direction; |
2325 } else { | 2500 } else { |
2326 SkASSERT(SkPath::kCW_Direction == dir); | 2501 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir); |
2327 dir = SkPath::kCCW_Direction; | 2502 dir = SkPath::kCCW_Direction; |
2328 } | 2503 } |
2329 check_for_circle(reporter, tmp, false, dir); | 2504 check_for_circle(reporter, tmp, false, dir); |
2330 } | 2505 } |
2331 | 2506 |
2332 static void test_circle_translate(skiatest::Reporter* reporter, | 2507 static void test_circle_translate(skiatest::Reporter* reporter, |
2333 const SkPath& path, | 2508 const SkPath& path, |
2334 SkPath::Direction dir) { | 2509 SkPath::Direction dir) { |
2335 SkPath tmp; | 2510 SkPath tmp; |
2336 | 2511 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 SkPath::Direction dir) { | 2549 SkPath::Direction dir) { |
2375 SkPath tmp; | 2550 SkPath tmp; |
2376 SkMatrix m; | 2551 SkMatrix m; |
2377 m.reset(); | 2552 m.reset(); |
2378 m.setScaleX(-SK_Scalar1); | 2553 m.setScaleX(-SK_Scalar1); |
2379 path.transform(m, &tmp); | 2554 path.transform(m, &tmp); |
2380 | 2555 |
2381 if (SkPath::kCW_Direction == dir) { | 2556 if (SkPath::kCW_Direction == dir) { |
2382 dir = SkPath::kCCW_Direction; | 2557 dir = SkPath::kCCW_Direction; |
2383 } else { | 2558 } else { |
2384 SkASSERT(SkPath::kCCW_Direction == dir); | 2559 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir); |
2385 dir = SkPath::kCW_Direction; | 2560 dir = SkPath::kCW_Direction; |
2386 } | 2561 } |
2387 | 2562 |
2388 check_for_circle(reporter, tmp, true, dir); | 2563 check_for_circle(reporter, tmp, true, dir); |
2389 } | 2564 } |
2390 | 2565 |
2391 static void test_circle_mirror_y(skiatest::Reporter* reporter, | 2566 static void test_circle_mirror_y(skiatest::Reporter* reporter, |
2392 const SkPath& path, | 2567 const SkPath& path, |
2393 SkPath::Direction dir) { | 2568 SkPath::Direction dir) { |
2394 SkPath tmp; | 2569 SkPath tmp; |
2395 SkMatrix m; | 2570 SkMatrix m; |
2396 m.reset(); | 2571 m.reset(); |
2397 m.setScaleY(-SK_Scalar1); | 2572 m.setScaleY(-SK_Scalar1); |
2398 path.transform(m, &tmp); | 2573 path.transform(m, &tmp); |
2399 | 2574 |
2400 if (SkPath::kCW_Direction == dir) { | 2575 if (SkPath::kCW_Direction == dir) { |
2401 dir = SkPath::kCCW_Direction; | 2576 dir = SkPath::kCCW_Direction; |
2402 } else { | 2577 } else { |
2403 SkASSERT(SkPath::kCCW_Direction == dir); | 2578 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir); |
2404 dir = SkPath::kCW_Direction; | 2579 dir = SkPath::kCW_Direction; |
2405 } | 2580 } |
2406 | 2581 |
2407 check_for_circle(reporter, tmp, true, dir); | 2582 check_for_circle(reporter, tmp, true, dir); |
2408 } | 2583 } |
2409 | 2584 |
2410 static void test_circle_mirror_xy(skiatest::Reporter* reporter, | 2585 static void test_circle_mirror_xy(skiatest::Reporter* reporter, |
2411 const SkPath& path, | 2586 const SkPath& path, |
2412 SkPath::Direction dir) { | 2587 SkPath::Direction dir) { |
2413 SkPath tmp; | 2588 SkPath tmp; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 path.lineTo(0, 0); | 2670 path.lineTo(0, 0); |
2496 check_for_circle(reporter, path, false, SkPath::kCW_Direction); | 2671 check_for_circle(reporter, path, false, SkPath::kCW_Direction); |
2497 | 2672 |
2498 // not back to the original point | 2673 // not back to the original point |
2499 path.reset(); | 2674 path.reset(); |
2500 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); | 2675 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
2501 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5)); | 2676 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5)); |
2502 check_for_circle(reporter, path, false, SkPath::kCW_Direction); | 2677 check_for_circle(reporter, path, false, SkPath::kCW_Direction); |
2503 | 2678 |
2504 test_circle_with_add_paths(reporter); | 2679 test_circle_with_add_paths(reporter); |
| 2680 |
| 2681 // test negative radius |
| 2682 path.reset(); |
| 2683 path.addCircle(0, 0, -1, SkPath::kCW_Direction); |
| 2684 REPORTER_ASSERT(reporter, path.isEmpty()); |
2505 } | 2685 } |
2506 | 2686 |
2507 static void test_oval(skiatest::Reporter* reporter) { | 2687 static void test_oval(skiatest::Reporter* reporter) { |
2508 SkRect rect; | 2688 SkRect rect; |
2509 SkMatrix m; | 2689 SkMatrix m; |
2510 SkPath path; | 2690 SkPath path; |
2511 | 2691 |
2512 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); | 2692 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); |
2513 path.addOval(rect); | 2693 path.addOval(rect); |
2514 | 2694 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2566 REPORTER_ASSERT(reporter, 0 == p.countPoints()); | 2746 REPORTER_ASSERT(reporter, 0 == p.countPoints()); |
2567 REPORTER_ASSERT(reporter, 0 == p.countVerbs()); | 2747 REPORTER_ASSERT(reporter, 0 == p.countVerbs()); |
2568 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); | 2748 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); |
2569 REPORTER_ASSERT(reporter, p.isConvex()); | 2749 REPORTER_ASSERT(reporter, p.isConvex()); |
2570 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); | 2750 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); |
2571 REPORTER_ASSERT(reporter, !p.isInverseFillType()); | 2751 REPORTER_ASSERT(reporter, !p.isInverseFillType()); |
2572 REPORTER_ASSERT(reporter, p == empty); | 2752 REPORTER_ASSERT(reporter, p == empty); |
2573 REPORTER_ASSERT(reporter, !(p != empty)); | 2753 REPORTER_ASSERT(reporter, !(p != empty)); |
2574 } | 2754 } |
2575 | 2755 |
2576 static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path) { | 2756 static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path, |
| 2757 SkPath::Direction dir) { |
2577 REPORTER_ASSERT(reporter, path->isConvex()); | 2758 REPORTER_ASSERT(reporter, path->isConvex()); |
| 2759 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir)); |
2578 path->setConvexity(SkPath::kUnknown_Convexity); | 2760 path->setConvexity(SkPath::kUnknown_Convexity); |
2579 REPORTER_ASSERT(reporter, path->isConvex()); | 2761 REPORTER_ASSERT(reporter, path->isConvex()); |
2580 path->reset(); | 2762 path->reset(); |
2581 } | 2763 } |
2582 | 2764 |
2583 static void test_rrect(skiatest::Reporter* reporter) { | 2765 static void test_rrect(skiatest::Reporter* reporter) { |
2584 SkPath p; | 2766 SkPath p; |
2585 SkRRect rr; | 2767 SkRRect rr; |
2586 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; | 2768 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; |
2587 SkRect r = {10, 20, 30, 40}; | 2769 SkRect r = {10, 20, 30, 40}; |
2588 rr.setRectRadii(r, radii); | 2770 rr.setRectRadii(r, radii); |
2589 p.addRRect(rr); | 2771 p.addRRect(rr); |
2590 test_rrect_is_convex(reporter, &p); | 2772 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
2591 p.addRRect(rr, SkPath::kCCW_Direction); | 2773 p.addRRect(rr, SkPath::kCCW_Direction); |
2592 test_rrect_is_convex(reporter, &p); | 2774 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
2593 p.addRoundRect(r, &radii[0].fX); | 2775 p.addRoundRect(r, &radii[0].fX); |
2594 test_rrect_is_convex(reporter, &p); | 2776 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
2595 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction); | 2777 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction); |
2596 test_rrect_is_convex(reporter, &p); | 2778 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
2597 p.addRoundRect(r, radii[1].fX, radii[1].fY); | 2779 p.addRoundRect(r, radii[1].fX, radii[1].fY); |
2598 test_rrect_is_convex(reporter, &p); | 2780 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
2599 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction); | 2781 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction); |
2600 test_rrect_is_convex(reporter, &p); | 2782 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
2601 } | 2783 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 2784 SkVector save = radii[i]; |
| 2785 radii[i].set(0, 0); |
| 2786 rr.setRectRadii(r, radii); |
| 2787 p.addRRect(rr); |
| 2788 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2789 radii[i] = save; |
| 2790 } |
| 2791 p.addRoundRect(r, 0, 0); |
| 2792 SkRect returnedRect; |
| 2793 REPORTER_ASSERT(reporter, p.isRect(&returnedRect)); |
| 2794 REPORTER_ASSERT(reporter, returnedRect == r); |
| 2795 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2796 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}}; |
| 2797 rr.setRectRadii(r, zeroRadii); |
| 2798 p.addRRect(rr); |
| 2799 bool closed; |
| 2800 SkPath::Direction dir; |
| 2801 REPORTER_ASSERT(reporter, p.isRect(&closed, &dir)); |
| 2802 REPORTER_ASSERT(reporter, closed); |
| 2803 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir); |
| 2804 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2805 p.addRRect(rr, SkPath::kCW_Direction); |
| 2806 p.addRRect(rr, SkPath::kCW_Direction); |
| 2807 REPORTER_ASSERT(reporter, !p.isConvex()); |
| 2808 p.reset(); |
| 2809 p.addRRect(rr, SkPath::kCCW_Direction); |
| 2810 p.addRRect(rr, SkPath::kCCW_Direction); |
| 2811 REPORTER_ASSERT(reporter, !p.isConvex()); |
| 2812 p.reset(); |
| 2813 SkRect emptyR = {10, 20, 10, 30}; |
| 2814 rr.setRectRadii(emptyR, radii); |
| 2815 p.addRRect(rr); |
| 2816 REPORTER_ASSERT(reporter, p.isEmpty()); |
| 2817 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax}; |
| 2818 rr.setRectRadii(largeR, radii); |
| 2819 p.addRRect(rr); |
| 2820 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2821 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity}; |
| 2822 rr.setRectRadii(infR, radii); |
| 2823 p.addRRect(rr); |
| 2824 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2825 SkRect tinyR = {0, 0, 1e-9f, 1e-9f}; |
| 2826 p.addRoundRect(tinyR, 5e-11f, 5e-11f); |
| 2827 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 2828 } |
| 2829 |
| 2830 static void test_arc(skiatest::Reporter* reporter) { |
| 2831 SkPath p; |
| 2832 SkRect emptyOval = {10, 20, 30, 20}; |
| 2833 REPORTER_ASSERT(reporter, emptyOval.isEmpty()); |
| 2834 p.addArc(emptyOval, 1, 2); |
| 2835 REPORTER_ASSERT(reporter, p.isEmpty()); |
| 2836 p.reset(); |
| 2837 SkRect oval = {10, 20, 30, 40}; |
| 2838 p.addArc(oval, 1, 0); |
| 2839 REPORTER_ASSERT(reporter, p.isEmpty()); |
| 2840 p.reset(); |
| 2841 SkPath cwOval; |
| 2842 cwOval.addOval(oval); |
| 2843 p.addArc(oval, 1, 360); |
| 2844 REPORTER_ASSERT(reporter, p == cwOval); |
| 2845 p.reset(); |
| 2846 SkPath ccwOval; |
| 2847 ccwOval.addOval(oval, SkPath::kCCW_Direction); |
| 2848 p.addArc(oval, 1, -360); |
| 2849 REPORTER_ASSERT(reporter, p == ccwOval); |
| 2850 p.reset(); |
| 2851 p.addArc(oval, 1, 180); |
| 2852 REPORTER_ASSERT(reporter, p.isConvex()); |
| 2853 REPORTER_ASSERT(reporter, p.cheapIsDirection(SkPath::kCW_Direction)); |
| 2854 p.setConvexity(SkPath::kUnknown_Convexity); |
| 2855 REPORTER_ASSERT(reporter, p.isConvex()); |
| 2856 } |
| 2857 |
| 2858 static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 2859 SkScalar x0, SkScalar y0) { |
| 2860 SkPoint pts[4]; |
| 2861 SkPath::Verb v = iter->next(pts); |
| 2862 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb); |
| 2863 REPORTER_ASSERT(reporter, pts[0].fX == x0); |
| 2864 REPORTER_ASSERT(reporter, pts[0].fY == y0); |
| 2865 } |
| 2866 |
| 2867 static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 2868 SkScalar x1, SkScalar y1) { |
| 2869 SkPoint pts[4]; |
| 2870 SkPath::Verb v = iter->next(pts); |
| 2871 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb); |
| 2872 REPORTER_ASSERT(reporter, pts[1].fX == x1); |
| 2873 REPORTER_ASSERT(reporter, pts[1].fY == y1); |
| 2874 } |
| 2875 |
| 2876 static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 2877 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) { |
| 2878 SkPoint pts[4]; |
| 2879 SkPath::Verb v = iter->next(pts); |
| 2880 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb); |
| 2881 REPORTER_ASSERT(reporter, pts[1].fX == x1); |
| 2882 REPORTER_ASSERT(reporter, pts[1].fY == y1); |
| 2883 REPORTER_ASSERT(reporter, pts[2].fX == x2); |
| 2884 REPORTER_ASSERT(reporter, pts[2].fY == y2); |
| 2885 } |
| 2886 |
| 2887 static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter*
iter) { |
| 2888 SkPoint pts[4]; |
| 2889 SkPath::Verb v = iter->next(pts); |
| 2890 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb); |
| 2891 } |
| 2892 |
| 2893 static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath
::RawIter* iter) { |
| 2894 check_done(reporter, p, iter); |
| 2895 p->reset(); |
| 2896 } |
| 2897 |
| 2898 static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p
, |
| 2899 SkScalar x0, SkScalar y0) { |
| 2900 SkPath::RawIter iter(*p); |
| 2901 check_move(reporter, &iter, x0, y0); |
| 2902 check_done_and_reset(reporter, p, &iter); |
| 2903 } |
| 2904 |
| 2905 static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p
, |
| 2906 SkScalar x1, SkScalar y1) { |
| 2907 SkPath::RawIter iter(*p); |
| 2908 check_move(reporter, &iter, 0, 0); |
| 2909 check_line(reporter, &iter, x1, y1); |
| 2910 check_done_and_reset(reporter, p, &iter); |
| 2911 } |
| 2912 |
| 2913 static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p, |
| 2914 SkScalar x1, SkScalar y1) { |
| 2915 SkPath::RawIter iter(*p); |
| 2916 check_move(reporter, &iter, 0, 0); |
| 2917 check_line(reporter, &iter, x1, y1); |
| 2918 check_done(reporter, p, &iter); |
| 2919 } |
| 2920 |
| 2921 static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPa
th* p, |
| 2922 SkScalar x1, SkScalar y1, SkScalar x2, SkSca
lar y2) { |
| 2923 SkPath::RawIter iter(*p); |
| 2924 check_move(reporter, &iter, 0, 0); |
| 2925 check_line(reporter, &iter, x1, y1); |
| 2926 check_line(reporter, &iter, x2, y2); |
| 2927 check_done_and_reset(reporter, p, &iter); |
| 2928 } |
| 2929 |
| 2930 static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p
, |
| 2931 SkScalar x1, SkScalar y1, SkScalar x2, SkSca
lar y2) { |
| 2932 SkPath::RawIter iter(*p); |
| 2933 check_move(reporter, &iter, 0, 0); |
| 2934 check_quad(reporter, &iter, x1, y1, x2, y2); |
| 2935 check_done_and_reset(reporter, p, &iter); |
| 2936 } |
| 2937 |
| 2938 static void test_arcTo(skiatest::Reporter* reporter) { |
| 2939 SkPath p; |
| 2940 p.arcTo(0, 0, 1, 2, 1); |
| 2941 check_path_is_line_and_reset(reporter, &p, 0, 0); |
| 2942 p.arcTo(1, 2, 1, 2, 1); |
| 2943 check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 2944 p.arcTo(1, 2, 3, 4, 0); |
| 2945 check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 2946 p.arcTo(1, 2, 0, 0, 1); |
| 2947 check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 2948 p.arcTo(1, 0, 1, 1, 1); |
| 2949 SkPoint pt; |
| 2950 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1); |
| 2951 p.reset(); |
| 2952 p.arcTo(1, 0, 1, -1, 1); |
| 2953 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1); |
| 2954 p.reset(); |
| 2955 SkRect oval = {1, 2, 3, 4}; |
| 2956 p.arcTo(oval, 0, 0, true); |
| 2957 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 2958 p.arcTo(oval, 0, 0, false); |
| 2959 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 2960 p.arcTo(oval, 360, 0, true); |
| 2961 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 2962 p.arcTo(oval, 360, 0, false); |
| 2963 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 2964 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) { |
| 2965 p.arcTo(oval, 0, SkFloatToScalar(sweep), false); |
| 2966 REPORTER_ASSERT(reporter, p.getBounds() == oval); |
| 2967 sweep += delta; |
| 2968 delta /= 2; |
| 2969 } |
| 2970 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) { |
| 2971 p.arcTo(oval, 0, SkFloatToScalar(sweep), false); |
| 2972 REPORTER_ASSERT(reporter, p.getBounds() == oval); |
| 2973 sweep -= delta; |
| 2974 delta /= 2; |
| 2975 } |
| 2976 SkRect noOvalWidth = {1, 2, 0, 3}; |
| 2977 p.reset(); |
| 2978 p.arcTo(noOvalWidth, 0, 360, false); |
| 2979 REPORTER_ASSERT(reporter, p.isEmpty()); |
| 2980 |
| 2981 SkRect noOvalHeight = {1, 2, 3, 1}; |
| 2982 p.reset(); |
| 2983 p.arcTo(noOvalHeight, 0, 360, false); |
| 2984 REPORTER_ASSERT(reporter, p.isEmpty()); |
| 2985 } |
| 2986 |
| 2987 static void test_addPath(skiatest::Reporter* reporter) { |
| 2988 SkPath p, q; |
| 2989 p.lineTo(1, 2); |
| 2990 q.moveTo(4, 4); |
| 2991 q.lineTo(7, 8); |
| 2992 q.conicTo(8, 7, 6, 5, 0.5f); |
| 2993 q.quadTo(6, 7, 8, 6); |
| 2994 q.cubicTo(5, 6, 7, 8, 7, 5); |
| 2995 q.close(); |
| 2996 p.addPath(q, -4, -4); |
| 2997 SkRect expected = {0, 0, 4, 4}; |
| 2998 REPORTER_ASSERT(reporter, p.getBounds() == expected); |
| 2999 p.reset(); |
| 3000 p.reverseAddPath(q); |
| 3001 SkRect reverseExpected = {4, 4, 8, 8}; |
| 3002 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
| 3003 } |
| 3004 |
| 3005 static void test_conicTo_special_case(skiatest::Reporter* reporter) { |
| 3006 SkPath p; |
| 3007 p.conicTo(1, 2, 3, 4, -1); |
| 3008 check_path_is_line_and_reset(reporter, &p, 3, 4); |
| 3009 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity); |
| 3010 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4); |
| 3011 p.conicTo(1, 2, 3, 4, 1); |
| 3012 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4); |
| 3013 } |
| 3014 |
| 3015 static void test_get_point(skiatest::Reporter* reporter) { |
| 3016 SkPath p; |
| 3017 SkPoint pt = p.getPoint(0); |
| 3018 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0)); |
| 3019 REPORTER_ASSERT(reporter, !p.getLastPt(NULL)); |
| 3020 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0)); |
| 3021 p.setLastPt(10, 10); |
| 3022 pt = p.getPoint(0); |
| 3023 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10)); |
| 3024 REPORTER_ASSERT(reporter, p.getLastPt(NULL)); |
| 3025 p.rMoveTo(10, 10); |
| 3026 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20)); |
| 3027 } |
| 3028 |
| 3029 static void test_contains(skiatest::Reporter* reporter) { |
| 3030 SkPath p; |
| 3031 p.setFillType(SkPath::kInverseWinding_FillType); |
| 3032 REPORTER_ASSERT(reporter, p.contains(0, 0)); |
| 3033 p.setFillType(SkPath::kWinding_FillType); |
| 3034 REPORTER_ASSERT(reporter, !p.contains(0, 0)); |
| 3035 p.moveTo(4, 4); |
| 3036 p.lineTo(6, 8); |
| 3037 p.lineTo(8, 4); |
| 3038 // test quick reject |
| 3039 REPORTER_ASSERT(reporter, !p.contains(4, 0)); |
| 3040 REPORTER_ASSERT(reporter, !p.contains(0, 4)); |
| 3041 REPORTER_ASSERT(reporter, !p.contains(4, 10)); |
| 3042 REPORTER_ASSERT(reporter, !p.contains(10, 4)); |
| 3043 // test various crossings in x |
| 3044 REPORTER_ASSERT(reporter, !p.contains(5, 7)); |
| 3045 REPORTER_ASSERT(reporter, p.contains(6, 7)); |
| 3046 REPORTER_ASSERT(reporter, !p.contains(7, 7)); |
| 3047 p.reset(); |
| 3048 p.moveTo(4, 4); |
| 3049 p.lineTo(8, 6); |
| 3050 p.lineTo(4, 8); |
| 3051 // test various crossings in y |
| 3052 REPORTER_ASSERT(reporter, !p.contains(7, 5)); |
| 3053 REPORTER_ASSERT(reporter, p.contains(7, 6)); |
| 3054 REPORTER_ASSERT(reporter, !p.contains(7, 7)); |
| 3055 // test quads |
| 3056 p.reset(); |
| 3057 p.moveTo(4, 4); |
| 3058 p.quadTo(6, 6, 8, 8); |
| 3059 p.quadTo(6, 8, 4, 8); |
| 3060 p.quadTo(4, 6, 4, 4); |
| 3061 REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 3062 REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
| 3063 |
| 3064 p.reset(); |
| 3065 p.moveTo(6, 6); |
| 3066 p.quadTo(8, 8, 6, 8); |
| 3067 p.quadTo(4, 8, 4, 6); |
| 3068 p.quadTo(4, 4, 6, 6); |
| 3069 REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 3070 REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
| 3071 |
| 3072 #define CONIC_CONTAINS_BUG_FIXED 0 |
| 3073 #if CONIC_CONTAINS_BUG_FIXED |
| 3074 p.reset(); |
| 3075 p.moveTo(4, 4); |
| 3076 p.conicTo(6, 6, 8, 8, 0.5f); |
| 3077 p.conicTo(6, 8, 4, 8, 0.5f); |
| 3078 p.conicTo(4, 6, 4, 4, 0.5f); |
| 3079 REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 3080 REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
| 3081 #endif |
| 3082 |
| 3083 // test cubics |
| 3084 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5,
4}, {6, 5}, {7, 6}}; |
| 3085 for (int i = 0; i < 3; ++i) { |
| 3086 p.reset(); |
| 3087 p.setFillType(SkPath::kEvenOdd_FillType); |
| 3088 p.moveTo(pts[i].fX, pts[i].fY); |
| 3089 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt
s[i + 3].fX, pts[i + 3].fY); |
| 3090 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt
s[i + 6].fX, pts[i + 6].fY); |
| 3091 p.close(); |
| 3092 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); |
| 3093 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); |
| 3094 } |
| 3095 } |
| 3096 |
| 3097 static void test_operatorEqual(skiatest::Reporter* reporter) { |
| 3098 SkPath a; |
| 3099 SkPath b; |
| 3100 REPORTER_ASSERT(reporter, a == a); |
| 3101 REPORTER_ASSERT(reporter, a == b); |
| 3102 a.setFillType(SkPath::kInverseWinding_FillType); |
| 3103 REPORTER_ASSERT(reporter, a != b); |
| 3104 a.reset(); |
| 3105 REPORTER_ASSERT(reporter, a == b); |
| 3106 a.lineTo(1, 1); |
| 3107 REPORTER_ASSERT(reporter, a != b); |
| 3108 a.reset(); |
| 3109 REPORTER_ASSERT(reporter, a == b); |
| 3110 a.lineTo(1, 1); |
| 3111 b.lineTo(1, 2); |
| 3112 REPORTER_ASSERT(reporter, a != b); |
| 3113 a.reset(); |
| 3114 a.lineTo(1, 2); |
| 3115 REPORTER_ASSERT(reporter, a == b); |
| 3116 } |
| 3117 |
| 3118 class PathTest_Private { |
| 3119 public: |
| 3120 static void TestPathTo(skiatest::Reporter* reporter) { |
| 3121 SkPath p, q; |
| 3122 p.lineTo(4, 4); |
| 3123 p.reversePathTo(q); |
| 3124 check_path_is_line(reporter, &p, 4, 4); |
| 3125 q.moveTo(-4, -4); |
| 3126 p.reversePathTo(q); |
| 3127 check_path_is_line(reporter, &p, 4, 4); |
| 3128 q.lineTo(7, 8); |
| 3129 q.conicTo(8, 7, 6, 5, 0.5f); |
| 3130 q.quadTo(6, 7, 8, 6); |
| 3131 q.cubicTo(5, 6, 7, 8, 7, 5); |
| 3132 q.close(); |
| 3133 p.reversePathTo(q); |
| 3134 SkRect reverseExpected = {-4, -4, 8, 8}; |
| 3135 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
| 3136 } |
| 3137 }; |
2602 | 3138 |
2603 static void TestPath(skiatest::Reporter* reporter) { | 3139 static void TestPath(skiatest::Reporter* reporter) { |
2604 SkTSize<SkScalar>::Make(3,4); | 3140 SkTSize<SkScalar>::Make(3,4); |
2605 | 3141 |
2606 SkPath p, empty; | 3142 SkPath p, empty; |
2607 SkRect bounds, bounds2; | 3143 SkRect bounds, bounds2; |
2608 test_empty(reporter, p); | 3144 test_empty(reporter, p); |
2609 | 3145 |
2610 REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); | 3146 REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
2611 | 3147 |
| 3148 // this triggers a code path in SkPath::operator= which is otherwise unexerc
ised |
| 3149 SkPath& self = p; |
| 3150 p = self; |
| 3151 |
| 3152 // this triggers a code path in SkPath::swap which is otherwise unexercised |
| 3153 p.swap(self); |
| 3154 |
2612 bounds.set(0, 0, SK_Scalar1, SK_Scalar1); | 3155 bounds.set(0, 0, SK_Scalar1, SK_Scalar1); |
2613 | 3156 |
2614 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); | 3157 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); |
2615 check_convex_bounds(reporter, p, bounds); | 3158 check_convex_bounds(reporter, p, bounds); |
2616 // we have quads or cubics | 3159 // we have quads or cubics |
2617 REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask); | 3160 REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask); |
2618 REPORTER_ASSERT(reporter, !p.isEmpty()); | 3161 REPORTER_ASSERT(reporter, !p.isEmpty()); |
2619 | 3162 |
2620 p.reset(); | 3163 p.reset(); |
2621 test_empty(reporter, p); | 3164 test_empty(reporter, p); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2661 REPORTER_ASSERT(reporter, p.isRect(NULL)); | 3204 REPORTER_ASSERT(reporter, p.isRect(NULL)); |
2662 bounds2.setEmpty(); | 3205 bounds2.setEmpty(); |
2663 REPORTER_ASSERT(reporter, p.isRect(&bounds2)); | 3206 REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
2664 REPORTER_ASSERT(reporter, bounds == bounds2); | 3207 REPORTER_ASSERT(reporter, bounds == bounds2); |
2665 | 3208 |
2666 // now force p to not be a rect | 3209 // now force p to not be a rect |
2667 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); | 3210 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
2668 p.addRect(bounds); | 3211 p.addRect(bounds); |
2669 REPORTER_ASSERT(reporter, !p.isRect(NULL)); | 3212 REPORTER_ASSERT(reporter, !p.isRect(NULL)); |
2670 | 3213 |
| 3214 test_operatorEqual(reporter); |
2671 test_isLine(reporter); | 3215 test_isLine(reporter); |
2672 test_isRect(reporter); | 3216 test_isRect(reporter); |
2673 test_isNestedRects(reporter); | 3217 test_isNestedRects(reporter); |
2674 test_zero_length_paths(reporter); | 3218 test_zero_length_paths(reporter); |
2675 test_direction(reporter); | 3219 test_direction(reporter); |
2676 test_convexity(reporter); | 3220 test_convexity(reporter); |
2677 test_convexity2(reporter); | 3221 test_convexity2(reporter); |
2678 test_conservativelyContains(reporter); | 3222 test_conservativelyContains(reporter); |
2679 test_close(reporter); | 3223 test_close(reporter); |
2680 test_segment_masks(reporter); | 3224 test_segment_masks(reporter); |
2681 test_flattening(reporter); | 3225 test_flattening(reporter); |
2682 test_transform(reporter); | 3226 test_transform(reporter); |
2683 test_bounds(reporter); | 3227 test_bounds(reporter); |
2684 test_iter(reporter); | 3228 test_iter(reporter); |
2685 test_raw_iter(reporter); | 3229 test_raw_iter(reporter); |
2686 test_circle(reporter); | 3230 test_circle(reporter); |
2687 test_oval(reporter); | 3231 test_oval(reporter); |
2688 test_strokerec(reporter); | 3232 test_strokerec(reporter); |
2689 test_addPoly(reporter); | 3233 test_addPoly(reporter); |
2690 test_isfinite(reporter); | 3234 test_isfinite(reporter); |
2691 test_isfinite_after_transform(reporter); | 3235 test_isfinite_after_transform(reporter); |
2692 test_arb_round_rect_is_convex(reporter); | 3236 test_arb_round_rect_is_convex(reporter); |
2693 test_arb_zero_rad_round_rect_is_rect(reporter); | 3237 test_arb_zero_rad_round_rect_is_rect(reporter); |
| 3238 test_addrect(reporter); |
2694 test_addrect_isfinite(reporter); | 3239 test_addrect_isfinite(reporter); |
2695 test_tricky_cubic(); | 3240 test_tricky_cubic(); |
2696 test_clipped_cubic(); | 3241 test_clipped_cubic(); |
2697 test_crbug_170666(); | 3242 test_crbug_170666(); |
2698 test_bad_cubic_crbug229478(); | 3243 test_bad_cubic_crbug229478(); |
2699 test_bad_cubic_crbug234190(); | 3244 test_bad_cubic_crbug234190(); |
2700 test_android_specific_behavior(reporter); | 3245 test_android_specific_behavior(reporter); |
2701 test_gen_id(reporter); | 3246 test_gen_id(reporter); |
2702 test_path_close_issue1474(reporter); | 3247 test_path_close_issue1474(reporter); |
2703 test_path_to_region(reporter); | 3248 test_path_to_region(reporter); |
2704 test_rrect(reporter); | 3249 test_rrect(reporter); |
| 3250 test_arc(reporter); |
| 3251 test_arcTo(reporter); |
| 3252 test_addPath(reporter); |
| 3253 test_conicTo_special_case(reporter); |
| 3254 test_get_point(reporter); |
| 3255 test_contains(reporter); |
| 3256 PathTest_Private::TestPathTo(reporter); |
2705 } | 3257 } |
2706 | 3258 |
2707 #include "TestClassDef.h" | 3259 #include "TestClassDef.h" |
2708 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) | 3260 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |
OLD | NEW |