blob: fe39d40b9cf1f938e13158b692281ab0782253a8 [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"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +00008#include "SkIntersections.h"
caryclark54359292015-03-26 07:52:43 -07009#include "SkOpContour.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000010#include "SkOpSegment.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000011#include "SkRandom.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000012#include "SkTSort.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000013#include "Test.h"
14
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000015static bool gDisableAngleTests = true;
16
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000017static float next(float f)
18{
19 int fBits = SkFloatAs2sCompliment(f);
20 ++fBits;
21 float fNext = Sk2sComplimentAsFloat(fBits);
22 return fNext;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000023}
24
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000025static float prev(float f)
26{
27 int fBits = SkFloatAs2sCompliment(f);
28 --fBits;
29 float fNext = Sk2sComplimentAsFloat(fBits);
30 return fNext;
31}
32
33DEF_TEST(PathOpsAngleFindCrossEpsilon, reporter) {
34 if (gDisableAngleTests) {
caryclark@google.com07e97fc2013-07-08 17:17:02 +000035 return;
36 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000037 SkRandom ran;
38 int maxEpsilon = 0;
39 for (int index = 0; index < 10000000; ++index) {
40 SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
41 for (int inner = 0; inner < 10; ++inner) {
42 float t = ran.nextRangeF(0.0001f, 1);
43 SkDPoint dPt = line.ptAtT(t);
44 SkPoint pt = dPt.asSkPoint();
45 float xs[3] = { prev(pt.fX), pt.fX, next(pt.fX) };
46 float ys[3] = { prev(pt.fY), pt.fY, next(pt.fY) };
47 for (int xIdx = 0; xIdx < 3; ++xIdx) {
48 for (int yIdx = 0; yIdx < 3; ++yIdx) {
49 SkPoint test = { xs[xIdx], ys[yIdx] };
50 float p1 = SkDoubleToScalar(line[1].fX * test.fY);
51 float p2 = SkDoubleToScalar(line[1].fY * test.fX);
52 int p1Bits = SkFloatAs2sCompliment(p1);
53 int p2Bits = SkFloatAs2sCompliment(p2);
bungeman60e0fee2015-08-26 05:15:46 -070054 int epsilon = SkTAbs(p1Bits - p2Bits);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000055 if (maxEpsilon < epsilon) {
56 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g pt={%1.7g, %1.7g}"
57 " epsilon=%d\n",
58 line[1].fX, line[1].fY, t, test.fX, test.fY, epsilon);
59 maxEpsilon = epsilon;
60 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +000061 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +000062 }
63 }
64 }
65}
66
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000067DEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) {
68 if (gDisableAngleTests) {
69 return;
70 }
71 SkRandom ran;
72 int maxEpsilon = 0;
73 double maxAngle = 0;
74 for (int index = 0; index < 100000; ++index) {
75 SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
76 float t = ran.nextRangeF(0.0001f, 1);
77 SkDPoint dPt = line.ptAtT(t);
78 float t2 = ran.nextRangeF(0.0001f, 1);
79 SkDPoint qPt = line.ptAtT(t2);
80 float t3 = ran.nextRangeF(0.0001f, 1);
81 SkDPoint qPt2 = line.ptAtT(t3);
82 qPt.fX += qPt2.fY;
83 qPt.fY -= qPt2.fX;
84 SkDQuad quad = {{line[0], dPt, qPt}};
85 // binary search for maximum movement of quad[1] towards test that still has 1 intersection
86 double moveT = 0.5f;
87 double deltaT = moveT / 2;
88 SkDPoint last;
89 do {
90 last = quad[1];
91 quad[1].fX = dPt.fX - line[1].fY * moveT;
92 quad[1].fY = dPt.fY + line[1].fX * moveT;
93 SkIntersections i;
94 i.intersect(quad, line);
95 REPORTER_ASSERT(reporter, i.used() > 0);
96 if (i.used() == 1) {
97 moveT += deltaT;
98 } else {
99 moveT -= deltaT;
100 }
101 deltaT /= 2;
102 } while (last.asSkPoint() != quad[1].asSkPoint());
103 float p1 = SkDoubleToScalar(line[1].fX * last.fY);
104 float p2 = SkDoubleToScalar(line[1].fY * last.fX);
105 int p1Bits = SkFloatAs2sCompliment(p1);
106 int p2Bits = SkFloatAs2sCompliment(p2);
bungeman60e0fee2015-08-26 05:15:46 -0700107 int epsilon = SkTAbs(p1Bits - p2Bits);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000108 if (maxEpsilon < epsilon) {
109 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
110 " pt={%1.7g, %1.7g} epsilon=%d\n",
111 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon);
112 maxEpsilon = epsilon;
113 }
114 double a1 = atan2(line[1].fY, line[1].fX);
115 double a2 = atan2(last.fY, last.fX);
116 double angle = fabs(a1 - a2);
117 if (maxAngle < angle) {
118 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
119 " pt={%1.7g, %1.7g} angle=%1.7g\n",
120 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle);
121 maxAngle = angle;
122 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000123 }
124}
125
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000126static int find_slop(double x, double y, double rx, double ry) {
127 int slopBits = 0;
128 bool less1, less2;
129 double absX = fabs(x);
130 double absY = fabs(y);
131 double length = absX < absY ? absX / 2 + absY : absX + absY / 2;
132 int exponent;
133 (void) frexp(length, &exponent);
134 double epsilon = ldexp(FLT_EPSILON, exponent);
135 do {
136 // get the length as the larger plus half the smaller (both same signs)
137 // find the ulps of the length
138 // compute the offsets from there
139 double xSlop = epsilon * slopBits;
140 double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ?
141 double x1 = x - xSlop;
142 double y1 = y + ySlop;
143 double x_ry1 = x1 * ry;
144 double rx_y1 = rx * y1;
145 less1 = x_ry1 < rx_y1;
146 double x2 = x + xSlop;
147 double y2 = y - ySlop;
148 double x_ry2 = x2 * ry;
149 double rx_y2 = rx * y2;
150 less2 = x_ry2 < rx_y2;
151 } while (less1 == less2 && ++slopBits);
152 return slopBits;
153}
154
155// from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors
156static double diamond_angle(double y, double x)
157{
158 if (y >= 0)
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000159 return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000160 else
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000161 return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000162}
163
164static const double slopTests[][4] = {
165 // x y rx ry
166 {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438},
167 {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074},
168 {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008},
169};
170
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000171DEF_TEST(PathOpsAngleFindSlop, reporter) {
172 if (gDisableAngleTests) {
173 return;
174 }
175 for (int index = 0; index < (int) SK_ARRAY_COUNT(slopTests); ++index) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000176 const double* slopTest = slopTests[index];
177 double x = slopTest[0];
178 double y = slopTest[1];
179 double rx = slopTest[2];
180 double ry = slopTest[3];
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000181 SkDebugf("%s xy %d=%d\n", __FUNCTION__, index, find_slop(x, y, rx, ry));
182 SkDebugf("%s rxy %d=%d\n", __FUNCTION__, index, find_slop(rx, ry, x, y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000183 double angle = diamond_angle(y, x);
184 double rAngle = diamond_angle(ry, rx);
185 double diff = fabs(angle - rAngle);
186 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__,
187 angle, rAngle, diff, (int) (diff / FLT_EPSILON));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000188 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000189}
190
191class PathOpsAngleTester {
192public:
caryclark54359292015-03-26 07:52:43 -0700193 static int After(SkOpAngle& lh, SkOpAngle& rh) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000194 return lh.after(&rh);
195 }
196
caryclark55888e42016-07-18 10:01:36 -0700197 static int AllOnOneSide(SkOpAngle& lh, SkOpAngle& rh) {
198 return lh.allOnOneSide(&rh);
199 }
200
caryclark54359292015-03-26 07:52:43 -0700201 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) {
202 return lh.convexHullOverlaps(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000203 }
204
caryclark54359292015-03-26 07:52:43 -0700205 static int Orderable(SkOpAngle& lh, SkOpAngle& rh) {
206 return lh.orderable(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000207 }
208
caryclark54359292015-03-26 07:52:43 -0700209 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) {
210 return lh.endsIntersect(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000211 }
212
213 static void SetNext(SkOpAngle& lh, SkOpAngle& rh) {
214 lh.fNext = &rh;
215 }
216};
217
218class PathOpsSegmentTester {
219public:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000220 static void DebugReset(SkOpSegment* segment) {
221 segment->debugReset();
222 }
223};
224
225struct CircleData {
226 const SkDCubic fPts;
227 const int fPtCount;
228 SkPoint fShortPts[4];
229};
230
231static CircleData circleDataSet[] = {
232 { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} },
233 { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394},
234 {320.05078125, 227.58743286132812}}}, 3, {} },
235};
236
237static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
238
239DEF_TEST(PathOpsAngleCircle, reporter) {
caryclark54359292015-03-26 07:52:43 -0700240 SkChunkAlloc allocator(4096);
caryclark624637c2015-05-11 07:21:27 -0700241 SkOpContourHead contour;
caryclark55888e42016-07-18 10:01:36 -0700242 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
caryclark54359292015-03-26 07:52:43 -0700243 contour.init(&state, false, false);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000244 for (int index = 0; index < circleDataSetSize; ++index) {
245 CircleData& data = circleDataSet[index];
246 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
247 data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint();
248 }
249 switch (data.fPtCount) {
250 case 2:
caryclark55888e42016-07-18 10:01:36 -0700251 contour.addLine(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000252 break;
253 case 3:
caryclark55888e42016-07-18 10:01:36 -0700254 contour.addQuad(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000255 break;
256 case 4:
caryclark55888e42016-07-18 10:01:36 -0700257 contour.addCubic(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000258 break;
259 }
260 }
caryclark54359292015-03-26 07:52:43 -0700261 SkOpSegment* first = contour.first();
caryclark55888e42016-07-18 10:01:36 -0700262 first->debugAddAngle(0, 1);
caryclark54359292015-03-26 07:52:43 -0700263 SkOpSegment* next = first->next();
caryclark55888e42016-07-18 10:01:36 -0700264 next->debugAddAngle(0, 1);
caryclark54359292015-03-26 07:52:43 -0700265 PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngle());
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000266}
267
268struct IntersectData {
269 const SkDCubic fPts;
270 const int fPtCount;
271 double fTStart;
272 double fTEnd;
273 SkPoint fShortPts[4];
274};
275
276static IntersectData intersectDataSet1[] = {
277 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
278 0.865309956, 0.154740299, {} },
279 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
280 0.345028807, 0.0786326511, {} },
281 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
282 0.865309956, 1, {} },
283 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
284 0.345028807, 1, {} },
285};
286
287static IntersectData intersectDataSet2[] = {
288 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
289 0.578520747, 1, {} },
290 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
291 0.578520747, 0.536512973, {} },
292 { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3,
293 0.490456543, 1, {} },
294};
295
296static IntersectData intersectDataSet3[] = {
297 { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
298 { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} },
299 { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
300};
301
302static IntersectData intersectDataSet4[] = {
303 { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} },
304 { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} },
305 { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} },
306};
307
308static IntersectData intersectDataSet5[] = {
309 { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} },
310 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} },
311 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} },
312};
313
314static IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658
315 { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616
316 { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616
317 { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0.417096368, {} }, // pathops_visualizer.htm:3616
318};
319
320static IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748
321 { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706
322 { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706
323 { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706
324}; //
325
326static IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194
327 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.311007457, 0.285714286, {} }, // pathops_visualizer.htm:4152
328 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.999982974, {} }, // pathops_visualizer.htm:4152
329 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.589885081, 0.576935809, {} }, // pathops_visualizer.htm:4152
330}; //
331
332static IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142
333 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 0.311007457, {} }, // pathops_visualizer.htm:4100
334 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100
335 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100
336}; //
337
338static IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186
339 { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 0.726275769, {} }, // pathops_visualizer.htm:4144
340 { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144
341 { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144
342}; //
343
344static IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704
345 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662
346 { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662
347 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662
348}; //
349
350static IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481
351 { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439
352 { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439
353 { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439
354}; //
355
356static IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735
357 { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // pathops_visualizer.htm:5693
358 { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.833333333, {} }, // pathops_visualizer.htm:5693
359 { {{{0.000,1.000}, {0.000,6.000}, {4.000,0.000}, {6.000,1.000}}}, 4, 0.5, 0.379043969, {} }, // pathops_visualizer.htm:5693
360}; //
361
362static IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875
363 { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.0594570973, {} }, // pathops_visualizer.htm:5833
364 { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833
365 { {{{0.000,1.000}, {4.000,6.000}, {2.000,1.000}, {2.000,0.000}}}, 4, 0.0756502183, 0.531917258, {} }, // pathops_visualizer.htm:5833
366}; //
367
368static IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580
369 { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538
370 { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538
371 { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 0.500000273, {} }, // pathops_visualizer.htm:6538
skia.committer@gmail.coma1ed7ae2014-04-15 03:04:18 +0000372}; //
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000373
374static IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419
375 { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377
376 { {{{2.000,3.000}, {3.000,6.000}, {4.000,1.000}, {5.000,4.000}}}, 4, 0.5, 0.112701665, {} }, // pathops_visualizer.htm:7377
377 { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377
378}; //
379
caryclark54359292015-03-26 07:52:43 -0700380// from skpi_gino_com_16
381static IntersectData intersectDataSet17[] = {
382 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
383 , 3, 0.74590454, 0.547660352, {} },
384 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
385 , 4, 0.12052623, 0, {} },
386 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
387 , 3, 0.74590454, 1, {} },
388};
389
390static IntersectData intersectDataSet18[] = {
391 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
392 , 3, 0.74590454, 1, {} },
393 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
394 , 4, 0.12052623, 0.217351928, {} },
395 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
396 , 3, 0.74590454, 0.547660352, {} },
397};
398
399static IntersectData intersectDataSet19[] = {
400 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
401 , 4, 0.135148995, 0.134791946, {} },
402 { /*seg=3*/ {{{1, 2}, {1, 2.15061641f}, {1, 2.21049166f}, {1.01366711f, 2.21379328f}}}
403 , 4, 0.956740456, 0.894913214, {} },
404 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
405 , 4, 0.135148995, 0.551812363, {} },
406};
407
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000408#define I(x) intersectDataSet##x
409
410static IntersectData* intersectDataSets[] = {
411 I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
caryclark54359292015-03-26 07:52:43 -0700412 I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19),
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000413};
414
415#undef I
416#define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x)
417
418static const int intersectDataSetSizes[] = {
419 I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
caryclark54359292015-03-26 07:52:43 -0700420 I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19),
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000421};
422
423#undef I
424
425static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes);
426
caryclark54359292015-03-26 07:52:43 -0700427struct FourPoints {
428 SkPoint pts[4];
429};
430
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000431DEF_TEST(PathOpsAngleAfter, reporter) {
caryclark54359292015-03-26 07:52:43 -0700432 SkChunkAlloc allocator(4096);
caryclark624637c2015-05-11 07:21:27 -0700433 SkOpContourHead contour;
caryclark55888e42016-07-18 10:01:36 -0700434 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
caryclark54359292015-03-26 07:52:43 -0700435 contour.init(&state, false, false);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000436 for (int index = intersectDataSetsSize - 1; index >= 0; --index) {
437 IntersectData* dataArray = intersectDataSets[index];
438 const int dataSize = intersectDataSetSizes[index];
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000439 for (int index2 = 0; index2 < dataSize - 2; ++index2) {
caryclark54359292015-03-26 07:52:43 -0700440 allocator.reset();
441 contour.reset();
442 for (int index3 = 0; index3 < 3; ++index3) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000443 IntersectData& data = dataArray[index2 + index3];
caryclark54359292015-03-26 07:52:43 -0700444 SkPoint* temp = (SkPoint*) SkOpTAllocator<FourPoints>::Allocate(&allocator);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000445 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
446 temp[idx2] = data.fPts.fPts[idx2].asSkPoint();
447 }
448 switch (data.fPtCount) {
449 case 2: {
caryclark55888e42016-07-18 10:01:36 -0700450 contour.addLine(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000451 } break;
452 case 3: {
caryclark55888e42016-07-18 10:01:36 -0700453 contour.addQuad(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000454 } break;
455 case 4: {
caryclark55888e42016-07-18 10:01:36 -0700456 contour.addCubic(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000457 } break;
458 }
459 }
caryclark54359292015-03-26 07:52:43 -0700460 SkOpSegment* seg1 = contour.first();
caryclark55888e42016-07-18 10:01:36 -0700461 seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2 + 0].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700462 SkOpSegment* seg2 = seg1->next();
caryclark55888e42016-07-18 10:01:36 -0700463 seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2 + 1].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700464 SkOpSegment* seg3 = seg2->next();
caryclark55888e42016-07-18 10:01:36 -0700465 seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2 + 2].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700466 SkOpAngle& angle1 = *seg1->debugLastAngle();
467 SkOpAngle& angle2 = *seg2->debugLastAngle();
468 SkOpAngle& angle3 = *seg3->debugLastAngle();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000469 PathOpsAngleTester::SetNext(angle1, angle3);
470 // These data sets are seeded when the set itself fails, so likely the dataset does not
471 // match the expected result. The tests above return 1 when first added, but
472 // return 0 after the bug is fixed.
473 SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1);
474 SkASSERT(result == 0 || result == 1);
475 }
476 }
477}
478
caryclark55888e42016-07-18 10:01:36 -0700479void SkOpSegment::debugAddAngle(double startT, double endT) {
caryclark54359292015-03-26 07:52:43 -0700480 SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT()
caryclark29b25632016-08-25 11:27:17 -0700481 : this->addT(startT);
caryclark54359292015-03-26 07:52:43 -0700482 SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT()
caryclark29b25632016-08-25 11:27:17 -0700483 : this->addT(endT);
caryclark55888e42016-07-18 10:01:36 -0700484 SkOpAngle* angle = SkOpTAllocator<SkOpAngle>::Allocate(this->globalState()->allocator());
caryclark54359292015-03-26 07:52:43 -0700485 SkOpSpanBase* startSpan = &fHead;
486 while (startSpan->ptT() != startPtT) {
487 startSpan = startSpan->upCast()->next();
488 }
489 SkOpSpanBase* endSpan = &fHead;
490 while (endSpan->ptT() != endPtT) {
491 endSpan = endSpan->upCast()->next();
492 }
493 angle->set(startSpan, endSpan);
494 if (startT < endT) {
495 startSpan->upCast()->setToAngle(angle);
496 endSpan->setFromAngle(angle);
497 } else {
498 endSpan->upCast()->setToAngle(angle);
499 startSpan->setFromAngle(angle);
500 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000501}
caryclark55888e42016-07-18 10:01:36 -0700502
503DEF_TEST(PathOpsAngleAllOnOneSide, reporter) {
504 SkChunkAlloc allocator(4096);
505 SkOpContourHead contour;
506 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
507 contour.init(&state, false, false);
508 SkPoint conicPts[3] = {{494.37100219726562f, 224.66200256347656f},
509 {494.37360910682298f, 224.6729026561527f},
510 {494.37600708007813f, 224.68400573730469f}};
511 SkPoint linePts[2] = {{494.371002f, 224.662003f}, {494.375000f, 224.675995f}};
512 for (int i = 10; i >= 0; --i) {
513 SkPoint modLinePts[2] = { linePts[0], linePts[1] };
514 modLinePts[1].fX += i * .1f;
515 contour.addLine(modLinePts);
516 contour.addQuad(conicPts);
517 // contour.addConic(conicPts, 0.999935746f, &allocator);
518 SkOpSegment* first = contour.first();
519 first->debugAddAngle(0, 1);
520 SkOpSegment* next = first->next();
521 next->debugAddAngle(0, 1);
522 /* int result = */
523 PathOpsAngleTester::AllOnOneSide(*first->debugLastAngle(), *next->debugLastAngle());
524 // SkDebugf("i=%d result=%d\n", i , result);
525 // SkDebugf("");
526 }
527}