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

Side by Side Diff: tests/PathOpsQuadLineIntersectionThreadedTest.cpp

Issue 13094010: Add implementation of path ops (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsSimplifyDegenerateThreadedTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "PathOpsExtendedTest.h"
8 #include "SkIntersections.h"
9 #include "SkPathOpsLine.h"
10 #include "SkPathOpsQuad.h"
11 #include "SkReduceOrder.h"
12
13 static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, cons t SkDLine& line,
14 bool& flipped) {
15 int result;
16 flipped = false;
17 if (line[0].fX == line[1].fX) {
18 double top = line[0].fY;
19 double bottom = line[1].fY;
20 flipped = top > bottom;
21 if (flipped) {
22 SkTSwap<double>(top, bottom);
23 }
24 result = intersections.vertical(quad, top, bottom, line[0].fX, flipped);
25 } else if (line[0].fY == line[1].fY) {
26 double left = line[0].fX;
27 double right = line[1].fX;
28 flipped = left > right;
29 if (flipped) {
30 SkTSwap<double>(left, right);
31 }
32 result = intersections.horizontal(quad, left, right, line[0].fY, flipped );
33 } else {
34 intersections.intersect(quad, line);
35 result = intersections.used();
36 }
37 return result;
38 }
39
40 static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad,
41 const SkDLine& line, const double x, const double y) {
42 char pathStr[1024];
43 bzero(pathStr, sizeof(pathStr));
44 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.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.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);
49
50 SkIntersections intersections;
51 bool flipped = false;
52 int result = doIntersect(intersections, quad, line, flipped);
53 bool found = false;
54 for (int index = 0; index < result; ++index) {
55 double quadT = intersections[0][index];
56 SkDPoint quadXY = quad.xyAtT(quadT);
57 double lineT = intersections[1][index];
58 SkDPoint lineXY = line.xyAtT(lineT);
59 if (quadXY.approximatelyEqual(lineXY)) {
60 found = true;
61 }
62 }
63 REPORTER_ASSERT(reporter, found);
64 }
65
66
67 // find a point on a quad by choosing a t from 0 to 1
68 // create a vertical span above and below the point
69 // 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
71 // verify that a vertical span starting at quad[2] intersects at t=1
72 static void* testQuadLineIntersectMain(void* data)
73 {
74 State4& state = *(State4*) data;
75 REPORTER_ASSERT(state.reporter, data);
76 do {
77 int ax = state.a & 0x03;
78 int ay = state.a >> 2;
79 int bx = state.b & 0x03;
80 int by = state.b >> 2;
81 int cx = state.c & 0x03;
82 int cy = state.c >> 2;
83 SkDQuad quad = {{{ax, ay}, {bx, by}, {cx, cy}}};
84 SkReduceOrder reducer;
85 int order = reducer.reduce(quad, SkReduceOrder::kFill_Style);
86 if (order < 3) {
87 continue; // skip degenerates
88 }
89 for (int tIndex = 0; tIndex <= 4; ++tIndex) {
90 SkDPoint xy = quad.xyAtT(tIndex / 4.0);
91 for (int h = -2; h <= 2; ++h) {
92 for (int v = -2; v <= 2; ++v) {
93 if (h == v && abs(h) != 1) {
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 }
106 }
107 }
108 } while (runNextTestSet(state));
109 return NULL;
110 }
111
112 static void TestQuadLineIntersectionThreaded(skiatest::Reporter* reporter)
113 {
114 int testsRun = 0;
115 if (gShowTestProgress) SkDebugf("%s\n", __FUNCTION__);
116 const char testStr[] = "testQuadLineIntersect";
117 initializeTests(reporter, testStr, sizeof(testStr));
118 for (int a = 0; a < 16; ++a) {
119 for (int b = 0 ; b < 16; ++b) {
120 for (int c = 0 ; c < 16; ++c) {
121 testsRun += dispatchTest4(testQuadLineIntersectMain, a, b, c, 0) ;
122 }
123 if (!gAllowExtendedTest) goto finish;
124 if (gShowTestProgress) SkDebugf(".");
125 }
126 if (gShowTestProgress) SkDebugf("%d", a);
127 }
128 finish:
129 testsRun += waitForCompletion();
130 if (gShowTestProgress) SkDebugf("\n%s tests=%d\n", __FUNCTION__, testsRun);
131 }
132
133 #include "TestClassDef.h"
134 DEFINE_TESTCLASS("PathOpsQuadLineIntersectionThreaded", QuadLineIntersectionThre adedTestClass, \
135 TestQuadLineIntersectionThreaded)
OLDNEW
« no previous file with comments | « tests/PathOpsOpTest.cpp ('k') | tests/PathOpsSimplifyDegenerateThreadedTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698