blob: f326a90cc48ed2dba72da254f4a13cdb11782825 [file] [log] [blame]
caryclark@google.comad65a3e2013-04-15 19:13:59 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
caryclark@google.com8d0a5242013-07-16 16:11:16 +00007#include "PathOpsTestCommon.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +00008#include "SkOpSegment.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +00009#include "SkTArray.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000010#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000011#include "TestClassDef.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000012
13static const SkPoint cubics[][4] = {
reed@google.com277c3f82013-05-31 15:17:50 +000014/* 0 */ {{0, 1}, {2, 6}, {4, 2}, {5, 3}},
15/* 1 */ {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}},
16/* 2 */ {{132, 11419}, {130.89543151855469f, 11419}, {130, 11418.1044921875f}, {130, 11417}},
17/* 3 */ {{130.04275512695312f, 11417.4130859375f}, {130.23307800292969f, 11418.3193359375f},
18 {131.03709411621094f, 11419}, {132, 11419}},
19/* 4 */ {{0,1}, {0,5}, {4,1}, {6,4}},
20/* 5 */ {{1,5}, {4,6}, {1,0}, {4,0}},
21/* 6 */ {{0,1}, {0,4}, {5,1}, {6,4}},
22/* 7 */ {{0,1}, {1,2}, {1,0}, {6,1}},
23/* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}},
24/* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}},
25/* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}},
26/* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}},
27/* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000028/* 13 */ {{0,1}, {4,6}, {4,3}, {5,4}},
caryclark@google.com4b66f362013-06-04 18:14:11 +000029/* 14 */ {{806,11419}, {806.962890625f,11419}, {807.76690673828125f,11418.3193359375f}, {807.957275390625f,11417.4130859375f}},
30/* 15 */ {{808,11417}, {808,11418.1044921875f}, {807.10455322265625f,11419}, {806,11419}},
31/* 16 */ {{132,11419}, {130.89543151855469f,11419}, {130,11418.1044921875f}, {130,11417}},
32/* 17 */ {{130.04275512695312f,11417.4130859375f}, {130.23312377929687f,11418.3193359375f}, {131.03707885742187f,11419}, {132,11419}},
caryclark@google.com07e97fc2013-07-08 17:17:02 +000033/* 18 */ {{1006.6951293945312f,291}, {1023.263671875f,291}, {1033.8402099609375f,304.43145751953125f}, {1030.318359375f,321}},
caryclark@google.coma5e55922013-05-07 18:51:31 +000034};
35
36static const SkPoint quads[][3] = {
reed@google.com277c3f82013-05-31 15:17:50 +000037/* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}},
38/* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f}, {306,596}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000039/* 2 */ {{0,0}, {3,1}, {0,3}},
40/* 3 */ {{0,1}, {3,1}, {0,2}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000041};
42
43static const SkPoint lines[][2] = {
reed@google.com277c3f82013-05-31 15:17:50 +000044/* 0 */ {{6, 2}, {2, 4}},
45/* 1 */ {{306,617}, {306,590}},
46/* 2 */ {{306,596}, {306,617}},
47/* 3 */ {{6,4}, {0,1}},
48/* 4 */ {{6,1}, {0,1}},
49/* 5 */ {{1,0}, {0,3}},
50/* 6 */ {{246,4}, {189,4}},
51/* 7 */ {{192,4}, {243,4}},
52/* 8 */ {{4,3}, {0,1}},
53/* 9 */ {{3,2}, {1,2}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000054/* 10 */ {{6,4}, {3,4}},
caryclark@google.com07e97fc2013-07-08 17:17:02 +000055/* 11 */ {{979.30487060546875f,561}, {1036.695068359375f,291}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000056};
57
58struct SortSet {
59 const SkPoint* ptData;
60 int ptCount;
61 double tStart;
62 double tEnd;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000063 SkPoint endPt;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000064};
65
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +000066/*static const SortSet set1[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000067 {cubics[0], 4, 0.66666987081928919, 0.875, {0, 0}},
68 {lines[0], 2, 0.574070336, 0.388888889, {0, 0}},
69 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307, {0, 0}},
70 {lines[0], 2, 0.574070336, 0.9140625, {0, 0}},
71};
72
73static const SortSet set1a[] = {
74 {cubics[0], 4, 0.666666667, 0.405037112, {4.58007812f,2.83203125f}},
75 {lines[0], 2, 0.574074074, 0.9140625, {4.44444466f,2.77777767f}},
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +000076};*/
caryclark@google.comad65a3e2013-04-15 19:13:59 +000077
78static const SortSet set2[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000079 {cubics[0], 4, 0.666666667, 0.875, {0, 0}},
80 {lines[0], 2, 0.574074074, 0.388888889, {0, 0}},
81 {cubics[0], 4, 0.666666667, 0.405037112, {0, 0}},
82 {lines[0], 2, 0.574074074, 0.9140625, {0, 0}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000083};
84
caryclark@google.coma5e55922013-05-07 18:51:31 +000085static const SortSet set3[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000086 {cubics[1], 4, 0, 1, {0, 0}},
87 {quads[0], 3, 1, 0, {0, 0}},
caryclark@google.coma5e55922013-05-07 18:51:31 +000088};
89
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +000090/*static const SortSet set4[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000091 {cubics[2], 4, 0.812114222, 1, {0, 0}},
92 {cubics[3], 4, 0.0684734759, 0, {0, 0}},
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +000093};*/
reed@google.com277c3f82013-05-31 15:17:50 +000094
95static const SortSet set5[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000096 {lines[1], 2, 0.777777778, 1, {0, 0}},
97 {quads[1], 3, 1, 4.34137342e-06, {0, 0}},
98 {lines[2], 2, 0, 1, {0, 0}},
99};
100
101static const SortSet set5a[] = {
102 {lines[1], 2, 0.777777778, 1, {306,590}},
103 {quads[1], 3, 1, 4.34137342e-06, {304.243195f,591.756775f}},
104 {lines[2], 2, 0, 1, {306,617}},
reed@google.com277c3f82013-05-31 15:17:50 +0000105};
106
107static const SortSet set6[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000108 {lines[3], 2, 0.407407407, 0.554627832, {0, 0}},
109 {cubics[4], 4, 0.666666667, 0.548022446, {0, 0}},
110 {lines[3], 2, 0.407407407, 0, {0, 0}},
111 {cubics[4], 4, 0.666666667, 1, {0, 0}},
112};
113
114static const SortSet set6a[] = {
115 {lines[3], 2, 0.407407407, 0.554627832, {2.6722331f,2.33611655f}},
116 {cubics[4], 4, 0.666666667, 0.548022446, {2.61642241f,2.83718514f}},
117 {lines[3], 2, 0.407407407, 0, {6,4}},
118 {cubics[4], 4, 0.666666667, 1, {6,4}},
reed@google.com277c3f82013-05-31 15:17:50 +0000119};
120
121static const SortSet set7[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000122 {cubics[5], 4, 0.545233342, 0.545454545, {0, 0}},
123 {cubics[6], 4, 0.484938134, 0.484805744, {0, 0}},
124 {cubics[5], 4, 0.545233342, 0, {0, 0}},
125 {cubics[6], 4, 0.484938134, 0.545454545, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000126};
127
128static const SortSet set8[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000129 {cubics[7], 4, 0.5, 0.522986744, {0, 0}},
130 {lines[4], 2, 0.75, 1, {0, 0}},
131 {cubics[7], 4, 0.5, 0, {0, 0}},
132 {lines[4], 2, 0.75, 0.737654321, {0, 0}},
133};
134
135static const SortSet set8a[] = {
136 {cubics[7], 4, 0.5, 0.522986744, {1.60668361f,0.965592742f}},
137 {lines[4], 2, 0.75, 1, {0,1}},
138 {cubics[7], 4, 0.5, 0, {0,1}},
139 {lines[4], 2, 0.75, 0.737654321, {1.57407403f,1}},
reed@google.com277c3f82013-05-31 15:17:50 +0000140};
141
142static const SortSet set9[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000143 {cubics[8], 4, 0.4, 1, {0, 0}},
144 {lines[5], 2, 0.36, 0, {0, 0}},
145 {cubics[8], 4, 0.4, 0.394675838, {0, 0}},
146 {lines[5], 2, 0.36, 0.363999782, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000147};
148
149static const SortSet set10[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000150 {lines[6], 2, 0.947368421, 1, {0, 0}},
151 {cubics[9], 4, 1, 0.500000357, {0, 0}},
152 {lines[7], 2, 0, 1, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000153};
154
155static const SortSet set11[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000156 {lines[3], 2, 0.75, 1, {0, 0}},
157 {cubics[10], 4, 0.5, 0.228744269, {0, 0}},
158 {lines[3], 2, 0.75, 0.627112191, {0, 0}},
159 {cubics[10], 4, 0.5, 0.6339746, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000160};
161
162static const SortSet set12[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000163 {cubics[12], 4, 0.5, 1, {0, 0}},
164 {lines[8], 2, 0.5, 1, {0, 0}},
165 {cubics[11], 4, 0.5, 0, {0, 0}},
166 {lines[9], 2, 0.5, 1, {0, 0}},
167 {cubics[12], 4, 0.5, 0, {0, 0}},
168 {lines[8], 2, 0.5, 0, {0, 0}},
169 {cubics[11], 4, 0.5, 1, {0, 0}},
170 {lines[9], 2, 0.5, 0, {0, 0}},
171};
172
mtklein@google.com6e223af2013-11-22 20:43:54 +0000173/*static const SortSet set13[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000174 {cubics[13], 4, 0.5, 0.400631046, {0, 0}},
175 {lines[10], 2, 0.791666667, 0.928, {0, 0}},
176 {lines[10], 2, 0.791666667, 0.333333333, {0, 0}},
177 {cubics[13], 4, 0.5, 0.866666667, {0, 0}},
mtklein@google.com6e223af2013-11-22 20:43:54 +0000178};*/
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000179
180static const SortSet set14[] = {
181 {quads[2], 3, 0.5, 0.310102051, {0, 0}},
182 {quads[3], 3, 0.5, 0.2, {0, 0}},
183 {quads[3], 3, 0.5, 0.770156212, {0, 0}},
184 {quads[2], 3, 0.5, 0.7, {0, 0}},
185};
186
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +0000187/*static const SortSet set15[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000188 {cubics[14], 4, 0.93081374, 1, {0, 0}},
189 {cubics[15], 4, 0.188518131, 0, {0, 0}},
190 {cubics[14], 4, 0.93081374, 0, {0, 0}},
commit-bot@chromium.org4b7d6732013-10-21 16:41:00 +0000191};*/
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000192
193static const SortSet set16[] = {
194 {cubics[17], 4, 0.0682619216, 0, {130.042755f,11417.4131f}},
195 {cubics[16], 4, 0.812302088, 1, {130,11417}},
196 {cubics[17], 4, 0.0682619216, 1, {132,11419}},
reed@google.com277c3f82013-05-31 15:17:50 +0000197};
198
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000199static const SortSet set17[] = {
200 {lines[11], 2, 0.888889581, 1, {0, 0}},
201 {cubics[18], 4, 0.999996241, 0, {0, 0}},
202 {lines[11], 2, 0.888889581, 0, {0, 0}},
203 {cubics[18], 4, 0.999996241, 1, {0, 0}},
204};
205
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000206struct SortSetTests {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000207 const char* name;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000208 const SortSet* set;
209 size_t count;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000210 SkPoint startPt;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000211};
212
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000213#define TEST_ENTRY(name) #name, name, SK_ARRAY_COUNT(name)
214
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000215static const SortSetTests tests[] = {
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000216 { TEST_ENTRY(set17), {0, 0}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000217 { TEST_ENTRY(set16), {130.090179f,11417.5957f} },
218// { TEST_ENTRY(set15), {0, 0}},
219 { TEST_ENTRY(set14), {0, 0}},
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000220// { TEST_ENTRY(set13), {0, 0}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000221 { TEST_ENTRY(set12), {0, 0}},
222 { TEST_ENTRY(set11), {0, 0}},
223 { TEST_ENTRY(set10), {0, 0}},
224 { TEST_ENTRY(set9), {0, 0}},
225 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} },
226 { TEST_ENTRY(set8a), {1.5f,1} },
227 { TEST_ENTRY(set8), {0, 0}},
228 { TEST_ENTRY(set7), {0, 0}},
229 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} },
230 { TEST_ENTRY(set6), {0, 0}},
231 { TEST_ENTRY(set5a), {306,596} },
232 { TEST_ENTRY(set5), {0, 0}},
233// { TEST_ENTRY(set4), {0, 0}},
234 { TEST_ENTRY(set3), {0, 0}},
235 { TEST_ENTRY(set2), {0, 0}},
236// { TEST_ENTRY(set1a), {3.70370364f,3.14814806f} },
caryclark@google.com570863f2013-09-16 15:55:01 +0000237// { TEST_ENTRY(set1), {0, 0}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000238};
239
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000240#undef TEST_ENTRY
241
242static void setup(const SortSet* set, const size_t idx,
243 SkOpSegment* seg, int* ts, const SkPoint& startPt) {
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000244 SkPoint start, end;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000245 const SkPoint* data = set[idx].ptData;
246 bool useIntersectPt = startPt.fX != 0 || startPt.fY != 0;
247 if (useIntersectPt) {
248 start = startPt;
249 end = set[idx].endPt;
250 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000251 switch(set[idx].ptCount) {
252 case 2: {
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000253 SkASSERT(ValidPoints(data, 2));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000254 seg->addLine(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000255 SkDLine dLine;
256 dLine.set(set[idx].ptData);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000257 SkASSERT(ValidLine(dLine));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000258 if (useIntersectPt) {
259 break;
260 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000261 start = dLine.ptAtT(set[idx].tStart).asSkPoint();
262 end = dLine.ptAtT(set[idx].tEnd).asSkPoint();
caryclark@google.coma5e55922013-05-07 18:51:31 +0000263 } break;
264 case 3: {
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000265 SkASSERT(ValidPoints(data, 3));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000266 seg->addQuad(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000267 SkDQuad dQuad;
268 dQuad.set(set[idx].ptData);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000269 SkASSERT(ValidQuad(dQuad));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000270 if (useIntersectPt) {
271 break;
272 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000273 start = dQuad.ptAtT(set[idx].tStart).asSkPoint();
274 end = dQuad.ptAtT(set[idx].tEnd).asSkPoint();
caryclark@google.coma5e55922013-05-07 18:51:31 +0000275 } break;
276 case 4: {
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000277 SkASSERT(ValidPoints(data, 4));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000278 seg->addCubic(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000279 SkDCubic dCubic;
280 dCubic.set(set[idx].ptData);
caryclark@google.com8d0a5242013-07-16 16:11:16 +0000281 SkASSERT(ValidCubic(dCubic));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000282 if (useIntersectPt) {
283 break;
284 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000285 start = dCubic.ptAtT(set[idx].tStart).asSkPoint();
286 end = dCubic.ptAtT(set[idx].tEnd).asSkPoint();
caryclark@google.coma5e55922013-05-07 18:51:31 +0000287 } break;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000288 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000289 double tStart = set[idx].tStart;
290 double tEnd = set[idx].tEnd;
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000291 seg->addT(NULL, start, tStart);
292 seg->addT(NULL, end, tEnd);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000293 if (tStart != 0 && tEnd != 0) {
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000294 seg->addT(NULL, set[idx].ptData[0], 0);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000295 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000296 if (tStart != 1 && tEnd != 1) {
commit-bot@chromium.org866f4e32013-11-21 17:04:29 +0000297 seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], 1);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000298 }
caryclark@google.comb3f09212013-04-17 15:49:16 +0000299 int tIndex = 0;
caryclark@google.com20d54612013-06-04 18:30:02 +0000300 ts[0] = 0;
301 ts[1] = 1;
caryclark@google.comb3f09212013-04-17 15:49:16 +0000302 do {
303 if (seg->t(tIndex) == set[idx].tStart) {
304 ts[0] = tIndex;
305 }
306 if (seg->t(tIndex) == set[idx].tEnd) {
307 ts[1] = tIndex;
308 }
309 if (seg->t(tIndex) >= 1) {
310 break;
311 }
312 } while (++tIndex);
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000313}
314
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000315static void testOne(skiatest::Reporter* reporter, const SortSetTests& test) {
316 SkTDArray<SkOpAngle> angles;
317 bool unsortable = false;
318 bool unorderable = false;
319 SkTArray<SkOpSegment> segs;
320 for (size_t idx = 0; idx < test.count; ++idx) {
321 int ts[2];
322 const SortSet* set = test.set;
323 SkOpSegment& seg = segs.push_back();
324 setup(set, idx, &seg, ts, test.startPt);
325 SkOpAngle* angle = angles.append();
326 angle->set(&seg, ts[0], ts[1]);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000327#if DEBUG_ANGLE
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000328 angle->setID(idx);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000329#endif
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000330 if (angle->unsortable()) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000331#if DEBUG_ANGLE
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000332 SkDebugf("%s test[%s]: angle[%d] unsortable\n", __FUNCTION__, test.name, idx);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000333#endif
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000334 unsortable = true;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000335 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000336 if (angle->unorderable()) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000337#if DEBUG_ANGLE
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000338 SkDebugf("%s test[%s]: angle[%d] unorderable\n", __FUNCTION__, test.name, idx);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000339#endif
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000340 unorderable = true;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000341 }
342 reporter->bumpTestCount();
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000343 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000344 if (unsortable || unorderable) {
345 return;
346 }
347#if DEBUG_ANGLE
348 SkDebugf("%s test[%s]\n", __FUNCTION__, test.name);
349#endif
350 for (size_t idxL = 0; idxL < test.count; ++idxL) {
351 const SkOpAngle& first = angles[idxL];
352 for (size_t idxG = 0; idxG < test.count; ++idxG) {
353 if (idxL == idxG) {
354 continue;
355 }
356 const SkOpAngle& second = angles[idxG];
357 bool compare = first < second;
358 if (idxL < idxG) {
359 if (!compare) {
360 SkDebugf("%s test[%s]: first[%d] > second[%d]\n", __FUNCTION__,
361 test.name, idxL, idxG);
362 compare = first < second;
363 }
364 REPORTER_ASSERT(reporter, compare);
365 } else {
366 SkASSERT(idxL > idxG);
367 if (compare) {
368 SkDebugf("%s test[%s]: first[%d] < second[%d]\n", __FUNCTION__,
369 test.name, idxL, idxG);
370 compare = first < second;
371 }
372 REPORTER_ASSERT(reporter, !compare);
373 }
374 compare = second < first;
375 if (idxL < idxG) {
376 if (compare) {
377 SkDebugf("%s test[%s]: second[%d] < first[%d]\n", __FUNCTION__,
378 test.name, idxL, idxG);
379 compare = second < first;
380 }
381 REPORTER_ASSERT(reporter, !compare);
382 } else {
383 SkASSERT(idxL > idxG);
384 if (!compare) {
385 SkDebugf("%s test[%s]: second[%d] > first[%d]\n", __FUNCTION__,
386 test.name, idxL, idxG);
387 compare = second < first;
388 }
389 REPORTER_ASSERT(reporter, compare);
390 }
391 }
392 }
393}
394
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000395DEF_TEST(PathOpsAngle, reporter) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000396 for (size_t index = 0; index < SK_ARRAY_COUNT(tests); ++index) {
397 const SortSetTests& test = tests[index];
398 testOne(reporter, test);
399 reporter->bumpTestCount();
400 }
401}
402
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000403DEF_TEST(PathOpsAngleTestOne, reporter) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000404 size_t index = 0;
405 const SortSetTests& test = tests[index];
406 testOne(reporter, test);
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000407}
408
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000409#if 0
410static int find_slop(double x, double y, double rx, double ry) {
411 int slopBits = 0;
412 bool less1, less2;
413 double absX = fabs(x);
414 double absY = fabs(y);
415 double length = absX < absY ? absX / 2 + absY : absX + absY / 2;
416 int exponent;
417 (void) frexp(length, &exponent);
418 double epsilon = ldexp(FLT_EPSILON, exponent);
419 do {
420 // get the length as the larger plus half the smaller (both same signs)
421 // find the ulps of the length
422 // compute the offsets from there
423 double xSlop = epsilon * slopBits;
424 double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ?
425 double x1 = x - xSlop;
426 double y1 = y + ySlop;
427 double x_ry1 = x1 * ry;
428 double rx_y1 = rx * y1;
429 less1 = x_ry1 < rx_y1;
430 double x2 = x + xSlop;
431 double y2 = y - ySlop;
432 double x_ry2 = x2 * ry;
433 double rx_y2 = rx * y2;
434 less2 = x_ry2 < rx_y2;
435 } while (less1 == less2 && ++slopBits);
436 return slopBits;
437}
438
439// from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors
440static double diamond_angle(double y, double x)
441{
442 if (y >= 0)
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000443 return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000444 else
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000445 return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000446}
447
448static const double slopTests[][4] = {
449 // x y rx ry
450 {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438},
451 {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074},
452 {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008},
453};
454
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000455/*DEF_TEST(PathOpsAngleFindSlop, reporter) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000456 for (size_t index = 0; index < SK_ARRAY_COUNT(slopTests); ++index) {
457 const double* slopTest = slopTests[index];
458 double x = slopTest[0];
459 double y = slopTest[1];
460 double rx = slopTest[2];
461 double ry = slopTest[3];
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000462 SkDebugf("%s xy %d=%d\n", __FUNCTION__, (int) index, find_slop(x, y, rx, ry));
463 SkDebugf("%s rxy %d=%d\n", __FUNCTION__, (int) index, find_slop(rx, ry, x, y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000464 double angle = diamond_angle(y, x);
465 double rAngle = diamond_angle(ry, rx);
466 double diff = fabs(angle - rAngle);
467 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__,
468 angle, rAngle, diff, (int) (diff / FLT_EPSILON));
469
470 }
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000471}*/
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000472#endif