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 "PathOpsTestCommon.h"
8#include "SkIntersections.h"
9#include "SkOpSegment.h"
10#include "SkPathOpsTriangle.h"
11#include "SkRandom.h"
12#include "SkTArray.h"
13#include "SkTSort.h"
14#include "Test.h"
15
16static bool gDisableAngleTests = true;
17
18static float next(float f)
19{
20    int fBits = SkFloatAs2sCompliment(f);
21    ++fBits;
22    float fNext = Sk2sComplimentAsFloat(fBits);
23    return fNext;
24}
25
26static float prev(float f)
27{
28    int fBits = SkFloatAs2sCompliment(f);
29    --fBits;
30    float fNext = Sk2sComplimentAsFloat(fBits);
31    return fNext;
32}
33
34DEF_TEST(PathOpsAngleFindCrossEpsilon, reporter) {
35    if (gDisableAngleTests) {
36        return;
37    }
38    SkRandom ran;
39    int maxEpsilon = 0;
40    for (int index = 0; index < 10000000; ++index) {
41        SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
42        for (int inner = 0; inner < 10; ++inner) {
43            float t = ran.nextRangeF(0.0001f, 1);
44            SkDPoint dPt = line.ptAtT(t);
45            SkPoint pt = dPt.asSkPoint();
46            float xs[3] = { prev(pt.fX), pt.fX, next(pt.fX) };
47            float ys[3] = { prev(pt.fY), pt.fY, next(pt.fY) };
48            for (int xIdx = 0; xIdx < 3; ++xIdx) {
49                for (int yIdx = 0; yIdx < 3; ++yIdx) {
50                    SkPoint test = { xs[xIdx], ys[yIdx] };
51                    float p1 = SkDoubleToScalar(line[1].fX * test.fY);
52                    float p2 = SkDoubleToScalar(line[1].fY * test.fX);
53                    int p1Bits = SkFloatAs2sCompliment(p1);
54                    int p2Bits = SkFloatAs2sCompliment(p2);
55                    int epsilon = abs(p1Bits - p2Bits);
56                    if (maxEpsilon < epsilon) {
57                        SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g pt={%1.7g, %1.7g}"
58                            " epsilon=%d\n",
59                            line[1].fX, line[1].fY, t, test.fX, test.fY, epsilon);
60                        maxEpsilon = epsilon;
61                    }
62                }
63            }
64        }
65    }
66}
67
68DEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) {
69    if (gDisableAngleTests) {
70        return;
71    }
72    SkRandom ran;
73    int maxEpsilon = 0;
74    double maxAngle = 0;
75    for (int index = 0; index < 100000; ++index) {
76        SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
77        float t = ran.nextRangeF(0.0001f, 1);
78        SkDPoint dPt = line.ptAtT(t);
79        float t2 = ran.nextRangeF(0.0001f, 1);
80        SkDPoint qPt = line.ptAtT(t2);
81        float t3 = ran.nextRangeF(0.0001f, 1);
82        SkDPoint qPt2 = line.ptAtT(t3);
83        qPt.fX += qPt2.fY;
84        qPt.fY -= qPt2.fX;
85        SkDQuad quad = {{line[0], dPt, qPt}};
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 = abs(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
127static 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
157static 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
165static 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
172DEF_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
192class PathOpsAngleTester {
193public:
194    static int After(const SkOpAngle& lh, const SkOpAngle& rh) {
195        return lh.after(&rh);
196    }
197
198    static int ConvexHullOverlaps(const SkOpAngle& lh, const SkOpAngle& rh) {
199        return lh.convexHullOverlaps(rh);
200    }
201
202    static int Orderable(const SkOpAngle& lh, const SkOpAngle& rh) {
203        return lh.orderable(rh);
204    }
205
206    static int EndsIntersect(const SkOpAngle& lh, const SkOpAngle& rh) {
207        return lh.endsIntersect(rh);
208    }
209
210    static void SetNext(SkOpAngle& lh, SkOpAngle& rh) {
211        lh.fNext = &rh;
212    }
213};
214
215class PathOpsSegmentTester {
216public:
217    static void ConstructCubic(SkOpSegment* segment, SkPoint shortCubic[4]) {
218        segment->debugConstructCubic(shortCubic);
219    }
220
221    static void ConstructLine(SkOpSegment* segment, SkPoint shortLine[2]) {
222        segment->debugConstructLine(shortLine);
223    }
224
225    static void ConstructQuad(SkOpSegment* segment, SkPoint shortQuad[3]) {
226        segment->debugConstructQuad(shortQuad);
227    }
228
229    static void DebugReset(SkOpSegment* segment) {
230        segment->debugReset();
231    }
232};
233
234struct CircleData {
235    const SkDCubic fPts;
236    const int fPtCount;
237    SkPoint fShortPts[4];
238};
239
240static CircleData circleDataSet[] = {
241    { {{{313.0155029296875, 207.90290832519531}, {320.05078125, 227.58743286132812}}}, 2, {} },
242    { {{{313.0155029296875, 207.90290832519531}, {313.98246891063195, 219.33615203830394},
243            {320.05078125, 227.58743286132812}}}, 3, {} },
244};
245
246static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
247
248DEF_TEST(PathOpsAngleCircle, reporter) {
249    SkOpSegment segment[2];
250    for (int index = 0; index < circleDataSetSize; ++index) {
251        CircleData& data = circleDataSet[index];
252        for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
253            data.fShortPts[idx2] = data.fPts.fPts[idx2].asSkPoint();
254        }
255        switch (data.fPtCount) {
256            case 2:
257                PathOpsSegmentTester::ConstructLine(&segment[index], data.fShortPts);
258                break;
259            case 3:
260                PathOpsSegmentTester::ConstructQuad(&segment[index], data.fShortPts);
261                break;
262            case 4:
263                PathOpsSegmentTester::ConstructCubic(&segment[index], data.fShortPts);
264                break;
265        }
266    }
267    PathOpsAngleTester::Orderable(*segment[0].debugLastAngle(), *segment[1].debugLastAngle());
268}
269
270struct IntersectData {
271    const SkDCubic fPts;
272    const int fPtCount;
273    double fTStart;
274    double fTEnd;
275    SkPoint fShortPts[4];
276};
277
278static IntersectData intersectDataSet1[] = {
279    { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
280            0.865309956, 0.154740299, {} },
281    { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
282            0.345028807, 0.0786326511, {} },
283    { {{{322.935669,231.030273}, {312.832214,220.393295}, {312.832214,203.454178}}}, 3,
284            0.865309956, 1, {} },
285    { {{{322.12738,233.397751}, {295.718353,159.505829}}}, 2,
286            0.345028807, 1, {} },
287};
288
289static IntersectData intersectDataSet2[] = {
290    { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
291            0.578520747, 1, {} },
292    { {{{364.390686,157.898193}, {375.281769,136.674606}, {396.039917,136.674606}}}, 3,
293            0.578520747, 0.536512973, {} },
294    { {{{366.608826,151.196014}, {378.803101,136.674606}, {398.164948,136.674606}}}, 3,
295            0.490456543, 1, {} },
296};
297
298static IntersectData intersectDataSet3[] = {
299    { {{{2.000000,0.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
300    { {{{1.33333333,0.66666667}, {0.000000,2.000000}}}, 2, 0, 0.25, {} },
301    { {{{2.000000,2.000000}, {1.33333333,0.66666667}}}, 2, 1, 0, {} },
302};
303
304static IntersectData intersectDataSet4[] = {
305    { {{{1.3333333,0.6666667}, {0.000,2.000}}}, 2, 0.250000006, 0, {} },
306    { {{{1.000,0.000}, {1.000,1.000}}}, 2, 1, 0, {} },
307    { {{{1.000,1.000}, {0.000,0.000}}}, 2, 0, 1, {} },
308};
309
310static IntersectData intersectDataSet5[] = {
311    { {{{0.000,0.000}, {1.000,0.000}, {1.000,1.000}}}, 3, 1, 0.666666667, {} },
312    { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 1, {} },
313    { {{{0.000,0.000}, {2.000,1.000}, {0.000,2.000}}}, 3, 0.5, 0, {} },
314};
315
316static IntersectData intersectDataSet6[] = { // pathops_visualizer.htm:3658
317    { {{{0.000,1.000}, {3.000,4.000}, {1.000,0.000}, {3.000,0.000}}}, 4, 0.0925339054, 0, {} }, // pathops_visualizer.htm:3616
318    { {{{0.000,1.000}, {0.000,3.000}, {1.000,0.000}, {4.000,3.000}}}, 4, 0.453872386, 0, {} }, // pathops_visualizer.htm:3616
319    { {{{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
320};
321
322static IntersectData intersectDataSet7[] = { // pathops_visualizer.htm:3748
323    { {{{2.000,1.000}, {0.000,1.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:3706
324    { {{{2.000,0.000}, {0.000,2.000}}}, 2, 0.5, 1, {} }, // pathops_visualizer.htm:3706
325    { {{{0.000,1.000}, {0.000,2.000}, {2.000,0.000}, {2.000,1.000}}}, 4, 0.5, 1, {} }, // pathops_visualizer.htm:3706
326}; //
327
328static IntersectData intersectDataSet8[] = { // pathops_visualizer.htm:4194
329    { {{{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
330    { {{{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
331    { {{{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
332}; //
333
334static IntersectData intersectDataSet9[] = { // pathops_visualizer.htm:4142
335    { {{{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
336    { {{{1.000,5.000}, {3.000,4.000}, {1.000,0.000}, {3.000,2.000}}}, 4, 0.999982974, 1, {} }, // pathops_visualizer.htm:4100
337    { {{{0.000,1.000}, {2.000,3.000}, {5.000,1.000}, {4.000,3.000}}}, 4, 0.476627072, 1, {} }, // pathops_visualizer.htm:4100
338}; //
339
340static IntersectData intersectDataSet10[] = { // pathops_visualizer.htm:4186
341    { {{{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
342    { {{{0.000,1.000}, {0.000,1.000}, {1.000,0.000}, {6.000,1.000}}}, 4, 0.473378977, 1, {} }, // pathops_visualizer.htm:4144
343    { {{{0.000,1.000}, {1.000,6.000}, {1.000,0.000}, {1.000,0.000}}}, 4, 0.788195121, 1, {} }, // pathops_visualizer.htm:4144
344}; //
345
346static IntersectData intersectDataSet11[] = { // pathops_visualizer.htm:4704
347    { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 0.11111108, {} }, // pathops_visualizer.htm:4662
348    { {{{1006.695,291.000}, {1023.264,291.000}, {1033.840,304.431}, {1030.318,321.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:4662
349    { {{{979.305,561.000}, {1036.695,291.000}}}, 2, 0.888888874, 1, {} }, // pathops_visualizer.htm:4662
350}; //
351
352static IntersectData intersectDataSet12[] = { // pathops_visualizer.htm:5481
353    { {{{67.000,912.000}, {67.000,913.000}}}, 2, 1, 0, {} }, // pathops_visualizer.htm:5439
354    { {{{67.000,913.000}, {67.000,917.389}, {67.224,921.726}, {67.662,926.000}}}, 4, 0, 1, {} }, // pathops_visualizer.htm:5439
355    { {{{194.000,1041.000}, {123.860,1041.000}, {67.000,983.692}, {67.000,913.000}}}, 4, 1, 0, {} }, // pathops_visualizer.htm:5439
356}; //
357
358static IntersectData intersectDataSet13[] = { // pathops_visualizer.htm:5735
359    { {{{6.000,0.000}, {0.000,4.000}}}, 2, 0.625, 0.25, {} }, // 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.833333333, {} }, // 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.379043969, {} }, // pathops_visualizer.htm:5693
362}; //
363
364static IntersectData intersectDataSet14[] = { // pathops_visualizer.htm:5875
365    { {{{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
366    { {{{1.000,2.000}, {0.000,2.000}, {1.000,0.000}, {6.000,4.000}}}, 4, 0.0756502184, 0, {} }, // pathops_visualizer.htm:5833
367    { {{{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
368}; //
369
370static IntersectData intersectDataSet15[] = { // pathops_visualizer.htm:6580
371    { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 1, {} }, // pathops_visualizer.htm:6538
372    { {{{447.967,894.438}, {448.007,894.424}, {448.014,894.422}}}, 3, 0, 1, {} }, // pathops_visualizer.htm:6538
373    { {{{490.435,879.407}, {405.593,909.436}}}, 2, 0.500554405, 0.500000273, {} }, // pathops_visualizer.htm:6538
374}; //
375
376static IntersectData intersectDataSet16[] = { // pathops_visualizer.htm:7419
377    { {{{1.000,4.000}, {4.000,5.000}, {3.000,2.000}, {6.000,3.000}}}, 4, 0.5, 0, {} }, // pathops_visualizer.htm:7377
378    { {{{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
379    { {{{5.000,4.000}, {2.000,3.000}}}, 2, 0.5, 0, {} }, // pathops_visualizer.htm:7377
380}; //
381
382#define I(x) intersectDataSet##x
383
384static IntersectData* intersectDataSets[] = {
385    I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
386    I(11), I(12), I(13), I(14), I(15), I(16),
387};
388
389#undef I
390#define I(x) (int) SK_ARRAY_COUNT(intersectDataSet##x)
391
392static const int intersectDataSetSizes[] = {
393    I(1), I(2), I(3), I(4), I(5), I(6), I(7), I(8), I(9), I(10),
394    I(11), I(12), I(13), I(14), I(15), I(16),
395};
396
397#undef I
398
399static const int intersectDataSetsSize = (int) SK_ARRAY_COUNT(intersectDataSetSizes);
400
401DEF_TEST(PathOpsAngleAfter, reporter) {
402    for (int index = intersectDataSetsSize - 1; index >= 0; --index) {
403        IntersectData* dataArray = intersectDataSets[index];
404        const int dataSize = intersectDataSetSizes[index];
405        SkOpSegment segment[3];
406        for (int index2 = 0; index2 < dataSize - 2; ++index2) {
407            for (int temp = 0; temp < (int) SK_ARRAY_COUNT(segment); ++temp) {
408                PathOpsSegmentTester::DebugReset(&segment[temp]);
409            }
410            for (int index3 = 0; index3 < (int) SK_ARRAY_COUNT(segment); ++index3) {
411                IntersectData& data = dataArray[index2 + index3];
412                SkPoint temp[4];
413                for (int idx2 = 0; idx2 < data.fPtCount; ++idx2) {
414                    temp[idx2] = data.fPts.fPts[idx2].asSkPoint();
415                }
416                switch (data.fPtCount) {
417                    case 2: {
418                        SkDLine seg = SkDLine::SubDivide(temp, data.fTStart,
419                                data.fTStart < data.fTEnd ? 1 : 0);
420                        data.fShortPts[0] = seg[0].asSkPoint();
421                        data.fShortPts[1] = seg[1].asSkPoint();
422                        PathOpsSegmentTester::ConstructLine(&segment[index3], data.fShortPts);
423                        } break;
424                    case 3: {
425                        SkDQuad seg = SkDQuad::SubDivide(temp, data.fTStart, data.fTEnd);
426                        data.fShortPts[0] = seg[0].asSkPoint();
427                        data.fShortPts[1] = seg[1].asSkPoint();
428                        data.fShortPts[2] = seg[2].asSkPoint();
429                        PathOpsSegmentTester::ConstructQuad(&segment[index3], data.fShortPts);
430                        } break;
431                    case 4: {
432                        SkDCubic seg = SkDCubic::SubDivide(temp, data.fTStart, data.fTEnd);
433                        data.fShortPts[0] = seg[0].asSkPoint();
434                        data.fShortPts[1] = seg[1].asSkPoint();
435                        data.fShortPts[2] = seg[2].asSkPoint();
436                        data.fShortPts[3] = seg[3].asSkPoint();
437                        PathOpsSegmentTester::ConstructCubic(&segment[index3], data.fShortPts);
438                        } break;
439                }
440            }
441            SkOpAngle& angle1 = *const_cast<SkOpAngle*>(segment[0].debugLastAngle());
442            SkOpAngle& angle2 = *const_cast<SkOpAngle*>(segment[1].debugLastAngle());
443            SkOpAngle& angle3 = *const_cast<SkOpAngle*>(segment[2].debugLastAngle());
444            PathOpsAngleTester::SetNext(angle1, angle3);
445       // These data sets are seeded when the set itself fails, so likely the dataset does not
446       // match the expected result. The tests above return 1 when first added, but
447       // return 0 after the bug is fixed.
448            SkDEBUGCODE(int result =) PathOpsAngleTester::After(angle2, angle1);
449            SkASSERT(result == 0 || result == 1);
450        }
451    }
452}
453
454void SkOpSegment::debugConstruct() {
455    addStartSpan(1);
456    addEndSpan(1);
457    debugAddAngle(0, 1);
458}
459
460void SkOpSegment::debugAddAngle(int start, int end) {
461    SkASSERT(start != end);
462    SkOpAngle& angle = fAngles.push_back();
463    angle.set(this, start, end);
464}
465
466void SkOpSegment::debugConstructCubic(SkPoint shortQuad[4]) {
467    addCubic(shortQuad, false, false);
468    addT(NULL, shortQuad[0], 0);
469    addT(NULL, shortQuad[3], 1);
470    debugConstruct();
471}
472
473void SkOpSegment::debugConstructLine(SkPoint shortQuad[2]) {
474    addLine(shortQuad, false, false);
475    addT(NULL, shortQuad[0], 0);
476    addT(NULL, shortQuad[1], 1);
477    debugConstruct();
478}
479
480void SkOpSegment::debugConstructQuad(SkPoint shortQuad[3]) {
481    addQuad(shortQuad, false, false);
482    addT(NULL, shortQuad[0], 0);
483    addT(NULL, shortQuad[2], 1);
484    debugConstruct();
485}
486