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

Side by Side Diff: tests/PathOpsAngleTest.cpp

Issue 16195004: add asserts to point<-->verb helpers (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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 | « src/utils/SkParsePath.cpp ('k') | tests/PathOpsOpTest.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 2013 Google Inc. 2 * Copyright 2013 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 "SkOpSegment.h" 7 #include "SkOpSegment.h"
8 #include "Test.h" 8 #include "Test.h"
9 9
10 static const SkPoint cubics[][4] = { 10 static const SkPoint cubics[][4] = {
11 {{0, 1}, {2, 6}, {4, 2}, {5, 3}}, 11 /* 0 */ {{0, 1}, {2, 6}, {4, 2}, {5, 3}},
12 {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}}, 12 /* 1 */ {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}},
13 /* 2 */ {{132, 11419}, {130.89543151855469f, 11419}, {130, 11418.1044921875f} , {130, 11417}},
14 /* 3 */ {{130.04275512695312f, 11417.4130859375f}, {130.23307800292969f, 1141 8.3193359375f},
15 {131.03709411621094f, 11419}, {132, 11419}},
16 /* 4 */ {{0,1}, {0,5}, {4,1}, {6,4}},
17 /* 5 */ {{1,5}, {4,6}, {1,0}, {4,0}},
18 /* 6 */ {{0,1}, {0,4}, {5,1}, {6,4}},
19 /* 7 */ {{0,1}, {1,2}, {1,0}, {6,1}},
20 /* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}},
21 /* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}} ,
22 /* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}},
23 /* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}},
24 /* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}},
13 }; 25 };
14 26
15 static const SkPoint quads[][3] = { 27 static const SkPoint quads[][3] = {
16 {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, 28 /* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}},
29 /* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f} , {306,596}},
17 }; 30 };
18 31
19 static const SkPoint lines[][2] = { 32 static const SkPoint lines[][2] = {
20 {{6, 2}, {2, 4}}, 33 /* 0 */ {{6, 2}, {2, 4}},
34 /* 1 */ {{306,617}, {306,590}},
35 /* 2 */ {{306,596}, {306,617}},
36 /* 3 */ {{6,4}, {0,1}},
37 /* 4 */ {{6,1}, {0,1}},
38 /* 5 */ {{1,0}, {0,3}},
39 /* 6 */ {{246,4}, {189,4}},
40 /* 7 */ {{192,4}, {243,4}},
41 /* 8 */ {{4,3}, {0,1}},
42 /* 9 */ {{3,2}, {1,2}},
21 }; 43 };
22 44
23 struct SortSet { 45 struct SortSet {
24 const SkPoint* ptData; 46 const SkPoint* ptData;
25 int ptCount; 47 int ptCount;
26 double tStart; 48 double tStart;
27 double tEnd; 49 double tEnd;
28 }; 50 };
29 51
30 static const SortSet set1[] = { 52 static const SortSet set1[] = {
31 {cubics[0], 4, 0.66666987081928919, 0.875}, 53 {cubics[0], 4, 0.66666987081928919, 0.875},
32 {lines[0], 2, 0.574070336, 0.388888889}, 54 {lines[0], 2, 0.574070336, 0.388888889},
33 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307 }, 55 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307 },
34 {lines[0], 2, 0.574070336, 0.9140625}, 56 {lines[0], 2, 0.574070336, 0.9140625},
35 }; 57 };
36 58
37 static const SortSet set2[] = { 59 static const SortSet set2[] = {
38 {cubics[0], 4, 0.666666667, 0.875}, 60 {cubics[0], 4, 0.666666667, 0.875},
39 {lines[0], 2, 0.574074074, 0.388888889}, 61 {lines[0], 2, 0.574074074, 0.388888889},
40 {cubics[0], 4, 0.666666667, 0.405037112}, 62 {cubics[0], 4, 0.666666667, 0.405037112},
41 {lines[0], 2, 0.574074074, 0.9140625}, 63 {lines[0], 2, 0.574074074, 0.9140625},
42 }; 64 };
43 65
44 static const SortSet set3[] = { 66 static const SortSet set3[] = {
45 {cubics[1], 4, 0, 1}, 67 {cubics[1], 4, 0, 1},
46 {quads[0], 3, 1, 0}, 68 {quads[0], 3, 1, 0},
47 }; 69 };
48 70
71 static const SortSet set4[] = {
72 {cubics[2], 4, 0.812114222, 1},
73 {cubics[3], 4, 0.0684734759, 0},
74 };
75
76 static const SortSet set5[] = {
77 {lines[1], 2, 0.777777778, 1},
78 {quads[1], 3, 1, 4.34137342e-06},
79 {lines[2], 2, 0, 1},
80 };
81
82 static const SortSet set6[] = {
83 {lines[3], 2, 0.407407407, 0.554627832},
84 {cubics[4], 4, 0.666666667, 0.548022446},
85 {lines[3], 2, 0.407407407, 0},
86 {cubics[4], 4, 0.666666667, 1},
87 };
88
89 static const SortSet set7[] = {
90 {cubics[5], 4, 0.545233342, 0.545454545},
91 {cubics[6], 4, 0.484938134, 0.484805744},
92 {cubics[5], 4, 0.545233342, 0},
93 {cubics[6], 4, 0.484938134, 0.545454545},
94 };
95
96 static const SortSet set8[] = {
97 {cubics[7], 4, 0.5, 0.522986744 },
98 {lines[4], 2, 0.75, 1},
99 {cubics[7], 4, 0.5, 0},
100 {lines[4], 2, 0.75, 0.737654321},
101 };
102
103 static const SortSet set9[] = {
104 {cubics[8], 4, 0.4, 1},
105 {lines[5], 2, 0.36, 0},
106 {cubics[8], 4, 0.4, 0.394675838},
107 {lines[5], 2, 0.36, 0.363999782},
108 };
109
110 static const SortSet set10[] = {
111 {lines[6], 2, 0.947368421, 1},
112 {cubics[9], 4, 1, 0.500000357},
113 {lines[7], 2, 0, 1},
114 };
115
116 static const SortSet set11[] = {
117 {lines[3], 2, 0.75, 1},
118 {cubics[10], 4, 0.5, 0.228744269},
119 {lines[3], 2, 0.75, 0.627112191},
120 {cubics[10], 4, 0.5, 0.6339746},
121 };
122
123 static const SortSet set12[] = {
124 {cubics[12], 4, 0.5, 1},
125 {lines[8], 2, 0.5, 1},
126 {cubics[11], 4, 0.5, 0},
127 {lines[9], 2, 0.5, 1},
128 {cubics[12], 4, 0.5, 0},
129 {lines[8], 2, 0.5, 0},
130 {cubics[11], 4, 0.5, 1},
131 {lines[9], 2, 0.5, 0},
132 };
133
49 struct SortSetTests { 134 struct SortSetTests {
50 const SortSet* set; 135 const SortSet* set;
51 size_t count; 136 size_t count;
52 }; 137 };
53 138
54 static const SortSetTests tests[] = { 139 static const SortSetTests tests[] = {
140 { set12, SK_ARRAY_COUNT(set12) },
141 { set11, SK_ARRAY_COUNT(set11) },
142 { set10, SK_ARRAY_COUNT(set10) },
143 { set9, SK_ARRAY_COUNT(set9) },
144 { set8, SK_ARRAY_COUNT(set8) },
145 { set7, SK_ARRAY_COUNT(set7) },
146 { set6, SK_ARRAY_COUNT(set6) },
147 { set2, SK_ARRAY_COUNT(set2) },
148 { set5, SK_ARRAY_COUNT(set5) },
149 { set4, SK_ARRAY_COUNT(set4) },
55 { set3, SK_ARRAY_COUNT(set3) }, 150 { set3, SK_ARRAY_COUNT(set3) },
56 { set2, SK_ARRAY_COUNT(set2) },
57 { set1, SK_ARRAY_COUNT(set1) }, 151 { set1, SK_ARRAY_COUNT(set1) },
58 }; 152 };
59 153
60 static void setup(const SortSet* set, const size_t idx, SkPoint const ** data, 154 static void setup(const SortSet* set, const size_t idx, SkPoint const ** data,
61 SkOpSegment* seg, int* ts) { 155 SkOpSegment* seg, int* ts) {
62 SkPoint start, end; 156 SkPoint start, end;
63 *data = set[idx].ptData; 157 *data = set[idx].ptData;
64 switch(set[idx].ptCount) { 158 switch(set[idx].ptCount) {
65 case 2: { 159 case 2: {
66 seg->addLine(*data, false, false); 160 seg->addLine(*data, false, false);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const SortSetTests& test = tests[index]; 209 const SortSetTests& test = tests[index];
116 for (size_t idxL = 0; idxL < test.count - 1; ++idxL) { 210 for (size_t idxL = 0; idxL < test.count - 1; ++idxL) {
117 SkOpSegment lesser, greater; 211 SkOpSegment lesser, greater;
118 int lesserTs[2], greaterTs[2]; 212 int lesserTs[2], greaterTs[2];
119 const SkPoint* lesserData, * greaterData; 213 const SkPoint* lesserData, * greaterData;
120 const SortSet* set = test.set; 214 const SortSet* set = test.set;
121 setup(set, idxL, &lesserData, &lesser, lesserTs); 215 setup(set, idxL, &lesserData, &lesser, lesserTs);
122 size_t idxG = idxL + 1; 216 size_t idxG = idxL + 1;
123 setup(set, idxG, &greaterData, &greater, greaterTs); 217 setup(set, idxG, &greaterData, &greater, greaterTs);
124 SkOpAngle first, second; 218 SkOpAngle first, second;
125 first.set(lesserData, (SkPath::Verb) (set[idxL].ptCount - 1), &lesse r, 219 first.set(lesserData, SkPathOpsPointsToVerb(set[idxL].ptCount - 1), &lesser,
126 lesserTs[0], lesserTs[1], lesser.spans()); 220 lesserTs[0], lesserTs[1], lesser.spans());
127 second.set(greaterData, (SkPath::Verb) (set[idxG].ptCount - 1), &gre ater, 221 second.set(greaterData, SkPathOpsPointsToVerb(set[idxG].ptCount - 1) , &greater,
128 greaterTs[0], greaterTs[1], greater.spans()); 222 greaterTs[0], greaterTs[1], greater.spans());
129 bool compare = first < second; 223 bool compare = first < second;
130 if (!compare) { 224 if (!compare) {
131 SkDebugf("%s test[%d]: lesser[%d] > greater[%d]\n", __FUNCTION_ _, 225 SkDebugf("%s test[%d]: lesser[%d] > greater[%d]\n", __FUNCTION_ _,
132 index, idxL, idxG); 226 index, idxL, idxG);
227 compare = first < second;
133 } 228 }
134 REPORTER_ASSERT(reporter, compare); 229 REPORTER_ASSERT(reporter, compare);
230 reporter->bumpTestCount();
135 } 231 }
136 } 232 }
137 } 233 }
138 234
139 #include "TestClassDef.h" 235 #include "TestClassDef.h"
140 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest) 236 DEFINE_TESTCLASS_SHORT(PathOpsAngleTest)
OLDNEW
« no previous file with comments | « src/utils/SkParsePath.cpp ('k') | tests/PathOpsOpTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698