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

Side by Side Diff: tests/PathOpsConicLineIntersectionTest.cpp

Issue 2426173002: fix fuzzers (Closed)
Patch Set: fix dm Created 4 years, 2 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 | « tests/PathOpsConicIntersectionTest.cpp ('k') | tests/PathOpsConicQuadIntersectionTest.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 "PathOpsExtendedTest.h" 7 #include "PathOpsExtendedTest.h"
8 #include "PathOpsTestCommon.h" 8 #include "PathOpsTestCommon.h"
9 #include "SkGeometry.h" 9 #include "SkGeometry.h"
10 #include "SkIntersections.h" 10 #include "SkIntersections.h"
11 #include "SkPathOpsConic.h" 11 #include "SkPathOpsConic.h"
12 #include "SkPathOpsLine.h" 12 #include "SkPathOpsLine.h"
13 #include "SkReduceOrder.h" 13 #include "SkReduceOrder.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static struct lineConic { 16 static struct lineConic {
17 SkDConic conic; 17 ConicPts conic;
18 SkDLine line; 18 SkDLine line;
19 int result; 19 int result;
20 SkDPoint expected[2]; 20 SkDPoint expected[2];
21 } lineConicTests[] = { 21 } lineConicTests[] = {
22 { 22 {
23 {{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996 }}}, 0.707107008f}, 23 {{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996 }}}, 0.707107008f},
24 {{{25.6499996,20.6499996}, {45.6500015,20.6499996}}}, 24 {{{25.6499996,20.6499996}, {45.6500015,20.6499996}}},
25 1, 25 1,
26 {{25.6499996,20.6499996}, {0,0}} 26 {{25.6499996,20.6499996}, {0,0}}
27 }, 27 },
(...skipping 22 matching lines...) Expand all
50 } 50 }
51 result = intersections.horizontal(conic, left, right, line[0].fY, flippe d); 51 result = intersections.horizontal(conic, left, right, line[0].fY, flippe d);
52 } else { 52 } else {
53 intersections.intersect(conic, line); 53 intersections.intersect(conic, line);
54 result = intersections.used(); 54 result = intersections.used();
55 } 55 }
56 return result; 56 return result;
57 } 57 }
58 58
59 static struct oneLineConic { 59 static struct oneLineConic {
60 SkDConic conic; 60 ConicPts conic;
61 SkDLine line; 61 SkDLine line;
62 } oneOffs[] = { 62 } oneOffs[] = {
63 {{{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996 }}}, 0.707107008f}, 63 {{{{{30.6499996,25.6499996}, {30.6499996,20.6499996}, {25.6499996,20.6499996 }}}, 0.707107008f},
64 {{{25.6499996,20.6499996}, {45.6500015,20.6499996}}}} 64 {{{25.6499996,20.6499996}, {45.6500015,20.6499996}}}}
65 }; 65 };
66 66
67 static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs); 67 static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs);
68 68
69 static void testOneOffs(skiatest::Reporter* reporter) { 69 static void testOneOffs(skiatest::Reporter* reporter) {
70 bool flipped = false; 70 bool flipped = false;
71 for (size_t index = 0; index < oneOffs_count; ++index) { 71 for (size_t index = 0; index < oneOffs_count; ++index) {
72 const SkDConic& conic = oneOffs[index].conic; 72 const ConicPts& c = oneOffs[index].conic;
73 SkDConic conic;
74 conic.debugSet(c.fPts.fPts, c.fWeight);
73 SkASSERT(ValidConic(conic)); 75 SkASSERT(ValidConic(conic));
74 const SkDLine& line = oneOffs[index].line; 76 const SkDLine& line = oneOffs[index].line;
75 SkASSERT(ValidLine(line)); 77 SkASSERT(ValidLine(line));
76 SkIntersections intersections; 78 SkIntersections intersections;
77 int result = doIntersect(intersections, conic, line, flipped); 79 int result = doIntersect(intersections, conic, line, flipped);
78 for (int inner = 0; inner < result; ++inner) { 80 for (int inner = 0; inner < result; ++inner) {
79 double conicT = intersections[0][inner]; 81 double conicT = intersections[0][inner];
80 SkDPoint conicXY = conic.ptAtT(conicT); 82 SkDPoint conicXY = conic.ptAtT(conicT);
81 double lineT = intersections[1][inner]; 83 double lineT = intersections[1][inner];
82 SkDPoint lineXY = line.ptAtT(lineT); 84 SkDPoint lineXY = line.ptAtT(lineT);
83 if (!conicXY.approximatelyEqual(lineXY)) { 85 if (!conicXY.approximatelyEqual(lineXY)) {
84 conicXY.approximatelyEqual(lineXY); 86 conicXY.approximatelyEqual(lineXY);
85 SkDebugf(""); 87 SkDebugf("");
86 } 88 }
87 REPORTER_ASSERT(reporter, conicXY.approximatelyEqual(lineXY)); 89 REPORTER_ASSERT(reporter, conicXY.approximatelyEqual(lineXY));
88 } 90 }
89 } 91 }
90 } 92 }
91 93
92 DEF_TEST(PathOpsConicLineIntersectionOneOff, reporter) { 94 DEF_TEST(PathOpsConicLineIntersectionOneOff, reporter) {
93 testOneOffs(reporter); 95 testOneOffs(reporter);
94 } 96 }
95 97
96 DEF_TEST(PathOpsConicLineIntersection, reporter) { 98 DEF_TEST(PathOpsConicLineIntersection, reporter) {
97 for (size_t index = 0; index < lineConicTests_count; ++index) { 99 for (size_t index = 0; index < lineConicTests_count; ++index) {
98 int iIndex = static_cast<int>(index); 100 int iIndex = static_cast<int>(index);
99 const SkDConic& conic = lineConicTests[index].conic; 101 const ConicPts& c = lineConicTests[index].conic;
102 SkDConic conic;
103 conic.debugSet(c.fPts.fPts, c.fWeight);
100 SkASSERT(ValidConic(conic)); 104 SkASSERT(ValidConic(conic));
101 const SkDLine& line = lineConicTests[index].line; 105 const SkDLine& line = lineConicTests[index].line;
102 SkASSERT(ValidLine(line)); 106 SkASSERT(ValidLine(line));
103 SkReduceOrder reducer; 107 SkReduceOrder reducer;
104 SkPoint pts[3] = { conic.fPts.fPts[0].asSkPoint(), conic.fPts.fPts[1].as SkPoint(), 108 SkPoint pts[3] = { conic.fPts.fPts[0].asSkPoint(), conic.fPts.fPts[1].as SkPoint(),
105 conic.fPts.fPts[2].asSkPoint() }; 109 conic.fPts.fPts[2].asSkPoint() };
106 SkPoint reduced[3]; 110 SkPoint reduced[3];
107 SkConic floatConic; 111 SkConic floatConic;
108 floatConic.set(pts, conic.fWeight); 112 floatConic.set(pts, conic.fWeight);
109 SkPath::Verb order1 = SkReduceOrder::Conic(floatConic, reduced); 113 SkPath::Verb order1 = SkReduceOrder::Conic(floatConic, reduced);
(...skipping 27 matching lines...) Expand all
137 } 141 }
138 if (!t1.approximatelyEqual(lineConicTests[index].expected[0]) 142 if (!t1.approximatelyEqual(lineConicTests[index].expected[0])
139 && (lineConicTests[index].result == 1 143 && (lineConicTests[index].result == 1
140 || !t1.approximatelyEqual(lineConicTests[index].expected[1]) )) { 144 || !t1.approximatelyEqual(lineConicTests[index].expected[1]) )) {
141 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY); 145 SkDebugf("%s t1=(%1.9g,%1.9g)\n", __FUNCTION__, t1.fX, t1.fY);
142 REPORTER_ASSERT(reporter, 0); 146 REPORTER_ASSERT(reporter, 0);
143 } 147 }
144 } 148 }
145 } 149 }
146 } 150 }
OLDNEW
« no previous file with comments | « tests/PathOpsConicIntersectionTest.cpp ('k') | tests/PathOpsConicQuadIntersectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698