OLD | NEW |
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 "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
8 #include "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 #include "SkOpSegment.h" | 9 #include "SkOpSegment.h" |
10 #include "SkPathOpsTriangle.h" | 10 #include "SkPathOpsTriangle.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkTArray.h" | 12 #include "SkTArray.h" |
13 #include "SkTSort.h" | 13 #include "SkTSort.h" |
14 #include "Test.h" | 14 #include "Test.h" |
15 | 15 |
16 static bool gDisableAngleTests = true; | 16 static bool gDisableAngleTests = true; |
17 | 17 |
18 static const SkPoint cubics[][4] = { | |
19 /* 0 */ {{0, 1}, {2, 6}, {4, 2}, {5, 3}}, | |
20 /* 1 */ {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}}, | |
21 /* 2 */ {{132, 11419}, {130.89543151855469f, 11419}, {130, 11418.1044921875f}
, {130, 11417}}, | |
22 /* 3 */ {{130.04275512695312f, 11417.4130859375f}, {130.23307800292969f, 1141
8.3193359375f}, | |
23 {131.03709411621094f, 11419}, {132, 11419}}, | |
24 /* 4 */ {{0,1}, {0,5}, {4,1}, {6,4}}, | |
25 /* 5 */ {{1,5}, {4,6}, {1,0}, {4,0}}, | |
26 /* 6 */ {{0,1}, {0,4}, {5,1}, {6,4}}, | |
27 /* 7 */ {{0,1}, {1,2}, {1,0}, {6,1}}, | |
28 /* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}}, | |
29 /* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}}
, | |
30 /* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}}, | |
31 /* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}}, | |
32 /* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}}, | |
33 /* 13 */ {{0,1}, {4,6}, {4,3}, {5,4}}, | |
34 /* 14 */ {{806,11419}, {806.962890625f,11419}, {807.76690673828125f,11418.3193
359375f}, {807.957275390625f,11417.4130859375f}}, | |
35 /* 15 */ {{808,11417}, {808,11418.1044921875f}, {807.10455322265625f,11419}, {
806,11419}}, | |
36 /* 16 */ {{132,11419}, {130.89543151855469f,11419}, {130,11418.1044921875f}, {
130,11417}}, | |
37 /* 17 */ {{130.04275512695312f,11417.4130859375f}, {130.23312377929687f,11418.
3193359375f}, {131.03707885742187f,11419}, {132,11419}}, | |
38 /* 18 */ {{1006.6951293945312f,291}, {1023.263671875f,291}, {1033.840209960937
5f,304.43145751953125f}, {1030.318359375f,321}}, | |
39 }; | |
40 | |
41 static const SkPoint quads[][3] = { | |
42 /* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, | |
43 /* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f}
, {306,596}}, | |
44 /* 2 */ {{0,0}, {3,1}, {0,3}}, | |
45 /* 3 */ {{0,1}, {3,1}, {0,2}}, | |
46 }; | |
47 | |
48 static const SkPoint lines[][2] = { | |
49 /* 0 */ {{6, 2}, {2, 4}}, | |
50 /* 1 */ {{306,617}, {306,590}}, | |
51 /* 2 */ {{306,596}, {306,617}}, | |
52 /* 3 */ {{6,4}, {0,1}}, | |
53 /* 4 */ {{6,1}, {0,1}}, | |
54 /* 5 */ {{1,0}, {0,3}}, | |
55 /* 6 */ {{246,4}, {189,4}}, | |
56 /* 7 */ {{192,4}, {243,4}}, | |
57 /* 8 */ {{4,3}, {0,1}}, | |
58 /* 9 */ {{3,2}, {1,2}}, | |
59 /* 10 */ {{6,4}, {3,4}}, | |
60 /* 11 */ {{979.30487060546875f,561}, {1036.695068359375f,291}}, | |
61 }; | |
62 | |
63 struct SortSet { | |
64 const SkPoint* ptData; | |
65 int ptCount; | |
66 double tStart; | |
67 double tEnd; | |
68 SkPoint endPt; | |
69 }; | |
70 | |
71 /*static const SortSet set1[] = { | |
72 {cubics[0], 4, 0.66666987081928919, 0.875, {0, 0}}, | |
73 {lines[0], 2, 0.574070336, 0.388888889, {0, 0}}, | |
74 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307, {0, 0}}, | |
75 {lines[0], 2, 0.574070336, 0.9140625, {0, 0}}, | |
76 }; | |
77 | |
78 static const SortSet set1a[] = { | |
79 {cubics[0], 4, 0.666666667, 0.405037112, {4.58007812f,2.83203125f}}, | |
80 {lines[0], 2, 0.574074074, 0.9140625, {4.44444466f,2.77777767f}}, | |
81 };*/ | |
82 | |
83 static const SortSet set2[] = { | |
84 {cubics[0], 4, 0.666666667, 0.875, {0, 0}}, | |
85 {lines[0], 2, 0.574074074, 0.388888889, {0, 0}}, | |
86 {cubics[0], 4, 0.666666667, 0.405037112, {0, 0}}, | |
87 {lines[0], 2, 0.574074074, 0.9140625, {0, 0}}, | |
88 }; | |
89 | |
90 static const SortSet set3[] = { | |
91 {cubics[1], 4, 0, 1, {0, 0}}, | |
92 {quads[0], 3, 1, 0, {0, 0}}, | |
93 }; | |
94 | |
95 /*static const SortSet set4[] = { | |
96 {cubics[2], 4, 0.812114222, 1, {0, 0}}, | |
97 {cubics[3], 4, 0.0684734759, 0, {0, 0}}, | |
98 };*/ | |
99 | |
100 static const SortSet set5[] = { | |
101 {lines[1], 2, 0.777777778, 1, {0, 0}}, | |
102 {quads[1], 3, 1, 4.34137342e-06, {0, 0}}, | |
103 {lines[2], 2, 0, 1, {0, 0}}, | |
104 }; | |
105 | |
106 static const SortSet set5a[] = { | |
107 {lines[1], 2, 0.777777778, 1, {306,590}}, | |
108 {quads[1], 3, 1, 4.34137342e-06, {304.243195f,591.756775f}}, | |
109 {lines[2], 2, 0, 1, {306,617}}, | |
110 }; | |
111 | |
112 static const SortSet set6[] = { | |
113 {lines[3], 2, 0.407407407, 0.554627832, {0, 0}}, | |
114 {cubics[4], 4, 0.666666667, 0.548022446, {0, 0}}, | |
115 {lines[3], 2, 0.407407407, 0, {0, 0}}, | |
116 {cubics[4], 4, 0.666666667, 1, {0, 0}}, | |
117 }; | |
118 | |
119 static const SortSet set6a[] = { | |
120 {lines[3], 2, 0.407407407, 0.554627832, {2.6722331f,2.33611655f}}, | |
121 {cubics[4], 4, 0.666666667, 0.548022446, {2.61642241f,2.83718514f}}, | |
122 {lines[3], 2, 0.407407407, 0, {6,4}}, | |
123 {cubics[4], 4, 0.666666667, 1, {6,4}}, | |
124 }; | |
125 | |
126 static const SortSet set7[] = { | |
127 {cubics[5], 4, 0.545233342, 0.545454545, {0, 0}}, | |
128 {cubics[6], 4, 0.484938134, 0.484805744, {0, 0}}, | |
129 {cubics[5], 4, 0.545233342, 0, {0, 0}}, | |
130 {cubics[6], 4, 0.484938134, 0.545454545, {0, 0}}, | |
131 }; | |
132 | |
133 static const SortSet set8[] = { | |
134 {cubics[7], 4, 0.5, 0.522986744, {0, 0}}, | |
135 {lines[4], 2, 0.75, 1, {0, 0}}, | |
136 {cubics[7], 4, 0.5, 0, {0, 0}}, | |
137 {lines[4], 2, 0.75, 0.737654321, {0, 0}}, | |
138 }; | |
139 | |
140 static const SortSet set8a[] = { | |
141 {cubics[7], 4, 0.5, 0.522986744, {1.60668361f,0.965592742f}}, | |
142 {lines[4], 2, 0.75, 1, {0,1}}, | |
143 {cubics[7], 4, 0.5, 0, {0,1}}, | |
144 {lines[4], 2, 0.75, 0.737654321, {1.57407403f,1}}, | |
145 }; | |
146 | |
147 static const SortSet set9[] = { | |
148 {cubics[8], 4, 0.4, 1, {0, 0}}, | |
149 {lines[5], 2, 0.36, 0, {0, 0}}, | |
150 {cubics[8], 4, 0.4, 0.394675838, {0, 0}}, | |
151 {lines[5], 2, 0.36, 0.363999782, {0, 0}}, | |
152 }; | |
153 | |
154 static const SortSet set10[] = { | |
155 {lines[6], 2, 0.947368421, 1, {0, 0}}, | |
156 {cubics[9], 4, 1, 0.500000357, {0, 0}}, | |
157 {lines[7], 2, 0, 1, {0, 0}}, | |
158 }; | |
159 | |
160 static const SortSet set11[] = { | |
161 {lines[3], 2, 0.75, 1, {0, 0}}, | |
162 {cubics[10], 4, 0.5, 0.228744269, {0, 0}}, | |
163 {lines[3], 2, 0.75, 0.627112191, {0, 0}}, | |
164 {cubics[10], 4, 0.5, 0.6339746, {0, 0}}, | |
165 }; | |
166 | |
167 static const SortSet set12[] = { | |
168 {cubics[12], 4, 0.5, 1, {0, 0}}, | |
169 {lines[8], 2, 0.5, 1, {0, 0}}, | |
170 {cubics[11], 4, 0.5, 0, {0, 0}}, | |
171 {lines[9], 2, 0.5, 1, {0, 0}}, | |
172 {cubics[12], 4, 0.5, 0, {0, 0}}, | |
173 {lines[8], 2, 0.5, 0, {0, 0}}, | |
174 {cubics[11], 4, 0.5, 1, {0, 0}}, | |
175 {lines[9], 2, 0.5, 0, {0, 0}}, | |
176 }; | |
177 | |
178 /*static const SortSet set13[] = { | |
179 {cubics[13], 4, 0.5, 0.400631046, {0, 0}}, | |
180 {lines[10], 2, 0.791666667, 0.928, {0, 0}}, | |
181 {lines[10], 2, 0.791666667, 0.333333333, {0, 0}}, | |
182 {cubics[13], 4, 0.5, 0.866666667, {0, 0}}, | |
183 };*/ | |
184 | |
185 static const SortSet set14[] = { | |
186 {quads[2], 3, 0.5, 0.310102051, {0, 0}}, | |
187 {quads[3], 3, 0.5, 0.2, {0, 0}}, | |
188 {quads[3], 3, 0.5, 0.770156212, {0, 0}}, | |
189 {quads[2], 3, 0.5, 0.7, {0, 0}}, | |
190 }; | |
191 | |
192 /*static const SortSet set15[] = { | |
193 {cubics[14], 4, 0.93081374, 1, {0, 0}}, | |
194 {cubics[15], 4, 0.188518131, 0, {0, 0}}, | |
195 {cubics[14], 4, 0.93081374, 0, {0, 0}}, | |
196 };*/ | |
197 | |
198 static const SortSet set16[] = { | |
199 {cubics[17], 4, 0.0682619216, 0, {130.042755f,11417.4131f}}, | |
200 {cubics[16], 4, 0.812302088, 1, {130,11417}}, | |
201 {cubics[17], 4, 0.0682619216, 1, {132,11419}}, | |
202 }; | |
203 | |
204 static const SortSet set17[] = { | |
205 {lines[11], 2, 0.888889581, 1, {0, 0}}, | |
206 {cubics[18], 4, 0.999996241, 0, {0, 0}}, | |
207 {lines[11], 2, 0.888889581, 0, {0, 0}}, | |
208 {cubics[18], 4, 0.999996241, 1, {0, 0}}, | |
209 }; | |
210 | |
211 struct SortSetTests { | |
212 const char* name; | |
213 const SortSet* set; | |
214 size_t count; | |
215 SkPoint startPt; | |
216 }; | |
217 | |
218 #define TEST_ENTRY(name) #name, name, SK_ARRAY_COUNT(name) | |
219 | |
220 static const SortSetTests tests[] = { | |
221 { TEST_ENTRY(set17), {0, 0}}, | |
222 { TEST_ENTRY(set16), {130.090179f,11417.5957f} }, | |
223 // { TEST_ENTRY(set15), {0, 0}}, | |
224 { TEST_ENTRY(set14), {0, 0}}, | |
225 // { TEST_ENTRY(set13), {0, 0}}, | |
226 { TEST_ENTRY(set12), {0, 0}}, | |
227 { TEST_ENTRY(set11), {0, 0}}, | |
228 { TEST_ENTRY(set10), {0, 0}}, | |
229 { TEST_ENTRY(set9), {0, 0}}, | |
230 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} }, | |
231 { TEST_ENTRY(set8a), {1.5f,1} }, | |
232 { TEST_ENTRY(set8), {0, 0}}, | |
233 { TEST_ENTRY(set7), {0, 0}}, | |
234 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} }, | |
235 { TEST_ENTRY(set6), {0, 0}}, | |
236 { TEST_ENTRY(set5a), {306,596} }, | |
237 { TEST_ENTRY(set5), {0, 0}}, | |
238 // { TEST_ENTRY(set4), {0, 0}}, | |
239 { TEST_ENTRY(set3), {0, 0}}, | |
240 { TEST_ENTRY(set2), {0, 0}}, | |
241 // { TEST_ENTRY(set1a), {3.70370364f,3.14814806f} }, | |
242 // { TEST_ENTRY(set1), {0, 0}}, | |
243 }; | |
244 | |
245 #undef TEST_ENTRY | |
246 | |
247 static float next(float f) | 18 static float next(float f) |
248 { | 19 { |
249 int fBits = SkFloatAs2sCompliment(f); | 20 int fBits = SkFloatAs2sCompliment(f); |
250 ++fBits; | 21 ++fBits; |
251 float fNext = Sk2sComplimentAsFloat(fBits); | 22 float fNext = Sk2sComplimentAsFloat(fBits); |
252 return fNext; | 23 return fNext; |
253 } | 24 } |
254 | 25 |
255 static float prev(float f) | 26 static float prev(float f) |
256 { | 27 { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 addT(NULL, shortQuad[1], 1); | 476 addT(NULL, shortQuad[1], 1); |
706 debugConstruct(); | 477 debugConstruct(); |
707 } | 478 } |
708 | 479 |
709 void SkOpSegment::debugConstructQuad(SkPoint shortQuad[3]) { | 480 void SkOpSegment::debugConstructQuad(SkPoint shortQuad[3]) { |
710 addQuad(shortQuad, false, false); | 481 addQuad(shortQuad, false, false); |
711 addT(NULL, shortQuad[0], 0); | 482 addT(NULL, shortQuad[0], 0); |
712 addT(NULL, shortQuad[2], 1); | 483 addT(NULL, shortQuad[2], 1); |
713 debugConstruct(); | 484 debugConstruct(); |
714 } | 485 } |
OLD | NEW |