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

Side by Side Diff: tests/PathOpsCubicToQuadsTest.cpp

Issue 16951017: convert pathops to use SkSTArray where possible. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: pathops use SkTArray Created 7 years, 6 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/PathOpsTestCommon.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 "PathOpsCubicIntersectionTestData.h" 7 #include "PathOpsCubicIntersectionTestData.h"
8 #include "PathOpsQuadIntersectionTestData.h" 8 #include "PathOpsQuadIntersectionTestData.h"
9 #include "PathOpsTestCommon.h" 9 #include "PathOpsTestCommon.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
11 #include "SkIntersections.h" 11 #include "SkIntersections.h"
12 #include "SkPathOpsRect.h" 12 #include "SkPathOpsRect.h"
13 #include "SkReduceOrder.h" 13 #include "SkReduceOrder.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 static void test(skiatest::Reporter* reporter, const SkDCubic* cubics, const cha r* name, 16 static void test(skiatest::Reporter* reporter, const SkDCubic* cubics, const cha r* name,
17 int firstTest, size_t testCount) { 17 int firstTest, size_t testCount) {
18 for (size_t index = firstTest; index < testCount; ++index) { 18 for (size_t index = firstTest; index < testCount; ++index) {
19 const SkDCubic& cubic = cubics[index]; 19 const SkDCubic& cubic = cubics[index];
20 double precision = cubic.calcPrecision(); 20 double precision = cubic.calcPrecision();
21 SkTDArray<SkDQuad> quads; 21 SkTArray<SkDQuad, true> quads;
22 CubicToQuads(cubic, precision, quads); 22 CubicToQuads(cubic, precision, quads);
23 if (quads.count() != 1 && quads.count() != 2) { 23 if (quads.count() != 1 && quads.count() != 2) {
24 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index), 24 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index),
25 quads.count()); 25 quads.count());
26 } 26 }
27 REPORTER_ASSERT(reporter, quads.count() == 1); 27 REPORTER_ASSERT(reporter, quads.count() == 1);
28 } 28 }
29 } 29 }
30 30
31 static void test(skiatest::Reporter* reporter, const SkDQuad* quadTests, const c har* name, 31 static void test(skiatest::Reporter* reporter, const SkDQuad* quadTests, const c har* name,
32 int firstTest, size_t testCount) { 32 int firstTest, size_t testCount) {
33 for (size_t index = firstTest; index < testCount; ++index) { 33 for (size_t index = firstTest; index < testCount; ++index) {
34 const SkDQuad& quad = quadTests[index]; 34 const SkDQuad& quad = quadTests[index];
35 SkDCubic cubic = quad.toCubic(); 35 SkDCubic cubic = quad.toCubic();
36 double precision = cubic.calcPrecision(); 36 double precision = cubic.calcPrecision();
37 SkTDArray<SkDQuad> quads; 37 SkTArray<SkDQuad, true> quads;
38 CubicToQuads(cubic, precision, quads); 38 CubicToQuads(cubic, precision, quads);
39 if (quads.count() != 1 && quads.count() != 2) { 39 if (quads.count() != 1 && quads.count() != 2) {
40 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index), 40 SkDebugf("%s [%d] cubic to quadratics failed count=%d\n", name, stat ic_cast<int>(index),
41 quads.count()); 41 quads.count());
42 } 42 }
43 REPORTER_ASSERT(reporter, quads.count() <= 2); 43 REPORTER_ASSERT(reporter, quads.count() <= 2);
44 } 44 }
45 } 45 }
46 46
47 static void testC(skiatest::Reporter* reporter, const SkDCubic* cubics, const ch ar* name, 47 static void testC(skiatest::Reporter* reporter, const SkDCubic* cubics, const ch ar* name,
48 int firstTest, size_t testCount) { 48 int firstTest, size_t testCount) {
49 // test if computed line end points are valid 49 // test if computed line end points are valid
50 for (size_t index = firstTest; index < testCount; ++index) { 50 for (size_t index = firstTest; index < testCount; ++index) {
51 const SkDCubic& cubic = cubics[index]; 51 const SkDCubic& cubic = cubics[index];
52 double precision = cubic.calcPrecision(); 52 double precision = cubic.calcPrecision();
53 SkTDArray<SkDQuad> quads; 53 SkTArray<SkDQuad, true> quads;
54 CubicToQuads(cubic, precision, quads); 54 CubicToQuads(cubic, precision, quads);
55 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) 55 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX)
56 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { 56 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) {
57 SkDebugf("[%d] unmatched start\n", static_cast<int>(index)); 57 SkDebugf("[%d] unmatched start\n", static_cast<int>(index));
58 REPORTER_ASSERT(reporter, 0); 58 REPORTER_ASSERT(reporter, 0);
59 } 59 }
60 int last = quads.count() - 1; 60 int last = quads.count() - 1;
61 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) 61 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX)
62 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) { 62 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) {
63 SkDebugf("[%d] unmatched end\n", static_cast<int>(index)); 63 SkDebugf("[%d] unmatched end\n", static_cast<int>(index));
64 REPORTER_ASSERT(reporter, 0); 64 REPORTER_ASSERT(reporter, 0);
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 static void testC(skiatest::Reporter* reporter, const SkDCubic(* cubics)[2], con st char* name, 69 static void testC(skiatest::Reporter* reporter, const SkDCubic(* cubics)[2], con st char* name,
70 int firstTest, size_t testCount) { 70 int firstTest, size_t testCount) {
71 for (size_t index = firstTest; index < testCount; ++index) { 71 for (size_t index = firstTest; index < testCount; ++index) {
72 for (int idx2 = 0; idx2 < 2; ++idx2) { 72 for (int idx2 = 0; idx2 < 2; ++idx2) {
73 const SkDCubic& cubic = cubics[index][idx2]; 73 const SkDCubic& cubic = cubics[index][idx2];
74 double precision = cubic.calcPrecision(); 74 double precision = cubic.calcPrecision();
75 SkTDArray<SkDQuad> quads; 75 SkTArray<SkDQuad, true> quads;
76 CubicToQuads(cubic, precision, quads); 76 CubicToQuads(cubic, precision, quads);
77 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX) 77 if (!AlmostEqualUlps(cubic[0].fX, quads[0][0].fX)
78 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) { 78 || !AlmostEqualUlps(cubic[0].fY, quads[0][0].fY)) {
79 SkDebugf("[%d][%d] unmatched start\n", static_cast<int>(index), idx2); 79 SkDebugf("[%d][%d] unmatched start\n", static_cast<int>(index), idx2);
80 REPORTER_ASSERT(reporter, 0); 80 REPORTER_ASSERT(reporter, 0);
81 } 81 }
82 int last = quads.count() - 1; 82 int last = quads.count() - 1;
83 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX) 83 if (!AlmostEqualUlps(cubic[3].fX, quads[last][2].fX)
84 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) { 84 || !AlmostEqualUlps(cubic[3].fY, quads[last][2].fY)) {
85 SkDebugf("[%d][%d] unmatched end\n", static_cast<int>(index), id x2); 85 SkDebugf("[%d][%d] unmatched end\n", static_cast<int>(index), id x2);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 static void oneOff(skiatest::Reporter* reporter, size_t x) { 169 static void oneOff(skiatest::Reporter* reporter, size_t x) {
170 const SkDCubic& cubic = locals[x]; 170 const SkDCubic& cubic = locals[x];
171 const SkPoint skcubic[4] = { 171 const SkPoint skcubic[4] = {
172 {static_cast<float>(cubic[0].fX), static_cast<float>(cubic[0].fY)}, 172 {static_cast<float>(cubic[0].fX), static_cast<float>(cubic[0].fY)},
173 {static_cast<float>(cubic[1].fX), static_cast<float>(cubic[1].fY)}, 173 {static_cast<float>(cubic[1].fX), static_cast<float>(cubic[1].fY)},
174 {static_cast<float>(cubic[2].fX), static_cast<float>(cubic[2].fY)}, 174 {static_cast<float>(cubic[2].fX), static_cast<float>(cubic[2].fY)},
175 {static_cast<float>(cubic[3].fX), static_cast<float>(cubic[3].fY)}}; 175 {static_cast<float>(cubic[3].fX), static_cast<float>(cubic[3].fY)}};
176 SkScalar skinflect[2]; 176 SkScalar skinflect[2];
177 int skin = SkFindCubicInflections(skcubic, skinflect); 177 int skin = SkFindCubicInflections(skcubic, skinflect);
178 if (false) SkDebugf("%s %d %1.9g\n", __FUNCTION__, skin, skinflect[0]); 178 if (false) SkDebugf("%s %d %1.9g\n", __FUNCTION__, skin, skinflect[0]);
179 SkTDArray<SkDQuad> quads; 179 SkTArray<SkDQuad, true> quads;
180 double precision = cubic.calcPrecision(); 180 double precision = cubic.calcPrecision();
181 CubicToQuads(cubic, precision, quads); 181 CubicToQuads(cubic, precision, quads);
182 if (false) SkDebugf("%s quads=%d\n", __FUNCTION__, quads.count()); 182 if (false) SkDebugf("%s quads=%d\n", __FUNCTION__, quads.count());
183 } 183 }
184 184
185 static void CubicsToQuadratics_OneOffTests(skiatest::Reporter* reporter) { 185 static void CubicsToQuadratics_OneOffTests(skiatest::Reporter* reporter) {
186 for (size_t x = 0; x < localsCount; ++x) { 186 for (size_t x = 0; x < localsCount; ++x) {
187 oneOff(reporter, x); 187 oneOff(reporter, x);
188 } 188 }
189 } 189 }
190 190
191 static void CubicsToQuadratics_OneOffTest(skiatest::Reporter* reporter) { 191 static void CubicsToQuadratics_OneOffTest(skiatest::Reporter* reporter) {
192 oneOff(reporter, 0); 192 oneOff(reporter, 0);
193 } 193 }
194 194
195 static void PathOpsCubicToQuadsTest(skiatest::Reporter* reporter) { 195 static void PathOpsCubicToQuadsTest(skiatest::Reporter* reporter) {
196 CubicToQuads_Test(reporter); 196 CubicToQuads_Test(reporter);
197 CubicsToQuadratics_OneOffTest(reporter); 197 CubicsToQuadratics_OneOffTest(reporter);
198 CubicsToQuadratics_OneOffTests(reporter); 198 CubicsToQuadratics_OneOffTests(reporter);
199 } 199 }
200 200
201 #include "TestClassDef.h" 201 #include "TestClassDef.h"
202 DEFINE_TESTCLASS_SHORT(PathOpsCubicToQuadsTest) 202 DEFINE_TESTCLASS_SHORT(PathOpsCubicToQuadsTest)
OLDNEW
« no previous file with comments | « tests/PathOpsCubicIntersectionTest.cpp ('k') | tests/PathOpsTestCommon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698