1 #include "Test.h" 2 #include "SkPath.h" 3 #include "SkLineClipper.h" 4 #include "SkEdgeClipper.h" 5 6 static void test_intersectline(skiatest::Reporter* reporter) { 7 static const SkScalar L = 0; 8 static const SkScalar T = 0; 9 static const SkScalar R = SkIntToScalar(100); 10 static const SkScalar B = SkIntToScalar(100); 11 static const SkScalar CX = SkScalarHalf(L + R); 12 static const SkScalar CY = SkScalarHalf(T + B); 13 static const SkRect gR = { L, T, R, B }; 14 15 size_t i; 16 SkPoint dst[2]; 17 18 static const SkPoint gEmpty[] = { 19 // sides 20 { L, CY }, { L - 10, CY }, 21 { R, CY }, { R + 10, CY }, 22 { CX, T }, { CX, T - 10 }, 23 { CX, B }, { CX, B + 10 }, 24 // corners 25 { L, T }, { L - 10, T - 10 }, 26 { L, B }, { L - 10, B + 10 }, 27 { R, T }, { R + 10, T - 10 }, 28 { R, B }, { R + 10, B + 10 }, 29 }; 30 for (i = 0; i < SK_ARRAY_COUNT(gEmpty); i += 2) { 31 bool valid = SkLineClipper::IntersectLine(&gEmpty[i], gR, dst); 32 if (valid) { 33 SkDebugf("----- [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY); 34 } 35 REPORTER_ASSERT(reporter, !valid); 36 } 37 38 static const SkPoint gFull[] = { 39 // diagonals, chords 40 { L, T }, { R, B }, 41 { L, B }, { R, T }, 42 { CX, T }, { CX, B }, 43 { L, CY }, { R, CY }, 44 { CX, T }, { R, CY }, 45 { CX, T }, { L, CY }, 46 { L, CY }, { CX, B }, 47 { R, CY }, { CX, B }, 48 // edges 49 { L, T }, { L, B }, 50 { R, T }, { R, B }, 51 { L, T }, { R, T }, 52 { L, B }, { R, B }, 53 }; 54 for (i = 0; i < SK_ARRAY_COUNT(gFull); i += 2) { 55 bool valid = SkLineClipper::IntersectLine(&gFull[i], gR, dst); 56 if (!valid || memcmp(&gFull[i], dst, sizeof(dst))) { 57 SkDebugf("++++ [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY); 58 } 59 REPORTER_ASSERT(reporter, valid && !memcmp(&gFull[i], dst, sizeof(dst))); 60 } 61 62 static const SkPoint gPartial[] = { 63 { L - 10, CY }, { CX, CY }, { L, CY }, { CX, CY }, 64 { CX, T - 10 }, { CX, CY }, { CX, T }, { CX, CY }, 65 { R + 10, CY }, { CX, CY }, { R, CY }, { CX, CY }, 66 { CX, B + 10 }, { CX, CY }, { CX, B }, { CX, CY }, 67 // extended edges 68 { L, T - 10 }, { L, B + 10 }, { L, T }, { L, B }, 69 { R, T - 10 }, { R, B + 10 }, { R, T }, { R, B }, 70 { L - 10, T }, { R + 10, T }, { L, T }, { R, T }, 71 { L - 10, B }, { R + 10, B }, { L, B }, { R, B }, 72 }; 73 for (i = 0; i < SK_ARRAY_COUNT(gPartial); i += 4) { 74 bool valid = SkLineClipper::IntersectLine(&gPartial[i], gR, dst); 75 if (!valid || memcmp(&gPartial[i+2], dst, sizeof(dst))) { 76 SkDebugf("++++ [%d] %g %g -> %g %g\n", i/2, dst[0].fX, dst[0].fY, dst[1].fX, dst[1].fY); 77 } 78 REPORTER_ASSERT(reporter, valid && 79 !memcmp(&gPartial[i+2], dst, sizeof(dst))); 80 } 81 82 } 83 84 void TestClipper(skiatest::Reporter* reporter) { 85 test_intersectline(reporter); 86 } 87 88 #include "TestClassDef.h" 89 DEFINE_TESTCLASS("Clipper", TestClipperClass, TestClipper) 90