• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "include/utils/SkRandom.h"
8 #include "src/pathops/SkIntersections.h"
9 #include "src/pathops/SkOpContour.h"
10 #include "src/pathops/SkOpSegment.h"
11 #include "tests/PathOpsTestCommon.h"
12 #include "tests/Test.h"
13 
14 static bool gDisableAngleTests = true;
15 
next(float f)16 static float next(float f)
17 {
18     int fBits = SkFloatAs2sCompliment(f);
19     ++fBits;
20     float fNext = Sk2sComplimentAsFloat(fBits);
21     return fNext;
22 }
23 
prev(float f)24 static float prev(float f)
25 {
26     int fBits = SkFloatAs2sCompliment(f);
27     --fBits;
28     float fNext = Sk2sComplimentAsFloat(fBits);
29     return fNext;
30 }
31 
DEF_TEST(PathOpsAngleFindCrossEpsilon,reporter)32 DEF_TEST(PathOpsAngleFindCrossEpsilon, reporter) {
33     if (gDisableAngleTests) {
34         return;
35     }
36     SkRandom ran;
37     int maxEpsilon = 0;
38     for (int index = 0; index < 10000000; ++index) {
39         SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
40         for (int inner = 0; inner < 10; ++inner) {
41             float t = ran.nextRangeF(0.0001f, 1);
42             SkDPoint dPt = line.ptAtT(t);
43             SkPoint pt = dPt.asSkPoint();
44             float xs[3] = { prev(pt.fX), pt.fX, next(pt.fX) };
45             float ys[3] = { prev(pt.fY), pt.fY, next(pt.fY) };
46             for (int xIdx = 0; xIdx < 3; ++xIdx) {
47                 for (int yIdx = 0; yIdx < 3; ++yIdx) {
48                     SkPoint test = { xs[xIdx], ys[yIdx] };
49                     float p1 = SkDoubleToScalar(line[1].fX * test.fY);
50                     float p2 = SkDoubleToScalar(line[1].fY * test.fX);
51                     int p1Bits = SkFloatAs2sCompliment(p1);
52                     int p2Bits = SkFloatAs2sCompliment(p2);
53                     int epsilon = SkTAbs(p1Bits - p2Bits);
54                     if (maxEpsilon < epsilon) {
55                         SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g pt={%1.7g, %1.7g}"
56                             " epsilon=%d\n",
57                             line[1].fX, line[1].fY, t, test.fX, test.fY, epsilon);
58                         maxEpsilon = epsilon;
59                     }
60                 }
61             }
62         }
63     }
64 }
65 
DEF_TEST(PathOpsAngleFindQuadEpsilon,reporter)66 DEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) {
67     if (gDisableAngleTests) {
68         return;
69     }
70     SkRandom ran;
71     int maxEpsilon = 0;
72     double maxAngle = 0;
73     for (int index = 0; index < 100000; ++index) {
74         SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
75         float t = ran.nextRangeF(0.0001f, 1);
76         SkDPoint dPt = line.ptAtT(t);
77         float t2 = ran.nextRangeF(0.0001f, 1);
78         SkDPoint qPt = line.ptAtT(t2);
79         float t3 = ran.nextRangeF(0.0001f, 1);
80         SkDPoint qPt2 = line.ptAtT(t3);
81         qPt.fX += qPt2.fY;
82         qPt.fY -= qPt2.fX;
83         QuadPts q = {{line[0], dPt, qPt}};
84         SkDQuad quad;
85         quad.debugSet(q.fPts);
86         // binary search for maximum movement of quad[1] towards test that still has 1 intersection
87         double moveT = 0.5f;
88         double deltaT = moveT / 2;
89         SkDPoint last;
90         do {
91             last = quad[1];
92             quad[1].fX = dPt.fX - line[1].fY * moveT;
93             quad[1].fY = dPt.fY + line[1].fX * moveT;
94             SkIntersections i;
95             i.intersect(quad, line);
96             REPORTER_ASSERT(reporter, i.used() > 0);
97             if (i.used() == 1) {
98                 moveT += deltaT;
99             } else {
100                 moveT -= deltaT;
101             }
102             deltaT /= 2;
103         } while (last.asSkPoint() != quad[1].asSkPoint());
104         float p1 = SkDoubleToScalar(line[1].fX * last.fY);
105         float p2 = SkDoubleToScalar(line[1].fY * last.fX);
106         int p1Bits = SkFloatAs2sCompliment(p1);
107         int p2Bits = SkFloatAs2sCompliment(p2);
108         int epsilon = SkTAbs(p1Bits - p2Bits);
109         if (maxEpsilon < epsilon) {
110             SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
111                     " pt={%1.7g, %1.7g} epsilon=%d\n",
112                     line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon);
113             maxEpsilon = epsilon;
114         }
115         double a1 = atan2(line[1].fY, line[1].fX);
116         double a2 = atan2(last.fY, last.fX);
117         double angle = fabs(a1 - a2);
118         if (maxAngle < angle) {
119             SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
120                     " pt={%1.7g, %1.7g} angle=%1.7g\n",
121                     line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle);
122             maxAngle = angle;
123         }
124     }
125 }
126 
find_slop(double x,double y,double rx,double ry)127 static int find_slop(double x, double y, double rx, double ry) {
128     int slopBits = 0;
129     bool less1, less2;
130     double absX = fabs(x);
131     double absY = fabs(y);
132     double length = absX < absY ? absX / 2 + absY : absX + absY / 2;
133     int exponent;
134     (void) frexp(length, &exponent);
135     double epsilon = ldexp(FLT_EPSILON, exponent);
136     do {
137         // get the length as the larger plus half the smaller (both same signs)
138         // find the ulps of the length
139         // compute the offsets from there
140         double xSlop = epsilon * slopBits;
141         double ySlop = x * y < 0 ? -xSlop : xSlop; // OPTIMIZATION: use copysign / _copysign ?
142         double x1 = x - xSlop;
143         double y1 = y + ySlop;
144         double x_ry1 = x1 * ry;
145         double rx_y1 = rx * y1;
146         less1 = x_ry1 < rx_y1;
147         double x2 = x + xSlop;
148         double y2 = y - ySlop;
149         double x_ry2 = x2 * ry;
150         double rx_y2 = rx * y2;
151         less2 = x_ry2 < rx_y2;
152     } while (less1 == less2 && ++slopBits);
153     return slopBits;
154 }
155 
156 // from http://stackoverflow.com/questions/1427422/cheap-algorithm-to-find-measure-of-angle-between-vectors
diamond_angle(double y,double x)157 static double diamond_angle(double y, double x)
158 {
159     if (y >= 0)
160         return (x >= 0 ? y/(x+y) : 1-x/(-x+y));
161     else
162         return (x < 0 ? 2-y/(-x-y) : 3+x/(x-y));
163 }
164 
165 static const double slopTests[][4] = {
166    // x                      y                       rx                      ry
167     {-0.058554756452593892, -0.18804585843827226, -0.018568569646021160, -0.059615294434479438},
168     {-0.0013717412948608398, 0.0041152238845825195, -0.00045837944195925573, 0.0013753175735478074},
169     {-2.1033774145221198, -1.4046019261273715e-008, -0.70062688352066704, -1.2706324683777995e-008},
170 };
171 
DEF_TEST(PathOpsAngleFindSlop,reporter)172 DEF_TEST(PathOpsAngleFindSlop, reporter) {
173     if (gDisableAngleTests) {
174         return;
175     }
176     for (int index = 0; index < (int) SK_ARRAY_COUNT(slopTests); ++index) {
177         const double* slopTest = slopTests[index];
178         double x = slopTest[0];
179         double y = slopTest[1];
180         double rx = slopTest[2];
181         double ry = slopTest[3];
182         SkDebugf("%s  xy %d=%d\n", __FUNCTION__, index, find_slop(x, y, rx, ry));
183         SkDebugf("%s rxy %d=%d\n", __FUNCTION__, index, find_slop(rx, ry, x, y));
184         double angle = diamond_angle(y, x);
185         double rAngle = diamond_angle(ry, rx);
186         double diff = fabs(angle - rAngle);
187         SkDebugf("%s diamond xy=%1.9g rxy=%1.9g diff=%1.9g factor=%d\n", __FUNCTION__,
188                 angle, rAngle, diff, (int) (diff / FLT_EPSILON));
189     }
190 }
191 
192 class PathOpsAngleTester {
193 public:
After(SkOpAngle & lh,SkOpAngle & rh)194     static int After(SkOpAngle& lh, SkOpAngle& rh) {
195         return lh.after(&rh);
196     }
197 
AllOnOneSide(SkOpAngle & lh,SkOpAngle & rh)198     static int AllOnOneSide(SkOpAngle& lh, SkOpAngle& rh) {
199         return lh.lineOnOneSide(&rh, false);
200     }
201 
ConvexHullOverlaps(SkOpAngle & lh,SkOpAngle & rh)202     static int ConvexHullOverlaps(SkOpAngle& lh, SkOpAngle& rh) {
203         return lh.convexHullOverlaps(&rh);
204     }
205 
Orderable(SkOpAngle & lh,SkOpAngle & rh)206     static int Orderable(SkOpAngle& lh, SkOpAngle& rh) {
207         return lh.orderable(&rh);
208     }
209 
EndsIntersect(SkOpAngle & lh,SkOpAngle & rh)210     static int EndsIntersect(SkOpAngle& lh, SkOpAngle& rh) {
211         return lh.endsIntersect(&rh);
212     }
213 
SetNext(SkOpAngle & lh,SkOpAngle & rh)214     static void SetNext(SkOpAngle& lh, SkOpAngle& rh) {
215         lh.fNext = &rh;
216     }
217 };
218 
219 class PathOpsSegmentTester {
220 public:
DebugReset(SkOpSegment * segment)221     static void DebugReset(SkOpSegment* segment) {
222         segment->debugReset();
223     }
224 };
225 
226 struct CircleData {
227     const CubicPts fPts;
228     const int fPtCount;
229     SkPoint fShortPts[4];
230 };
231 
232 static CircleData circleDataSet[] = {
233     { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} },
234     { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394},
235             {320.05078125, 227.58743286132812}}}, 3, {} },
236 };
237 
238 static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
239 
DEF_TEST(PathOpsAngleCircle,reporter)240 DEF_TEST(PathOpsAngleCircle, reporter) {
241     SkSTArenaAlloc<4096> allocator;
242     SkOpContourHead contour;
243     SkOpGlobalState state(&contour, &allocator  SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
244     contour.init(&state, false, false);
245     for (int index = 0; index < circleDataSetSize; ++index) {
246         CircleData& data = circleDataSet[index];
247         for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
248             data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint();
249         }
250         switch (data.fPtCount) {
251             case 2:
252                 contour.addLine(data.fShortPts);
253                 break;
254             case 3:
255                 contour.addQuad(data.fShortPts);
256                 break;
257             case 4:
258                 contour.addCubic(data.fShortPts);
259                 break;
260         }
261     }
262     SkOpSegment* first = contour.first();
263     first->debugAddAngle(0, 1);
264     SkOpSegment* next = first->next();
265     next->debugAddAngle(0, 1);
266     PathOpsAngleTester::Orderable(*first->debugLastAngle(), *next->debugLastAngle());
267 }
268 
269 struct IntersectData {
270     const CubicPts fPts;
271     const int fPtCount;
272     double fTStart;
273     double fTEnd;
274     SkPoint fShortPts[4];
275 };
276 
277 static IntersectData intersectDataSet1[] = {
278     { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
279             0.865309956, 0.154740299, {} },
280     { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
281             0.345028807, 0.0786326511, {} },
282     { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
283             0.865309956, 1, {} },
284     { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
285             0.345028807, 1, {} },
286 };
287 
288 static IntersectData intersectDataSet2[] = {
289     { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
290             0.578520747, 1, {} },
291     { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
292             0.578520747, 0.536512973, {} },
293     { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3,
294             0.490456543, 1, {} },
295 };
296 
297 static IntersectData intersectDataSet3[] = {
298     { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
299     { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} },
300     { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
301 };
302 
303 static IntersectData intersectDataSet4[] = {
304     { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} },
305     { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} },
306     { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} },
307 };
308 
309 static IntersectData intersectDataSet5[] = {
310     { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} },
311     { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} },
312     { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} },
313 };
314 
315 static IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658
316     { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616
317     { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616
318     { {{{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
319 };
320 
321 static IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748
322     { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706
323     { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706
324     { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706
325 }; //
326 
327 static IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194
328     { {{{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
329     { {{{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
330     { {{{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
331 }; //
332 
333 static IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142
334     { {{{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
335     { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100
336     { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100
337 }; //
338 
339 static IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186
340     { {{{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
341     { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144
342     { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144
343 }; //
344 
345 static IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704
346     { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662
347     { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662
348     { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662
349 }; //
350 
351 static IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481
352     { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439
353     { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439
354     { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439
355 }; //
356 
357 static IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735
358     { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // 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.833333333, {} }, // pathops_visualizer.htm:5693
360     { {{{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
361 }; //
362 
363 static IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875
364     { {{{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
365     { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833
366     { {{{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
367 }; //
368 
369 static IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580
370     { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538
371     { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538
372     { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 0.500000273, {} }, // pathops_visualizer.htm:6538
373 }; //
374 
375 static IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419
376     { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377
377     { {{{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
378     { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377
379 }; //
380 
381 // from skpi_gino_com_16
382 static IntersectData intersectDataSet17[] = {
383     { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
384         , 3, 0.74590454, 0.547660352, {} },
385     { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
386         , 4, 0.12052623, 0, {} },
387     { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
388         , 3, 0.74590454, 1, {} },
389 };
390 
391 static IntersectData intersectDataSet18[] = {
392     { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
393         , 3, 0.74590454, 1, {} },
394     { /*seg=8*/ {{{185, 734}, {252.93103f, 734}, {308, 789.06897f}, {308, 857}}}
395         , 4, 0.12052623, 0.217351928, {} },
396     { /*seg=7*/ {{{270.974121f, 770.025879f}, {234.948273f, 734}, {184, 734}}}
397         , 3, 0.74590454, 0.547660352, {} },
398 };
399 
400 static IntersectData intersectDataSet19[] = {
401     { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
402         , 4, 0.135148995, 0.134791946, {} },
403     { /*seg=3*/ {{{1, 2}, {1, 2.15061641f}, {1, 2.21049166f}, {1.01366711f, 2.21379328f}}}
404         , 4, 0.956740456, 0.894913214, {} },
405     { /*seg=1*/ {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}
406         , 4, 0.135148995, 0.551812363, {} },
407 };
408 
409 #define I(x) intersectDataSet##x
410 
411 static IntersectData* intersectDataSets[] = {
412     I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
413     I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19),
414 };
415 
416 #undef I
417 #define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x)
418 
419 static const int intersectDataSetSizes[] = {
420     I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
421     I(11), I(12), I(13), I(14), I(15), I(16), I(17), I(18), I(19),
422 };
423 
424 #undef I
425 
426 static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes);
427 
428 struct FourPoints {
429     SkPoint pts[4];
430 };
431 
DEF_TEST(PathOpsAngleAfter,reporter)432 DEF_TEST(PathOpsAngleAfter, reporter) {
433     for (int index = intersectDataSetsSize - 1; index >= 0; --index) {
434         IntersectData* dataArray = intersectDataSets[index];
435         const int dataSize = intersectDataSetSizes[index];
436         for (int index2 = 0; index2 < dataSize - 2; ++index2) {
437             SkSTArenaAlloc<4096> alloc;
438             SkOpContourHead contour;
439             SkOpGlobalState state(&contour, &alloc  SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
440             contour.init(&state, false, false);
441             for (int index3 = 0; index3 < 3; ++index3) {
442                 IntersectData& data = dataArray[index2 + index3];
443                 SkPoint* temp = (SkPoint*) alloc.make<FourPoints>();
444                 for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
445                     temp[idx2] = data.fPts.fPts[idx2].asSkPoint();
446                 }
447                 switch (data.fPtCount) {
448                     case 2: {
449                         contour.addLine(temp);
450                         } break;
451                     case 3: {
452                         contour.addQuad(temp);
453                         } break;
454                     case 4: {
455                         contour.addCubic(temp);
456                         } break;
457                 }
458             }
459             SkOpSegment* seg1 = contour.first();
460             seg1->debugAddAngle(dataArray[index2 + 0].fTStart, dataArray[index2 + 0].fTEnd);
461             SkOpSegment* seg2 = seg1->next();
462             seg2->debugAddAngle(dataArray[index2 + 1].fTStart, dataArray[index2 + 1].fTEnd);
463             SkOpSegment* seg3 = seg2->next();
464             seg3->debugAddAngle(dataArray[index2 + 2].fTStart, dataArray[index2 + 2].fTEnd);
465             SkOpAngle& angle1 = *seg1->debugLastAngle();
466             SkOpAngle& angle2 = *seg2->debugLastAngle();
467             SkOpAngle& angle3 = *seg3->debugLastAngle();
468             PathOpsAngleTester::SetNext(angle1, angle3);
469        // These data sets are seeded when the set itself fails, so likely the dataset does not
470        // match the expected result. The tests above return 1 when first added, but
471        // return 0 after the bug is fixed.
472             SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1);
473             SkASSERT(result == 0 || result == 1);
474         }
475     }
476 }
477 
debugAddAngle(double startT,double endT)478 void SkOpSegment::debugAddAngle(double startT, double endT) {
479     SkOpPtT* startPtT = startT == 0 ? fHead.ptT() : startT == 1 ? fTail.ptT()
480             : this->addT(startT);
481     SkOpPtT* endPtT = endT == 0 ? fHead.ptT() : endT == 1 ? fTail.ptT()
482             : this->addT(endT);
483     SkOpAngle* angle = this->globalState()->allocator()->make<SkOpAngle>();
484     SkOpSpanBase* startSpan = &fHead;
485     while (startSpan->ptT() != startPtT) {
486         startSpan = startSpan->upCast()->next();
487     }
488     SkOpSpanBase* endSpan = &fHead;
489     while (endSpan->ptT() != endPtT) {
490         endSpan = endSpan->upCast()->next();
491     }
492     angle->set(startSpan, endSpan);
493     if (startT < endT) {
494         startSpan->upCast()->setToAngle(angle);
495         endSpan->setFromAngle(angle);
496     } else {
497         endSpan->upCast()->setToAngle(angle);
498         startSpan->setFromAngle(angle);
499     }
500 }
501 
DEF_TEST(PathOpsAngleAllOnOneSide,reporter)502 DEF_TEST(PathOpsAngleAllOnOneSide, reporter) {
503     SkSTArenaAlloc<4096> allocator;
504     SkOpContourHead contour;
505     SkOpGlobalState state(&contour, &allocator  SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
506     contour.init(&state, false, false);
507     SkPoint conicPts[3] = {{494.37100219726562f, 224.66200256347656f},
508         {494.37360910682298f, 224.6729026561527f},
509         {494.37600708007813f, 224.68400573730469f}};
510     SkPoint linePts[2] = {{494.371002f, 224.662003f}, {494.375000f, 224.675995f}};
511     for (int i = 10; i >= 0; --i) {
512         SkPoint modLinePts[2] = { linePts[0], linePts[1] };
513         modLinePts[1].fX += i * .1f;
514         contour.addLine(modLinePts);
515         contour.addQuad(conicPts);
516    //     contour.addConic(conicPts, 0.999935746f, &allocator);
517         SkOpSegment* first = contour.first();
518         first->debugAddAngle(0, 1);
519         SkOpSegment* next = first->next();
520         next->debugAddAngle(0, 1);
521         /* int result = */
522             PathOpsAngleTester::AllOnOneSide(*first->debugLastAngle(), *next->debugLastAngle());
523   //      SkDebugf("i=%d result=%d\n", i , result);
524     }
525 }
526