blob: 1986a506bd7c822606eb29e719dfe8861c69d5c0 [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 */
7#include "SkOpSegment.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +00008#include "SkTArray.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +00009#include "Test.h"
10
11static const SkPoint cubics[][4] = {
reed@google.com277c3f82013-05-31 15:17:50 +000012/* 0 */ {{0, 1}, {2, 6}, {4, 2}, {5, 3}},
13/* 1 */ {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}},
14/* 2 */ {{132, 11419}, {130.89543151855469f, 11419}, {130, 11418.1044921875f}, {130, 11417}},
15/* 3 */ {{130.04275512695312f, 11417.4130859375f}, {130.23307800292969f, 11418.3193359375f},
16 {131.03709411621094f, 11419}, {132, 11419}},
17/* 4 */ {{0,1}, {0,5}, {4,1}, {6,4}},
18/* 5 */ {{1,5}, {4,6}, {1,0}, {4,0}},
19/* 6 */ {{0,1}, {0,4}, {5,1}, {6,4}},
20/* 7 */ {{0,1}, {1,2}, {1,0}, {6,1}},
21/* 8 */ {{0,3}, {0,1}, {2,0}, {1,0}},
22/* 9 */ {{189,7}, {189,5.3431458473205566f}, {190.3431396484375f,4}, {192,4}},
23/* 10 */ {{0,1}, {1,3}, {1,0}, {6,4}},
24/* 11 */ {{0,1}, {2,3}, {2,1}, {4,3}},
25/* 12 */ {{1,2}, {3,4}, {1,0}, {3,2}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000026/* 13 */ {{0,1}, {4,6}, {4,3}, {5,4}},
caryclark@google.com4b66f362013-06-04 18:14:11 +000027/* 14 */ {{806,11419}, {806.962890625f,11419}, {807.76690673828125f,11418.3193359375f}, {807.957275390625f,11417.4130859375f}},
28/* 15 */ {{808,11417}, {808,11418.1044921875f}, {807.10455322265625f,11419}, {806,11419}},
29/* 16 */ {{132,11419}, {130.89543151855469f,11419}, {130,11418.1044921875f}, {130,11417}},
30/* 17 */ {{130.04275512695312f,11417.4130859375f}, {130.23312377929687f,11418.3193359375f}, {131.03707885742187f,11419}, {132,11419}},
caryclark@google.coma5e55922013-05-07 18:51:31 +000031};
32
33static const SkPoint quads[][3] = {
reed@google.com277c3f82013-05-31 15:17:50 +000034/* 0 */ {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}},
35/* 1 */ {{304.24319458007812f,591.75677490234375f}, {306,593.51470947265625f}, {306,596}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000036/* 2 */ {{0,0}, {3,1}, {0,3}},
37/* 3 */ {{0,1}, {3,1}, {0,2}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000038};
39
40static const SkPoint lines[][2] = {
reed@google.com277c3f82013-05-31 15:17:50 +000041/* 0 */ {{6, 2}, {2, 4}},
42/* 1 */ {{306,617}, {306,590}},
43/* 2 */ {{306,596}, {306,617}},
44/* 3 */ {{6,4}, {0,1}},
45/* 4 */ {{6,1}, {0,1}},
46/* 5 */ {{1,0}, {0,3}},
47/* 6 */ {{246,4}, {189,4}},
48/* 7 */ {{192,4}, {243,4}},
49/* 8 */ {{4,3}, {0,1}},
50/* 9 */ {{3,2}, {1,2}},
caryclark@google.comcffbcc32013-06-04 17:59:42 +000051/* 10 */ {{6,4}, {3,4}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000052};
53
54struct SortSet {
55 const SkPoint* ptData;
56 int ptCount;
57 double tStart;
58 double tEnd;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000059 SkPoint endPt;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000060};
61
62static const SortSet set1[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000063 {cubics[0], 4, 0.66666987081928919, 0.875, {0, 0}},
64 {lines[0], 2, 0.574070336, 0.388888889, {0, 0}},
65 {cubics[0], 4, 0.66666987081928919, 0.4050371120499307, {0, 0}},
66 {lines[0], 2, 0.574070336, 0.9140625, {0, 0}},
67};
68
69static const SortSet set1a[] = {
70 {cubics[0], 4, 0.666666667, 0.405037112, {4.58007812f,2.83203125f}},
71 {lines[0], 2, 0.574074074, 0.9140625, {4.44444466f,2.77777767f}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000072};
73
74static const SortSet set2[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000075 {cubics[0], 4, 0.666666667, 0.875, {0, 0}},
76 {lines[0], 2, 0.574074074, 0.388888889, {0, 0}},
77 {cubics[0], 4, 0.666666667, 0.405037112, {0, 0}},
78 {lines[0], 2, 0.574074074, 0.9140625, {0, 0}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +000079};
80
caryclark@google.coma5e55922013-05-07 18:51:31 +000081static const SortSet set3[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000082 {cubics[1], 4, 0, 1, {0, 0}},
83 {quads[0], 3, 1, 0, {0, 0}},
caryclark@google.coma5e55922013-05-07 18:51:31 +000084};
85
reed@google.com277c3f82013-05-31 15:17:50 +000086static const SortSet set4[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000087 {cubics[2], 4, 0.812114222, 1, {0, 0}},
88 {cubics[3], 4, 0.0684734759, 0, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +000089};
90
91static const SortSet set5[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +000092 {lines[1], 2, 0.777777778, 1, {0, 0}},
93 {quads[1], 3, 1, 4.34137342e-06, {0, 0}},
94 {lines[2], 2, 0, 1, {0, 0}},
95};
96
97static const SortSet set5a[] = {
98 {lines[1], 2, 0.777777778, 1, {306,590}},
99 {quads[1], 3, 1, 4.34137342e-06, {304.243195f,591.756775f}},
100 {lines[2], 2, 0, 1, {306,617}},
reed@google.com277c3f82013-05-31 15:17:50 +0000101};
102
103static const SortSet set6[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000104 {lines[3], 2, 0.407407407, 0.554627832, {0, 0}},
105 {cubics[4], 4, 0.666666667, 0.548022446, {0, 0}},
106 {lines[3], 2, 0.407407407, 0, {0, 0}},
107 {cubics[4], 4, 0.666666667, 1, {0, 0}},
108};
109
110static const SortSet set6a[] = {
111 {lines[3], 2, 0.407407407, 0.554627832, {2.6722331f,2.33611655f}},
112 {cubics[4], 4, 0.666666667, 0.548022446, {2.61642241f,2.83718514f}},
113 {lines[3], 2, 0.407407407, 0, {6,4}},
114 {cubics[4], 4, 0.666666667, 1, {6,4}},
reed@google.com277c3f82013-05-31 15:17:50 +0000115};
116
117static const SortSet set7[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000118 {cubics[5], 4, 0.545233342, 0.545454545, {0, 0}},
119 {cubics[6], 4, 0.484938134, 0.484805744, {0, 0}},
120 {cubics[5], 4, 0.545233342, 0, {0, 0}},
121 {cubics[6], 4, 0.484938134, 0.545454545, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000122};
123
124static const SortSet set8[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000125 {cubics[7], 4, 0.5, 0.522986744, {0, 0}},
126 {lines[4], 2, 0.75, 1, {0, 0}},
127 {cubics[7], 4, 0.5, 0, {0, 0}},
128 {lines[4], 2, 0.75, 0.737654321, {0, 0}},
129};
130
131static const SortSet set8a[] = {
132 {cubics[7], 4, 0.5, 0.522986744, {1.60668361f,0.965592742f}},
133 {lines[4], 2, 0.75, 1, {0,1}},
134 {cubics[7], 4, 0.5, 0, {0,1}},
135 {lines[4], 2, 0.75, 0.737654321, {1.57407403f,1}},
reed@google.com277c3f82013-05-31 15:17:50 +0000136};
137
138static const SortSet set9[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000139 {cubics[8], 4, 0.4, 1, {0, 0}},
140 {lines[5], 2, 0.36, 0, {0, 0}},
141 {cubics[8], 4, 0.4, 0.394675838, {0, 0}},
142 {lines[5], 2, 0.36, 0.363999782, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000143};
144
145static const SortSet set10[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000146 {lines[6], 2, 0.947368421, 1, {0, 0}},
147 {cubics[9], 4, 1, 0.500000357, {0, 0}},
148 {lines[7], 2, 0, 1, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000149};
150
151static const SortSet set11[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000152 {lines[3], 2, 0.75, 1, {0, 0}},
153 {cubics[10], 4, 0.5, 0.228744269, {0, 0}},
154 {lines[3], 2, 0.75, 0.627112191, {0, 0}},
155 {cubics[10], 4, 0.5, 0.6339746, {0, 0}},
reed@google.com277c3f82013-05-31 15:17:50 +0000156};
157
158static const SortSet set12[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000159 {cubics[12], 4, 0.5, 1, {0, 0}},
160 {lines[8], 2, 0.5, 1, {0, 0}},
161 {cubics[11], 4, 0.5, 0, {0, 0}},
162 {lines[9], 2, 0.5, 1, {0, 0}},
163 {cubics[12], 4, 0.5, 0, {0, 0}},
164 {lines[8], 2, 0.5, 0, {0, 0}},
165 {cubics[11], 4, 0.5, 1, {0, 0}},
166 {lines[9], 2, 0.5, 0, {0, 0}},
167};
168
169static const SortSet set13[] = {
170 {cubics[13], 4, 0.5, 0.400631046, {0, 0}},
171 {lines[10], 2, 0.791666667, 0.928, {0, 0}},
172 {lines[10], 2, 0.791666667, 0.333333333, {0, 0}},
173 {cubics[13], 4, 0.5, 0.866666667, {0, 0}},
174};
175
176static const SortSet set14[] = {
177 {quads[2], 3, 0.5, 0.310102051, {0, 0}},
178 {quads[3], 3, 0.5, 0.2, {0, 0}},
179 {quads[3], 3, 0.5, 0.770156212, {0, 0}},
180 {quads[2], 3, 0.5, 0.7, {0, 0}},
181};
182
183static const SortSet set15[] = {
184 {cubics[14], 4, 0.93081374, 1, {0, 0}},
185 {cubics[15], 4, 0.188518131, 0, {0, 0}},
186 {cubics[14], 4, 0.93081374, 0, {0, 0}},
187};
188
189static const SortSet set16[] = {
190 {cubics[17], 4, 0.0682619216, 0, {130.042755f,11417.4131f}},
191 {cubics[16], 4, 0.812302088, 1, {130,11417}},
192 {cubics[17], 4, 0.0682619216, 1, {132,11419}},
reed@google.com277c3f82013-05-31 15:17:50 +0000193};
194
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000195struct SortSetTests {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000196 const char* name;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000197 const SortSet* set;
198 size_t count;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000199 SkPoint startPt;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000200};
201
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000202#define TEST_ENTRY(name) #name, name, SK_ARRAY_COUNT(name)
203
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000204static const SortSetTests tests[] = {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000205 { TEST_ENTRY(set16), {130.090179f,11417.5957f} },
206// { TEST_ENTRY(set15), {0, 0}},
207 { TEST_ENTRY(set14), {0, 0}},
208 { TEST_ENTRY(set13), {0, 0}},
209 { TEST_ENTRY(set12), {0, 0}},
210 { TEST_ENTRY(set11), {0, 0}},
211 { TEST_ENTRY(set10), {0, 0}},
212 { TEST_ENTRY(set9), {0, 0}},
213 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} },
214 { TEST_ENTRY(set8a), {1.5f,1} },
215 { TEST_ENTRY(set8), {0, 0}},
216 { TEST_ENTRY(set7), {0, 0}},
217 { TEST_ENTRY(set6a), {3.55555558f,2.77777767f} },
218 { TEST_ENTRY(set6), {0, 0}},
219 { TEST_ENTRY(set5a), {306,596} },
220 { TEST_ENTRY(set5), {0, 0}},
221// { TEST_ENTRY(set4), {0, 0}},
222 { TEST_ENTRY(set3), {0, 0}},
223 { TEST_ENTRY(set2), {0, 0}},
224// { TEST_ENTRY(set1a), {3.70370364f,3.14814806f} },
225 { TEST_ENTRY(set1), {0, 0}},
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000226};
227
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000228#undef TEST_ENTRY
229
230static void setup(const SortSet* set, const size_t idx,
231 SkOpSegment* seg, int* ts, const SkPoint& startPt) {
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000232 SkPoint start, end;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000233 const SkPoint* data = set[idx].ptData;
234 bool useIntersectPt = startPt.fX != 0 || startPt.fY != 0;
235 if (useIntersectPt) {
236 start = startPt;
237 end = set[idx].endPt;
238 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000239 switch(set[idx].ptCount) {
240 case 2: {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000241 seg->addLine(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000242 SkDLine dLine;
243 dLine.set(set[idx].ptData);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000244 if (useIntersectPt) {
245 break;
246 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000247 start = dLine.xyAtT(set[idx].tStart).asSkPoint();
248 end = dLine.xyAtT(set[idx].tEnd).asSkPoint();
249 } break;
250 case 3: {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000251 seg->addQuad(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000252 SkDQuad dQuad;
253 dQuad.set(set[idx].ptData);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000254 if (useIntersectPt) {
255 break;
256 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000257 start = dQuad.xyAtT(set[idx].tStart).asSkPoint();
258 end = dQuad.xyAtT(set[idx].tEnd).asSkPoint();
259 } break;
260 case 4: {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000261 seg->addCubic(data, false, false);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000262 SkDCubic dCubic;
263 dCubic.set(set[idx].ptData);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000264 if (useIntersectPt) {
265 break;
266 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000267 start = dCubic.xyAtT(set[idx].tStart).asSkPoint();
268 end = dCubic.xyAtT(set[idx].tEnd).asSkPoint();
269 } break;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000270 }
caryclark@google.coma5e55922013-05-07 18:51:31 +0000271 double tStart = set[idx].tStart;
272 double tEnd = set[idx].tEnd;
273 seg->addT(NULL, start, tStart);
274 seg->addT(NULL, end, tEnd);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000275 if (tStart != 0 && tEnd != 0) {
276 seg->addT(NULL, set[idx].ptData[0], 0);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000277 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000278 if (tStart != 1 && tEnd != 1) {
279 seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], 1);
caryclark@google.coma5e55922013-05-07 18:51:31 +0000280 }
caryclark@google.comb3f09212013-04-17 15:49:16 +0000281 int tIndex = 0;
caryclark@google.com20d54612013-06-04 18:30:02 +0000282 ts[0] = 0;
283 ts[1] = 1;
caryclark@google.comb3f09212013-04-17 15:49:16 +0000284 do {
285 if (seg->t(tIndex) == set[idx].tStart) {
286 ts[0] = tIndex;
287 }
288 if (seg->t(tIndex) == set[idx].tEnd) {
289 ts[1] = tIndex;
290 }
291 if (seg->t(tIndex) >= 1) {
292 break;
293 }
294 } while (++tIndex);
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000295}
296
297static void PathOpsAngleTest(skiatest::Reporter* reporter) {
298 for (size_t index = 0; index < SK_ARRAY_COUNT(tests); ++index) {
299 const SortSetTests& test = tests[index];
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000300 SkTDArray<SkOpAngle> angles;
301 bool unsortable = false;
302 bool unorderable = false;
303 SkTArray<SkOpSegment> segs;
304 for (size_t idx = 0; idx < test.count; ++idx) {
305 int ts[2];
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000306 const SortSet* set = test.set;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000307 SkOpSegment& seg = segs.push_back();
308 setup(set, idx, &seg, ts, test.startPt);
309 SkOpAngle* angle = angles.append();
310 angle->set(&seg, ts[0], ts[1]);
311#if DEBUG_ANGLE
312 angle->setID(idx);
313#endif
314 if (angle->unsortable()) {
315#if DEBUG_ANGLE
316 SkDebugf("%s test[%s]: angle[%d] unsortable\n", __FUNCTION__, test.name, idx);
317#endif
318 unsortable = true;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000319 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000320 if (angle->unorderable()) {
321#if DEBUG_ANGLE
322 SkDebugf("%s test[%s]: angle[%d] unorderable\n", __FUNCTION__, test.name, idx);
323#endif
324 unorderable = true;
325 }
reed@google.com277c3f82013-05-31 15:17:50 +0000326 reporter->bumpTestCount();
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000327 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000328 if (unsortable || unorderable) {
329 continue;
330 }
331#if DEBUG_ANGLE
332 SkDebugf("%s test[%s]\n", __FUNCTION__, test.name);
333#endif
334 for (size_t idxL = 0; idxL < test.count; ++idxL) {
335 const SkOpAngle& first = angles[idxL];
336 for (size_t idxG = 0; idxG < test.count; ++idxG) {
337 if (idxL == idxG) {
338 continue;
339 }
340 const SkOpAngle& second = angles[idxG];
341 bool compare = first < second;
342 if (idxL < idxG) {
343 if (!compare) {
344 SkDebugf("%s test[%s]: first[%d] > second[%d]\n", __FUNCTION__,
345 test.name, idxL, idxG);
346 compare = first < second;
347 }
348 REPORTER_ASSERT(reporter, compare);
349 } else {
350 SkASSERT(idxL > idxG);
351 if (compare) {
352 SkDebugf("%s test[%s]: first[%d] < second[%d]\n", __FUNCTION__,
353 test.name, idxL, idxG);
354 compare = first < second;
355 }
356 REPORTER_ASSERT(reporter, !compare);
357 }
358 compare = second < first;
359 if (idxL < idxG) {
360 if (compare) {
361 SkDebugf("%s test[%s]: second[%d] < first[%d]\n", __FUNCTION__,
362 test.name, idxL, idxG);
363 compare = second < first;
364 }
365 REPORTER_ASSERT(reporter, !compare);
366 } else {
367 SkASSERT(idxL > idxG);
368 if (!compare) {
369 SkDebugf("%s test[%s]: second[%d] > first[%d]\n", __FUNCTION__,
370 test.name, idxL, idxG);
371 compare = second < first;
372 }
373 REPORTER_ASSERT(reporter, compare);
374 }
375 }
376 }
377 reporter->bumpTestCount();
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000378 }
379}
380
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000381#if 0
382static int find_slop(double x, double y, double rx, double ry) {
383 int slopBits = 0;
384 bool less1, less2;
385 double absX = fabs(x);
386 double absY = fabs(y);
387 double length = absX < absY ? absX / 2 + absY : absX + absY / 2;
388 int exponent;
389 (void) frexp(length, &exponent);
390 double epsilon = ldexp(FLT_EPSILON, exponent);
391 do {
392 // get the length as the larger plus half the smaller (both same signs)
393 // find the ulps of the length
394 // compute the offsets from there
395 double xSlop = epsilon * slopBits;
396 double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ?
397 double x1 = x - xSlop;
398 double y1 = y + ySlop;
399 double x_ry1 = x1 * ry;
400 double rx_y1 = rx * y1;
401 less1 = x_ry1 < rx_y1;
402 double x2 = x + xSlop;
403 double y2 = y - ySlop;
404 double x_ry2 = x2 * ry;
405 double rx_y2 = rx * y2;
406 less2 = x_ry2 < rx_y2;
407 } while (less1 == less2 && ++slopBits);
408 return slopBits;
409}
410
411// from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors
412static double diamond_angle(double y, double x)
413{
414 if (y >= 0)
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000415 return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000416 else
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000417 return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000418}
419
420static const double slopTests[][4] = {
421 // x y rx ry
422 {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438},
423 {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074},
424 {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008},
425};
426
427static void PathOpsAngleFindSlop(skiatest::Reporter* reporter) {
428 for (size_t index = 0; index < SK_ARRAY_COUNT(slopTests); ++index) {
429 const double* slopTest = slopTests[index];
430 double x = slopTest[0];
431 double y = slopTest[1];
432 double rx = slopTest[2];
433 double ry = slopTest[3];
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000434 SkDebugf("%s xy %d=%d\n", __FUNCTION__, (int) index, find_slop(x, y, rx, ry));
435 SkDebugf("%s rxy %d=%d\n", __FUNCTION__, (int) index, find_slop(rx, ry, x, y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000436 double angle = diamond_angle(y, x);
437 double rAngle = diamond_angle(ry, rx);
438 double diff = fabs(angle - rAngle);
439 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__,
440 angle, rAngle, diff, (int) (diff / FLT_EPSILON));
441
442 }
443}
444#endif
445
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000446#include "TestClassDef.h"
447DEFINE_TESTCLASS_SHORT(PathOpsAngleTest)
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000448
449// DEFINE_TESTCLASS_SHORT(PathOpsAngleFindSlop)