blob: cfa8fc0e7bdad14dc70e4502e162ea3fdedd6ec7 [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;
caryclarka35ab3e2016-10-20 08:32:18 -070084 QuadPts q = {{line[0], dPt, qPt}};
85 SkDQuad quad;
86 quad.debugSet(q.fPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000087 // binary search for maximum movement of quad[1] towards test that still has 1 intersection
88 double moveT = 0.5f;
89 double deltaT = moveT / 2;
90 SkDPoint last;
91 do {
92 last = quad[1];
93 quad[1].fX = dPt.fX - line[1].fY * moveT;
94 quad[1].fY = dPt.fY + line[1].fX * moveT;
95 SkIntersections i;
96 i.intersect(quad, line);
97 REPORTER_ASSERT(reporter, i.used() > 0);
98 if (i.used() == 1) {
99 moveT += deltaT;
100 } else {
101 moveT -= deltaT;
102 }
103 deltaT /= 2;
104 } while (last.asSkPoint() != quad[1].asSkPoint());
105 float p1 = SkDoubleToScalar(line[1].fX * last.fY);
106 float p2 = SkDoubleToScalar(line[1].fY * last.fX);
107 int p1Bits = SkFloatAs2sCompliment(p1);
108 int p2Bits = SkFloatAs2sCompliment(p2);
bungeman60e0fee2015-08-26 05:15:46 -0700109 int epsilon = SkTAbs(p1Bits - p2Bits);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000110 if (maxEpsilon < epsilon) {
111 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
112 " pt={%1.7g, %1.7g} epsilon=%d\n",
113 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon);
114 maxEpsilon = epsilon;
115 }
116 double a1 = atan2(line[1].fY, line[1].fX);
117 double a2 = atan2(last.fY, last.fX);
118 double angle = fabs(a1 - a2);
119 if (maxAngle < angle) {
120 SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
121 " pt={%1.7g, %1.7g} angle=%1.7g\n",
122 line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle);
123 maxAngle = angle;
124 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000125 }
126}
127
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000128static int find_slop(double x, double y, double rx, double ry) {
129 int slopBits = 0;
130 bool less1, less2;
131 double absX = fabs(x);
132 double absY = fabs(y);
133 double length = absX < absY ? absX / 2 + absY : absX + absY / 2;
134 int exponent;
135 (void) frexp(length, &exponent);
136 double epsilon = ldexp(FLT_EPSILON, exponent);
137 do {
138 // get the length as the larger plus half the smaller (both same signs)
139 // find the ulps of the length
140 // compute the offsets from there
141 double xSlop = epsilon * slopBits;
142 double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ?
143 double x1 = x - xSlop;
144 double y1 = y + ySlop;
145 double x_ry1 = x1 * ry;
146 double rx_y1 = rx * y1;
147 less1 = x_ry1 < rx_y1;
148 double x2 = x + xSlop;
149 double y2 = y - ySlop;
150 double x_ry2 = x2 * ry;
151 double rx_y2 = rx * y2;
152 less2 = x_ry2 < rx_y2;
153 } while (less1 == less2 && ++slopBits);
154 return slopBits;
155}
156
157// from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors
158static double diamond_angle(double y, double x)
159{
160 if (y >= 0)
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000161 return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000162 else
skia.committer@gmail.com8f6ef402013-06-05 07:01:06 +0000163 return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000164}
165
166static const double slopTests[][4] = {
167 // x y rx ry
168 {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438},
169 {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074},
170 {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008},
171};
172
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000173DEF_TEST(PathOpsAngleFindSlop, reporter) {
174 if (gDisableAngleTests) {
175 return;
176 }
177 for (int index = 0; index < (int) SK_ARRAY_COUNT(slopTests); ++index) {
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000178 const double* slopTest = slopTests[index];
179 double x = slopTest[0];
180 double y = slopTest[1];
181 double rx = slopTest[2];
182 double ry = slopTest[3];
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000183 SkDebugf("%s xy %d=%d\n", __FUNCTION__, index, find_slop(x, y, rx, ry));
184 SkDebugf("%s rxy %d=%d\n", __FUNCTION__, index, find_slop(rx, ry, x, y));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000185 double angle = diamond_angle(y, x);
186 double rAngle = diamond_angle(ry, rx);
187 double diff = fabs(angle - rAngle);
188 SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__,
189 angle, rAngle, diff, (int) (diff / FLT_EPSILON));
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000190 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000191}
192
193class PathOpsAngleTester {
194public:
caryclark54359292015-03-26 07:52:43 -0700195 static int After(SkOpAngle& lh, SkOpAngle& rh) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000196 return lh.after(&rh);
197 }
198
caryclark55888e42016-07-18 10:01:36 -0700199 static int AllOnOneSide(SkOpAngle& lh, SkOpAngle& rh) {
200 return lh.allOnOneSide(&rh);
201 }
202
caryclark54359292015-03-26 07:52:43 -0700203 static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) {
204 return lh.convexHullOverlaps(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000205 }
206
caryclark54359292015-03-26 07:52:43 -0700207 static int Orderable(SkOpAngle& lh, SkOpAngle& rh) {
208 return lh.orderable(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000209 }
210
caryclark54359292015-03-26 07:52:43 -0700211 static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) {
212 return lh.endsIntersect(&rh);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000213 }
214
215 static void SetNext(SkOpAngle& lh, SkOpAngle& rh) {
216 lh.fNext = &rh;
217 }
218};
219
220class PathOpsSegmentTester {
221public:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000222 static void DebugReset(SkOpSegment* segment) {
223 segment->debugReset();
224 }
225};
226
227struct CircleData {
caryclarka35ab3e2016-10-20 08:32:18 -0700228 const CubicPts fPts;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000229 const int fPtCount;
230 SkPoint fShortPts[4];
231};
232
233static CircleData circleDataSet[] = {
234 { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} },
235 { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394},
236 {320.05078125, 227.58743286132812}}}, 3, {} },
237};
238
239static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
240
241DEF_TEST(PathOpsAngleCircle, reporter) {
Herb Derbyc3cc5fa2017-03-07 11:11:47 -0500242 char storage[4096];
243 SkArenaAlloc allocator(storage);
caryclark624637c2015-05-11 07:21:27 -0700244 SkOpContourHead contour;
caryclark55888e42016-07-18 10:01:36 -0700245 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
caryclark54359292015-03-26 07:52:43 -0700246 contour.init(&state, false, false);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000247 for (int index = 0; index < circleDataSetSize; ++index) {
248 CircleData& data = circleDataSet[index];
249 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
250 data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint();
251 }
252 switch (data.fPtCount) {
253 case 2:
caryclark55888e42016-07-18 10:01:36 -0700254 contour.addLine(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000255 break;
256 case 3:
caryclark55888e42016-07-18 10:01:36 -0700257 contour.addQuad(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000258 break;
259 case 4:
caryclark55888e42016-07-18 10:01:36 -0700260 contour.addCubic(data.fShortPts);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000261 break;
262 }
263 }
caryclark54359292015-03-26 07:52:43 -0700264 SkOpSegment* first = contour.first();
caryclark55888e42016-07-18 10:01:36 -0700265 first->debugAddAngle(0, 1);
caryclark54359292015-03-26 07:52:43 -0700266 SkOpSegment* next = first->next();
caryclark55888e42016-07-18 10:01:36 -0700267 next->debugAddAngle(0, 1);
caryclark54359292015-03-26 07:52:43 -0700268 PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngle());
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000269}
270
271struct IntersectData {
caryclarka35ab3e2016-10-20 08:32:18 -0700272 const CubicPts fPts;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000273 const int fPtCount;
274 double fTStart;
275 double fTEnd;
276 SkPoint fShortPts[4];
277};
278
279static IntersectData intersectDataSet1[] = {
280 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
281 0.865309956, 0.154740299, {} },
282 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
283 0.345028807, 0.0786326511, {} },
284 { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
285 0.865309956, 1, {} },
286 { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
287 0.345028807, 1, {} },
288};
289
290static IntersectData intersectDataSet2[] = {
291 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
292 0.578520747, 1, {} },
293 { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
294 0.578520747, 0.536512973, {} },
295 { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3,
296 0.490456543, 1, {} },
297};
298
299static IntersectData intersectDataSet3[] = {
300 { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
301 { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} },
302 { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
303};
304
305static IntersectData intersectDataSet4[] = {
306 { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} },
307 { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} },
308 { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} },
309};
310
311static IntersectData intersectDataSet5[] = {
312 { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} },
313 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} },
314 { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} },
315};
316
317static IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658
318 { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616
319 { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616
320 { {{{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
321};
322
323static IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748
324 { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706
325 { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706
326 { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706
327}; //
328
329static IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194
330 { {{{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
331 { {{{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
332 { {{{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
333}; //
334
335static IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142
336 { {{{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
337 { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100
338 { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100
339}; //
340
341static IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186
342 { {{{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
343 { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144
344 { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144
345}; //
346
347static IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704
348 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662
349 { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662
350 { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662
351}; //
352
353static IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481
354 { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439
355 { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439
356 { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439
357}; //
358
359static IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735
360 { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // pathops_visualizer.htm:5693
361 { {{{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
362 { {{{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
363}; //
364
365static IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875
366 { {{{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
367 { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833
368 { {{{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
369}; //
370
371static IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580
372 { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538
373 { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538
374 { {{{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 +0000375}; //
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000376
377static IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419
378 { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377
379 { {{{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
380 { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377
381}; //
382
caryclark54359292015-03-26 07:52:43 -0700383// from skpi_gino_com_16
384static IntersectData intersectDataSet17[] = {
385 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
386 , 3, 0.74590454, 0.547660352, {} },
387 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
388 , 4, 0.12052623, 0, {} },
389 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
390 , 3, 0.74590454, 1, {} },
391};
392
393static IntersectData intersectDataSet18[] = {
394 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
395 , 3, 0.74590454, 1, {} },
396 { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
397 , 4, 0.12052623, 0.217351928, {} },
398 { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
399 , 3, 0.74590454, 0.547660352, {} },
400};
401
402static IntersectData intersectDataSet19[] = {
403 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
404 , 4, 0.135148995, 0.134791946, {} },
405 { /*seg=3*/ {{{1, 2}, {1, 2.15061641f}, {1, 2.21049166f}, {1.01366711f, 2.21379328f}}}
406 , 4, 0.956740456, 0.894913214, {} },
407 { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
408 , 4, 0.135148995, 0.551812363, {} },
409};
410
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000411#define I(x) intersectDataSet##x
412
413static IntersectData* intersectDataSets[] = {
414 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 -0700415 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 +0000416};
417
418#undef I
419#define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x)
420
421static const int intersectDataSetSizes[] = {
422 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 -0700423 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 +0000424};
425
426#undef I
427
428static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes);
429
caryclark54359292015-03-26 07:52:43 -0700430struct FourPoints {
431 SkPoint pts[4];
432};
433
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000434DEF_TEST(PathOpsAngleAfter, reporter) {
Herb Derbyc3cc5fa2017-03-07 11:11:47 -0500435 char storage[4096];
436 SkArenaAlloc allocator(storage);
caryclark624637c2015-05-11 07:21:27 -0700437 SkOpContourHead contour;
caryclark55888e42016-07-18 10:01:36 -0700438 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
caryclark54359292015-03-26 07:52:43 -0700439 contour.init(&state, false, false);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000440 for (int index = intersectDataSetsSize - 1; index >= 0; --index) {
441 IntersectData* dataArray = intersectDataSets[index];
442 const int dataSize = intersectDataSetSizes[index];
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000443 for (int index2 = 0; index2 < dataSize - 2; ++index2) {
caryclark54359292015-03-26 07:52:43 -0700444 allocator.reset();
445 contour.reset();
446 for (int index3 = 0; index3 < 3; ++index3) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000447 IntersectData& data = dataArray[index2 + index3];
Herb Derbyecc364c2017-04-19 15:09:48 -0400448 SkPoint* temp = (SkPoint*) allocator.make<FourPoints>();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000449 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
450 temp[idx2] = data.fPts.fPts[idx2].asSkPoint();
451 }
452 switch (data.fPtCount) {
453 case 2: {
caryclark55888e42016-07-18 10:01:36 -0700454 contour.addLine(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000455 } break;
456 case 3: {
caryclark55888e42016-07-18 10:01:36 -0700457 contour.addQuad(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000458 } break;
459 case 4: {
caryclark55888e42016-07-18 10:01:36 -0700460 contour.addCubic(temp);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000461 } break;
462 }
463 }
caryclark54359292015-03-26 07:52:43 -0700464 SkOpSegment* seg1 = contour.first();
caryclark55888e42016-07-18 10:01:36 -0700465 seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2 + 0].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700466 SkOpSegment* seg2 = seg1->next();
caryclark55888e42016-07-18 10:01:36 -0700467 seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2 + 1].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700468 SkOpSegment* seg3 = seg2->next();
caryclark55888e42016-07-18 10:01:36 -0700469 seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2 + 2].fTEnd);
caryclark54359292015-03-26 07:52:43 -0700470 SkOpAngle& angle1 = *seg1->debugLastAngle();
471 SkOpAngle& angle2 = *seg2->debugLastAngle();
472 SkOpAngle& angle3 = *seg3->debugLastAngle();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000473 PathOpsAngleTester::SetNext(angle1, angle3);
474 // These data sets are seeded when the set itself fails, so likely the dataset does not
475 // match the expected result. The tests above return 1 when first added, but
476 // return 0 after the bug is fixed.
477 SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1);
478 SkASSERT(result == 0 || result == 1);
479 }
480 }
481}
482
caryclark55888e42016-07-18 10:01:36 -0700483void SkOpSegment::debugAddAngle(double startT, double endT) {
caryclark54359292015-03-26 07:52:43 -0700484 SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT()
caryclark29b25632016-08-25 11:27:17 -0700485 : this->addT(startT);
caryclark54359292015-03-26 07:52:43 -0700486 SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT()
caryclark29b25632016-08-25 11:27:17 -0700487 : this->addT(endT);
Herb Derbyecc364c2017-04-19 15:09:48 -0400488 SkOpAngle* angle = this->globalState()->allocator()->make<SkOpAngle>();
caryclark54359292015-03-26 07:52:43 -0700489 SkOpSpanBase* startSpan = &fHead;
490 while (startSpan->ptT() != startPtT) {
491 startSpan = startSpan->upCast()->next();
492 }
493 SkOpSpanBase* endSpan = &fHead;
494 while (endSpan->ptT() != endPtT) {
495 endSpan = endSpan->upCast()->next();
496 }
497 angle->set(startSpan, endSpan);
498 if (startT < endT) {
499 startSpan->upCast()->setToAngle(angle);
500 endSpan->setFromAngle(angle);
501 } else {
502 endSpan->upCast()->setToAngle(angle);
503 startSpan->setFromAngle(angle);
504 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000505}
caryclark55888e42016-07-18 10:01:36 -0700506
507DEF_TEST(PathOpsAngleAllOnOneSide, reporter) {
Herb Derbyc3cc5fa2017-03-07 11:11:47 -0500508 char storage[4096];
509 SkArenaAlloc allocator(storage);
caryclark55888e42016-07-18 10:01:36 -0700510 SkOpContourHead contour;
511 SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
512 contour.init(&state, false, false);
513 SkPoint conicPts[3] = {{494.37100219726562f, 224.66200256347656f},
514 {494.37360910682298f, 224.6729026561527f},
515 {494.37600708007813f, 224.68400573730469f}};
516 SkPoint linePts[2] = {{494.371002f, 224.662003f}, {494.375000f, 224.675995f}};
517 for (int i = 10; i >= 0; --i) {
518 SkPoint modLinePts[2] = { linePts[0], linePts[1] };
519 modLinePts[1].fX += i * .1f;
520 contour.addLine(modLinePts);
521 contour.addQuad(conicPts);
522 // contour.addConic(conicPts, 0.999935746f, &allocator);
523 SkOpSegment* first = contour.first();
524 first->debugAddAngle(0, 1);
525 SkOpSegment* next = first->next();
526 next->debugAddAngle(0, 1);
527 /* int result = */
528 PathOpsAngleTester::AllOnOneSide(*first->debugLastAngle(), *next->debugLastAngle());
529 // SkDebugf("i=%d result=%d\n", i , result);
530 // SkDebugf("");
531 }
532}