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

Side by Side Diff: tests/PathOpsCubicLineIntersectionTest.cpp

Issue 18058007: path ops work in progress (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: try try again Created 7 years, 5 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/PathOpsCubicIntersectionTest.cpp ('k') | tests/PathOpsExtendedTest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkIntersections.h" 7 #include "SkIntersections.h"
8 #include "SkPathOpsCubic.h" 8 #include "SkPathOpsCubic.h"
9 #include "SkPathOpsLine.h" 9 #include "SkPathOpsLine.h"
10 #include "SkReduceOrder.h" 10 #include "SkReduceOrder.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static struct lineCubic { 13 static struct lineCubic {
14 SkDCubic cubic; 14 SkDCubic cubic;
15 SkDLine line; 15 SkDLine line;
16 } lineCubicTests[] = { 16 } lineCubicTests[] = {
17 {{{{1006.6951293945312,291}, {1023.263671875,291}, {1033.8402099609375,304.4 3145751953125},
18 {1030.318359375,321}}},
19 {{{979.30487060546875,561}, {1036.695068359375,291}}}},
20 {{{{259.30487060546875,561}, {242.73631286621094,561}, {232.15980529785156,5 47.56854248046875},
21 {235.68154907226562,531}}},
22 {{{286.69512939453125,291}, {229.30485534667969,561}}}},
17 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}}, 23 {{{{1, 2}, {2, 6}, {2, 0}, {1, 0}}}, {{{1, 0}, {1, 2}}}},
18 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}}, 24 {{{{0, 0}, {0, 1}, {0, 1}, {1, 1}}}, {{{0, 1}, {1, 0}}}},
19 }; 25 };
20 26
21 static const size_t lineCubicTests_count = SK_ARRAY_COUNT(lineCubicTests); 27 static const size_t lineCubicTests_count = SK_ARRAY_COUNT(lineCubicTests);
22 28
23 static void PathOpsCubicLineIntersectionTest(skiatest::Reporter* reporter) { 29 static void testOne(skiatest::Reporter* reporter, int iIndex) {
24 for (size_t index = 0; index < lineCubicTests_count; ++index) { 30 const SkDCubic& cubic = lineCubicTests[iIndex].cubic;
25 int iIndex = static_cast<int>(index); 31 const SkDLine& line = lineCubicTests[iIndex].line;
26 const SkDCubic& cubic = lineCubicTests[index].cubic; 32 SkReduceOrder reduce1;
27 const SkDLine& line = lineCubicTests[index].line; 33 SkReduceOrder reduce2;
28 SkReduceOrder reduce1; 34 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics,
29 SkReduceOrder reduce2; 35 SkReduceOrder::kFill_Style);
30 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics, 36 int order2 = reduce2.reduce(line);
31 SkReduceOrder::kFill_Style); 37 if (order1 < 4) {
32 int order2 = reduce2.reduce(line); 38 SkDebugf("[%d] cubic order=%d\n", iIndex, order1);
33 if (order1 < 4) { 39 REPORTER_ASSERT(reporter, 0);
34 SkDebugf("[%d] cubic order=%d\n", iIndex, order1); 40 }
35 REPORTER_ASSERT(reporter, 0); 41 if (order2 < 2) {
36 } 42 SkDebugf("[%d] line order=%d\n", iIndex, order2);
37 if (order2 < 2) { 43 REPORTER_ASSERT(reporter, 0);
38 SkDebugf("[%d] line order=%d\n", iIndex, order2); 44 }
39 REPORTER_ASSERT(reporter, 0); 45 if (order1 == 4 && order2 == 2) {
40 } 46 SkIntersections i;
41 if (order1 == 4 && order2 == 2) { 47 int roots = i.intersect(cubic, line);
42 SkIntersections i; 48 for (int pt = 0; pt < roots; ++pt) {
43 int roots = i.intersect(cubic, line); 49 double tt1 = i[0][pt];
44 for (int pt = 0; pt < roots; ++pt) { 50 SkDPoint xy1 = cubic.xyAtT(tt1);
45 double tt1 = i[0][pt]; 51 double tt2 = i[1][pt];
46 SkDPoint xy1 = cubic.xyAtT(tt1); 52 SkDPoint xy2 = line.xyAtT(tt2);
47 double tt2 = i[1][pt]; 53 if (!xy1.approximatelyEqual(xy2)) {
48 SkDPoint xy2 = line.xyAtT(tt2); 54 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
49 if (!xy1.approximatelyEqual(xy2)) { 55 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
50 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
51 __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2. fX, xy2.fY);
52 }
53 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
54 } 56 }
57 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
55 } 58 }
56 } 59 }
57 } 60 }
58 61
62 static void PathOpsCubicLineIntersectionTest(skiatest::Reporter* reporter) {
63 for (size_t index = 0; index < lineCubicTests_count; ++index) {
64 int iIndex = static_cast<int>(index);
65 testOne(reporter, iIndex);
66 reporter->bumpTestCount();
67 }
68 }
69
70 static void PathOpsCubicLineIntersectionTestOne(skiatest::Reporter* reporter) {
71 int iIndex = 0;
72 testOne(reporter, iIndex);
73 const SkDCubic& cubic = lineCubicTests[iIndex].cubic;
74 const SkDLine& line = lineCubicTests[iIndex].line;
75 SkIntersections i;
76 i.intersect(cubic, line);
77 SkASSERT(i.used() == 1);
78 #if ONE_OFF_DEBUG
79 double cubicT = i[0][0];
80 SkDPoint prev = cubic.xyAtT(cubicT * 2 - 1);
81 SkDPoint sect = cubic.xyAtT(cubicT);
82 double left[3] = { line.isLeft(prev), line.isLeft(sect), line.isLeft(cubic[3 ]) };
83 SkDebugf("cubic=(%1.9g, %1.9g, %1.9g)\n", left[0], left[1], left[2]);
84 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prev.fX, prev.fY, sect.fX, sec t.fY);
85 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", sect.fX, sect.fY, cubic[3].fX, cubic[3].fY);
86 SkDPoint prevL = line.xyAtT(i[1][0] - 0.0000007);
87 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prevL.fX, prevL.fY, i.pt(0).fX , i.pt(0).fY);
88 SkDPoint nextL = line.xyAtT(i[1][0] + 0.0000007);
89 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", i.pt(0).fX, i.pt(0).fY, nextL. fX, nextL.fY);
90 SkDebugf("prevD=%1.9g dist=%1.9g nextD=%1.9g\n", prev.distance(nextL),
91 sect.distance(i.pt(0)), cubic[3].distance(prevL));
92 #endif
93 }
94
59 #include "TestClassDef.h" 95 #include "TestClassDef.h"
60 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTest) 96 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTest)
97
98 DEFINE_TESTCLASS_SHORT(PathOpsCubicLineIntersectionTestOne)
OLDNEW
« no previous file with comments | « tests/PathOpsCubicIntersectionTest.cpp ('k') | tests/PathOpsExtendedTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698