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

Side by Side Diff: tests/PathOpsCubicLineIntersectionTest.cpp

Issue 252243003: fix cubic/line intersection; add skp tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bracket new test correctly Created 6 years, 7 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
« no previous file with comments | « src/pathops/SkDCubicLineIntersection.cpp ('k') | tests/PathOpsExtendedTest.cpp » ('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 "PathOpsTestCommon.h" 7 #include "PathOpsTestCommon.h"
8 #include "SkIntersections.h" 8 #include "SkIntersections.h"
9 #include "SkPathOpsCubic.h" 9 #include "SkPathOpsCubic.h"
10 #include "SkPathOpsLine.h" 10 #include "SkPathOpsLine.h"
11 #include "SkReduceOrder.h" 11 #include "SkReduceOrder.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 static struct lineCubic { 14 struct lineCubic {
15 SkDCubic cubic; 15 SkDCubic cubic;
16 SkDLine line; 16 SkDLine line;
17 } lineCubicTests[] = { 17 };
18
19 static lineCubic failLineCubicTests[] = {
20 {{{{37.5273438,-1.44140625}, {37.8736992,-1.69921875}, {38.1640625,-2.140625 },
21 {38.3984375,-2.765625}}},
22 {{{40.625,-5.7890625}, {37.7109375,1.3515625}}}},
23 };
24
25 static const size_t failLineCubicTests_count = SK_ARRAY_COUNT(failLineCubicTests );
26
27 static void testFail(skiatest::Reporter* reporter, int iIndex) {
28 const SkDCubic& cubic = failLineCubicTests[iIndex].cubic;
29 SkASSERT(ValidCubic(cubic));
30 const SkDLine& line = failLineCubicTests[iIndex].line;
31 SkASSERT(ValidLine(line));
32 SkReduceOrder reduce1;
33 SkReduceOrder reduce2;
34 int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
35 int order2 = reduce2.reduce(line);
36 if (order1 < 4) {
37 SkDebugf("[%d] cubic order=%d\n", iIndex, order1);
38 REPORTER_ASSERT(reporter, 0);
39 }
40 if (order2 < 2) {
41 SkDebugf("[%d] line order=%d\n", iIndex, order2);
42 REPORTER_ASSERT(reporter, 0);
43 }
44 if (order1 == 4 && order2 == 2) {
45 SkIntersections i;
46 int roots = i.intersect(cubic, line);
47 REPORTER_ASSERT(reporter, roots == 0);
48 }
49 }
50
51 static lineCubic lineCubicTests[] = {
52
18 {{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}}, 53 {{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}},
19 {{{320, 378}, {421, 378.000031f}}}}, 54 {{{320, 378}, {421, 378.000031f}}}},
20 55
21 {{{{416, 383}, {418.761414f, 383}, {421, 380.761414f}, {421, 378}}}, 56 {{{{416, 383}, {418.761414f, 383}, {421, 380.761414f}, {421, 378}}},
22 {{{320, 378}, {421, 378.000031f}}}}, 57 {{{320, 378}, {421, 378.000031f}}}},
23 58
24 {{{{154,715}, {151.238571,715}, {149,712.761414}, {149,710}}}, 59 {{{{154,715}, {151.238571,715}, {149,712.761414}, {149,710}}},
25 {{{149,675}, {149,710.001465}}}}, 60 {{{149,675}, {149,710.001465}}}},
26 61
27 {{{{0,1}, {1,6}, {4,1}, {4,3}}}, 62 {{{{0,1}, {1,6}, {4,1}, {4,3}}},
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 SkDPoint prevL = line.ptAtT(i[1][0] - 0.0000007); 125 SkDPoint prevL = line.ptAtT(i[1][0] - 0.0000007);
91 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prevL.fX, prevL.fY, i.pt(0 ).fX, i.pt(0).fY); 126 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", prevL.fX, prevL.fY, i.pt(0 ).fX, i.pt(0).fY);
92 SkDPoint nextL = line.ptAtT(i[1][0] + 0.0000007); 127 SkDPoint nextL = line.ptAtT(i[1][0] + 0.0000007);
93 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", i.pt(0).fX, i.pt(0).fY, ne xtL.fX, nextL.fY); 128 SkDebugf("{{%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", i.pt(0).fX, i.pt(0).fY, ne xtL.fX, nextL.fY);
94 SkDebugf("prevD=%1.9g dist=%1.9g nextD=%1.9g\n", prev.distance(nextL), 129 SkDebugf("prevD=%1.9g dist=%1.9g nextD=%1.9g\n", prev.distance(nextL),
95 sect.distance(i.pt(0)), cubic[3].distance(prevL)); 130 sect.distance(i.pt(0)), cubic[3].distance(prevL));
96 #endif 131 #endif
97 } 132 }
98 } 133 }
99 134
135 DEF_TEST(PathOpsFailCubicLineIntersection, reporter) {
136 for (size_t index = 0; index < failLineCubicTests_count; ++index) {
137 int iIndex = static_cast<int>(index);
138 testFail(reporter, iIndex);
139 reporter->bumpTestCount();
140 }
141 }
142
100 DEF_TEST(PathOpsCubicLineIntersection, reporter) { 143 DEF_TEST(PathOpsCubicLineIntersection, reporter) {
101 for (size_t index = 0; index < lineCubicTests_count; ++index) { 144 for (size_t index = 0; index < lineCubicTests_count; ++index) {
102 int iIndex = static_cast<int>(index); 145 int iIndex = static_cast<int>(index);
103 testOne(reporter, iIndex); 146 testOne(reporter, iIndex);
104 reporter->bumpTestCount(); 147 reporter->bumpTestCount();
105 } 148 }
106 } 149 }
107 150
108 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) { 151 DEF_TEST(PathOpsCubicLineIntersectionOneOff, reporter) {
109 int iIndex = 0; 152 int iIndex = 0;
110 testOne(reporter, iIndex); 153 testOne(reporter, iIndex);
111 const SkDCubic& cubic = lineCubicTests[iIndex].cubic; 154 const SkDCubic& cubic = lineCubicTests[iIndex].cubic;
112 const SkDLine& line = lineCubicTests[iIndex].line; 155 const SkDLine& line = lineCubicTests[iIndex].line;
113 SkIntersections i; 156 SkIntersections i;
114 i.intersect(cubic, line); 157 i.intersect(cubic, line);
115 SkASSERT(i.used() == 1); 158 SkASSERT(i.used() == 1);
116 } 159 }
OLDNEW
« no previous file with comments | « src/pathops/SkDCubicLineIntersection.cpp ('k') | tests/PathOpsExtendedTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698