| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "PathOpsExtendedTest.h" | 7 #include "PathOpsExtendedTest.h" |
| 8 #include "PathOpsThreadedCommon.h" |
| 8 #include "SkIntersections.h" | 9 #include "SkIntersections.h" |
| 9 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
| 10 #include "SkPathOpsQuad.h" | 11 #include "SkPathOpsQuad.h" |
| 11 #include "SkReduceOrder.h" | 12 #include "SkReduceOrder.h" |
| 12 | 13 |
| 13 static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, cons
t SkDLine& line, | 14 static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, cons
t SkDLine& line, |
| 14 bool& flipped) { | 15 bool& flipped) { |
| 15 int result; | 16 int result; |
| 16 flipped = false; | 17 flipped = false; |
| 17 if (line[0].fX == line[1].fX) { | 18 if (line[0].fX == line[1].fX) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 36 } | 37 } |
| 37 return result; | 38 return result; |
| 38 } | 39 } |
| 39 | 40 |
| 40 static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad, | 41 static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad, |
| 41 const SkDLine& line, const double x, const double
y) { | 42 const SkDLine& line, const double x, const double
y) { |
| 42 char pathStr[1024]; | 43 char pathStr[1024]; |
| 43 sk_bzero(pathStr, sizeof(pathStr)); | 44 sk_bzero(pathStr, sizeof(pathStr)); |
| 44 char* str = pathStr; | 45 char* str = pathStr; |
| 45 str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].
fY); | 46 str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].
fY); |
| 46 str += sprintf(str, " path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1
].fX, quad[1].fY, quad[2].fX, quad[2].fY); | 47 str += sprintf(str, " path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1
].fX, |
| 48 quad[1].fY, quad[2].fX, quad[2].fY); |
| 47 str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].
fY); | 49 str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].
fY); |
| 48 str += sprintf(str, " path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].
fY); | 50 str += sprintf(str, " path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].
fY); |
| 49 | 51 |
| 50 SkIntersections intersections; | 52 SkIntersections intersections; |
| 51 bool flipped = false; | 53 bool flipped = false; |
| 52 int result = doIntersect(intersections, quad, line, flipped); | 54 int result = doIntersect(intersections, quad, line, flipped); |
| 53 bool found = false; | 55 bool found = false; |
| 54 for (int index = 0; index < result; ++index) { | 56 for (int index = 0; index < result; ++index) { |
| 55 double quadT = intersections[0][index]; | 57 double quadT = intersections[0][index]; |
| 56 SkDPoint quadXY = quad.xyAtT(quadT); | 58 SkDPoint quadXY = quad.xyAtT(quadT); |
| 57 double lineT = intersections[1][index]; | 59 double lineT = intersections[1][index]; |
| 58 SkDPoint lineXY = line.xyAtT(lineT); | 60 SkDPoint lineXY = line.xyAtT(lineT); |
| 59 if (quadXY.approximatelyEqual(lineXY)) { | 61 if (quadXY.approximatelyEqual(lineXY)) { |
| 60 found = true; | 62 found = true; |
| 61 } | 63 } |
| 62 } | 64 } |
| 63 REPORTER_ASSERT(reporter, found); | 65 REPORTER_ASSERT(reporter, found); |
| 64 } | 66 } |
| 65 | 67 |
| 66 | 68 |
| 67 // find a point on a quad by choosing a t from 0 to 1 | 69 // find a point on a quad by choosing a t from 0 to 1 |
| 68 // create a vertical span above and below the point | 70 // create a vertical span above and below the point |
| 69 // verify that intersecting the vertical span and the quad returns t | 71 // verify that intersecting the vertical span and the quad returns t |
| 70 // verify that a vertical span starting at quad[0] intersects at t=0 | 72 // verify that a vertical span starting at quad[0] intersects at t=0 |
| 71 // verify that a vertical span starting at quad[2] intersects at t=1 | 73 // verify that a vertical span starting at quad[2] intersects at t=1 |
| 72 static THREAD_TYPE testQuadLineIntersectMain(void* data) | 74 static void testQuadLineIntersectMain(PathOpsThreadState* data) |
| 73 { | 75 { |
| 74 State4& state = *(State4*) data; | 76 PathOpsThreadState& state = *data; |
| 75 REPORTER_ASSERT(state.reporter, data); | 77 REPORTER_ASSERT(state.fReporter, data); |
| 76 do { | 78 int ax = state.fA & 0x03; |
| 77 int ax = state.a & 0x03; | 79 int ay = state.fA >> 2; |
| 78 int ay = state.a >> 2; | 80 int bx = state.fB & 0x03; |
| 79 int bx = state.b & 0x03; | 81 int by = state.fB >> 2; |
| 80 int by = state.b >> 2; | 82 int cx = state.fC & 0x03; |
| 81 int cx = state.c & 0x03; | 83 int cy = state.fC >> 2; |
| 82 int cy = state.c >> 2; | 84 SkDQuad quad = {{{ax, ay}, {bx, by}, {cx, cy}}}; |
| 83 SkDQuad quad = {{{ax, ay}, {bx, by}, {cx, cy}}}; | 85 SkReduceOrder reducer; |
| 84 SkReduceOrder reducer; | 86 int order = reducer.reduce(quad, SkReduceOrder::kFill_Style); |
| 85 int order = reducer.reduce(quad, SkReduceOrder::kFill_Style); | 87 if (order < 3) { |
| 86 if (order < 3) { | 88 return; |
| 87 continue; // skip degenerates | 89 } |
| 88 } | 90 for (int tIndex = 0; tIndex <= 4; ++tIndex) { |
| 89 for (int tIndex = 0; tIndex <= 4; ++tIndex) { | 91 SkDPoint xy = quad.xyAtT(tIndex / 4.0); |
| 90 SkDPoint xy = quad.xyAtT(tIndex / 4.0); | 92 for (int h = -2; h <= 2; ++h) { |
| 91 for (int h = -2; h <= 2; ++h) { | 93 for (int v = -2; v <= 2; ++v) { |
| 92 for (int v = -2; v <= 2; ++v) { | 94 if (h == v && abs(h) != 1) { |
| 93 if (h == v && abs(h) != 1) { | 95 continue; |
| 94 continue; | |
| 95 } | |
| 96 double x = xy.fX; | |
| 97 double y = xy.fY; | |
| 98 SkDLine line = {{{x - h, y - v}, {x, y}}}; | |
| 99 testLineIntersect(state.reporter, quad, line, x, y); | |
| 100 SkDLine line2 = {{{x, y}, {x + h, y + v}}}; | |
| 101 testLineIntersect(state.reporter, quad, line2, x, y); | |
| 102 SkDLine line3 = {{{x - h, y - v}, {x + h, y + v}}}; | |
| 103 testLineIntersect(state.reporter, quad, line3, x, y); | |
| 104 state.testsRun += 3; | |
| 105 } | 96 } |
| 97 double x = xy.fX; |
| 98 double y = xy.fY; |
| 99 SkDLine line = {{{x - h, y - v}, {x, y}}}; |
| 100 testLineIntersect(state.fReporter, quad, line, x, y); |
| 101 state.fReporter->bumpTestCount(); |
| 102 SkDLine line2 = {{{x, y}, {x + h, y + v}}}; |
| 103 testLineIntersect(state.fReporter, quad, line2, x, y); |
| 104 state.fReporter->bumpTestCount(); |
| 105 SkDLine line3 = {{{x - h, y - v}, {x + h, y + v}}}; |
| 106 testLineIntersect(state.fReporter, quad, line3, x, y); |
| 107 state.fReporter->bumpTestCount(); |
| 106 } | 108 } |
| 107 } | 109 } |
| 108 } while (runNextTestSet(state)); | 110 } |
| 109 THREAD_RETURN | |
| 110 } | 111 } |
| 111 | 112 |
| 112 static void TestQuadLineIntersectionThreaded(skiatest::Reporter* reporter) | 113 static void TestQuadLineIntersectionThreaded(skiatest::Reporter* reporter) |
| 113 { | 114 { |
| 114 int testsRun = 0; | 115 int threadCount = initializeTests("testQuadLineIntersect"); |
| 115 if (gShowTestProgress) SkDebugf("%s\n", __FUNCTION__); | 116 PathOpsThreadedTestRunner testRunner(reporter, threadCount); |
| 116 const char testStr[] = "testQuadLineIntersect"; | |
| 117 initializeTests(reporter, testStr, sizeof(testStr)); | |
| 118 for (int a = 0; a < 16; ++a) { | 117 for (int a = 0; a < 16; ++a) { |
| 119 for (int b = 0 ; b < 16; ++b) { | 118 for (int b = 0 ; b < 16; ++b) { |
| 120 for (int c = 0 ; c < 16; ++c) { | 119 for (int c = 0 ; c < 16; ++c) { |
| 121 testsRun += dispatchTest4(testQuadLineIntersectMain, a, b, c, 0)
; | 120 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreaded
Runnable, |
| 121 (&testQuadLineIntersectMain, a, b, c, 0, &testRunner
)); |
| 122 } | 122 } |
| 123 if (!gAllowExtendedTest) goto finish; | 123 if (!reporter->allowExtendedTest()) goto finish; |
| 124 if (gShowTestProgress) SkDebugf("."); | |
| 125 } | 124 } |
| 126 if (gShowTestProgress) SkDebugf("%d", a); | |
| 127 } | 125 } |
| 128 finish: | 126 finish: |
| 129 testsRun += waitForCompletion(); | 127 testRunner.render(); |
| 130 if (gShowTestProgress) SkDebugf("\n%s tests=%d\n", __FUNCTION__, testsRun); | |
| 131 } | 128 } |
| 132 | 129 |
| 133 #include "TestClassDef.h" | 130 #include "TestClassDef.h" |
| 134 DEFINE_TESTCLASS("PathOpsQuadLineIntersectionThreaded", QuadLineIntersectionThre
adedTestClass, \ | 131 DEFINE_TESTCLASS("PathOpsQuadLineIntersectionThreaded", QuadLineIntersectionThre
adedTestClass, \ |
| 135 TestQuadLineIntersectionThreaded) | 132 TestQuadLineIntersectionThreaded) |
| OLD | NEW |