blob: 0248f41658c964700bf8787f7c4719d3a9be2e41 [file] [log] [blame]
caryclark@google.com9166dcb2013-04-08 11:50:00 +00001/*
2 * Copyright 2012 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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "src/core/SkGeometry.h"
8#include "src/pathops/SkIntersections.h"
9#include "src/pathops/SkPathOpsRect.h"
10#include "src/pathops/SkReduceOrder.h"
11#include "tests/PathOpsCubicIntersectionTestData.h"
12#include "tests/PathOpsTestCommon.h"
13#include "tests/Test.h"
caryclark@google.com9166dcb2013-04-08 11:50:00 +000014
bungeman60e0fee2015-08-26 05:15:46 -070015#include <stdlib.h>
16
John Stiles97659732021-08-12 10:48:09 -040017using namespace PathOpsCubicIntersectionTestData;
18
19static constexpr int kFirstCubicIntersectionTest = 9;
caryclark@google.com9166dcb2013-04-08 11:50:00 +000020
21static void standardTestCases(skiatest::Reporter* reporter) {
John Stiles97659732021-08-12 10:48:09 -040022 for (size_t index = kFirstCubicIntersectionTest; index < tests_count; ++index) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +000023 int iIndex = static_cast<int>(index);
caryclarka35ab3e2016-10-20 08:32:18 -070024 const CubicPts& cubic1 = tests[index][0];
25 const CubicPts& cubic2 = tests[index][1];
26 SkDCubic c1, c2;
27 c1.debugSet(cubic1.fPts);
28 c2.debugSet(cubic2.fPts);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000029 SkReduceOrder reduce1, reduce2;
caryclarka35ab3e2016-10-20 08:32:18 -070030 int order1 = reduce1.reduce(c1, SkReduceOrder::kNo_Quadratics);
31 int order2 = reduce2.reduce(c2, SkReduceOrder::kNo_Quadratics);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000032 const bool showSkipped = false;
33 if (order1 < 4) {
34 if (showSkipped) {
35 SkDebugf("%s [%d] cubic1 order=%d\n", __FUNCTION__, iIndex, order1);
36 }
37 continue;
38 }
39 if (order2 < 4) {
40 if (showSkipped) {
41 SkDebugf("%s [%d] cubic2 order=%d\n", __FUNCTION__, iIndex, order2);
42 }
43 continue;
44 }
45 SkIntersections tIntersections;
caryclarka35ab3e2016-10-20 08:32:18 -070046 tIntersections.intersect(c1, c2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000047 if (!tIntersections.used()) {
48 if (showSkipped) {
49 SkDebugf("%s [%d] no intersection\n", __FUNCTION__, iIndex);
50 }
51 continue;
52 }
53 if (tIntersections.isCoincident(0)) {
54 if (showSkipped) {
55 SkDebugf("%s [%d] coincident\n", __FUNCTION__, iIndex);
56 }
57 continue;
58 }
59 for (int pt = 0; pt < tIntersections.used(); ++pt) {
60 double tt1 = tIntersections[0][pt];
caryclarka35ab3e2016-10-20 08:32:18 -070061 SkDPoint xy1 = c1.ptAtT(tt1);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000062 double tt2 = tIntersections[1][pt];
caryclarka35ab3e2016-10-20 08:32:18 -070063 SkDPoint xy2 = c2.ptAtT(tt2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000064 if (!xy1.approximatelyEqual(xy2)) {
65 SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
66 __FUNCTION__, (int)index, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY);
67 }
68 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
69 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000070 reporter->bumpTestCount();
caryclark@google.com9166dcb2013-04-08 11:50:00 +000071 }
72}
73
caryclarka35ab3e2016-10-20 08:32:18 -070074static const CubicPts testSet[] = {
caryclark@google.com9166dcb2013-04-08 11:50:00 +000075// FIXME: uncommenting these two will cause this to fail
76// this results in two curves very nearly but not exactly coincident
77#if 0
78{{{67.426548091427676, 37.993772624988935}, {23.483695892376684, 90.476863174921306},
79 {35.597065061143162, 79.872482633158796}, {75.38634169631932, 18.244890038969412}}},
80{{{67.4265481, 37.9937726}, {23.4836959, 90.4768632}, {35.5970651, 79.8724826},
81 {75.3863417, 18.24489}}},
82#endif
83
84{{{0, 0}, {0, 1}, {1, 1}, {1, 0}}},
85{{{1, 0}, {0, 0}, {0, 1}, {1, 1}}},
86
87{{{0, 1}, {4, 5}, {1, 0}, {5, 3}}},
88{{{0, 1}, {3, 5}, {1, 0}, {5, 4}}},
89
90{{{0, 1}, {1, 6}, {1, 0}, {1, 0}}},
91{{{0, 1}, {0, 1}, {1, 0}, {6, 1}}},
92
93{{{0, 1}, {3, 4}, {1, 0}, {5, 1}}},
94{{{0, 1}, {1, 5}, {1, 0}, {4, 3}}},
95
96{{{0, 1}, {1, 2}, {1, 0}, {6, 1}}},
97{{{0, 1}, {1, 6}, {1, 0}, {2, 1}}},
98
99{{{0, 1}, {0, 5}, {1, 0}, {4, 0}}},
100{{{0, 1}, {0, 4}, {1, 0}, {5, 0}}},
101
102{{{0, 1}, {3, 4}, {1, 0}, {3, 0}}},
103{{{0, 1}, {0, 3}, {1, 0}, {4, 3}}},
104
105{{{0, 0}, {1, 2}, {3, 4}, {4, 4}}},
106{{{0, 0}, {1, 2}, {3, 4}, {4, 4}}},
107{{{4, 4}, {3, 4}, {1, 2}, {0, 0}}},
108
109{{{0, 1}, {2, 3}, {1, 0}, {1, 0}}},
110{{{0, 1}, {0, 1}, {1, 0}, {3, 2}}},
111
112{{{0, 2}, {0, 1}, {1, 0}, {1, 0}}},
113{{{0, 1}, {0, 1}, {2, 0}, {1, 0}}},
114
115{{{0, 1}, {0, 2}, {1, 0}, {1, 0}}},
116{{{0, 1}, {0, 1}, {1, 0}, {2, 0}}},
117
118{{{0, 1}, {1, 6}, {1, 0}, {2, 0}}},
119{{{0, 1}, {0, 2}, {1, 0}, {6, 1}}},
120
121{{{0, 1}, {5, 6}, {1, 0}, {1, 0}}},
122{{{0, 1}, {0, 1}, {1, 0}, {6, 5}}},
123
124{{{95.837747722788592, 45.025976907939643}, {16.564570095652982, 0.72959763963222402},
125 {63.209855865319199, 68.047528419665767}, {57.640240647662544, 59.524565264361243}}},
126{{{51.593891741518817, 38.53849970667553}, {62.34752929878772, 74.924924725166022},
127 {74.810149322641152, 34.17966562983564}, {29.368398119401373, 94.66719277886078}}},
128
129{{{39.765160968417838, 33.060396198677083}, {5.1922921581157908, 66.854301452103215},
130 {31.619281802149157, 25.269248720849514}, {81.541621071073038, 70.025341524754353}}},
131{{{46.078911165743556, 48.259962651999651}, {20.24450549867214, 49.403916182650214},
132 {0.26325131778756683, 24.46489805563581}, {15.915006546264051, 83.515023059917155}}},
133
134{{{65.454505973241524, 93.881892270353575}, {45.867360264932437, 92.723972719499827},
135 {2.1464054482739447, 74.636369140183717}, {33.774068594804994, 40.770872887582925}}},
136{{{72.963387832494163, 95.659300729473728}, {11.809496633619768, 82.209921247423594},
137 {13.456139067865974, 57.329313623406605}, {36.060621606214262, 70.867335643091849}}},
138
139{{{32.484981432782945, 75.082940782924624}, {42.467313093350882, 48.131159948246157},
140 {3.5963115764764657, 43.208665839959245}, {79.442476890721579, 89.709102357602262}}},
141{{{18.98573861410177, 93.308887208490106}, {40.405250173250792, 91.039661826118675},
142 {8.0467721950480584, 42.100282172719147}, {40.883324221187891, 26.030185504830527}}},
143
144{{{7.5374809128872498, 82.441702896003477}, {22.444346930107265, 22.138854312775123},
145 {66.76091829629658, 50.753805856571446}, {78.193478508942519, 97.7932997968948}}},
146{{{97.700573130371311, 53.53260215070685}, {87.72443481149358, 84.575876772671876},
147 {19.215031396232092, 47.032676472809484}, {11.989686410869325, 10.659507480757082}}},
148
149{{{26.192053931854691, 9.8504326817814416}, {10.174241480498686, 98.476562741434464},
150 {21.177712558385782, 33.814968789841501}, {75.329030899018534, 55.02231980442177}}},
151{{{56.222082700683771, 24.54395039218662}, {95.589995289030483, 81.050822735322086},
152 {28.180450866082897, 28.837706255185282}, {60.128952916771617, 87.311672180570511}}},
153
154{{{42.449716172390481, 52.379709366885805}, {27.896043159019225, 48.797373636065686},
155 {92.770268299044233, 89.899302036454571}, {12.102066544863426, 99.43241951960718}}},
156{{{45.77532924980639, 45.958701495993274}, {37.458701356062065, 68.393691335056758},
157 {37.569326692060258, 27.673713456687381}, {60.674866037757539, 62.47349659096146}}},
158
159{{{67.426548091427676, 37.993772624988935}, {23.483695892376684, 90.476863174921306},
160 {35.597065061143162, 79.872482633158796}, {75.38634169631932, 18.244890038969412}}},
161{{{61.336508189019057, 82.693132843213675}, {44.639380902349664, 54.074825790745592},
162 {16.815615499771951, 20.049704667203923}, {41.866884958868326, 56.735503699973002}}},
163
164{{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945},
165 {18.5656052, 32.1268808}}},
166{{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981},
167 {56.4860195, 60.529264}}},
168};
169
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000170const int testSetCount = (int) SK_ARRAY_COUNT(testSet);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000171
caryclarka35ab3e2016-10-20 08:32:18 -0700172static const CubicPts newTestSet[] = {
Cary Clark4efcb7d2018-02-02 15:09:49 -0500173
caryclark27c015d2016-09-23 05:47:20 -0700174{ { { 130.0427549999999997, 11417.41309999999976 },{ 130.2331240000000037, 11418.3192999999992 },{ 131.0370790000000056, 11419 },{ 132, 11419 } } },
175{ { { 132, 11419 },{ 130.8954319999999996, 11419 },{ 130, 11418.10449999999946 },{ 130, 11417 } } },
Ben Wagner63fd7602017-10-09 15:45:33 -0400176
caryclark1049f122015-04-20 08:31:59 -0700177{{{1,3}, {-1.0564518,1.79032254}, {1.45265341,0.229448318}, {1.45381773,0.22913377}}},
178{{{1.45381773,0.22913377}, {1.45425761,0.229014933}, {1.0967741,0.451612949}, {0,1}}},
179
180{{{1.64551306f, 3.57876182f}, {0.298127174f, 3.70454836f}, {-0.809808373f, 6.39524937f}, {-3.66666651f, 13.333334f}}},
181{{{1, 2}, {1, 2}, {-3.66666651f, 13.333334f}, {5, 6}}},
182
183{{{0.0660428554,1.65340209}, {-0.251940489,1.43560803}, {-0.782382965,-0.196299091}, {3.33333325,-0.666666627}}},
184{{{1,3}, {-1.22353387,1.09411383}, {0.319867611,0.12996155}, {0.886705518,0.107543148}}},
185
186{{{-0.13654758,2.10514426}, {-0.585797966,1.89349782}, {-0.807703257,-0.192306399}, {6,-1}}},
187{{{1,4}, {-2.25000453,1.42241001}, {1.1314013,0.0505309105}, {1.87140274,0.0363764353}}},
188
189{{{1.3127951622009277, 2.0637707710266113}, {1.8210518360137939, 1.9148571491241455}, {1.6106204986572266, -0.68700540065765381}, {8.5, -2.5}}},
190{{{3, 4}, {0.33333325386047363, 1.3333332538604736}, {3.6666667461395264, -0.66666674613952637}, {3.6666665077209473, -0.66666656732559204}}},
191
caryclark54359292015-03-26 07:52:43 -0700192{{{980.026001,1481.276}, {980.026001,1481.276}, {980.02594,1481.27576}, {980.025879,1481.27527}}},
193{{{980.025879,1481.27527}, {980.025452,1481.27222}, {980.023743,1481.26038}, {980.02179,1481.24072}}},
194
195{{{1.80943513,3.07782435}, {1.66686702,2.16806936}, {1.68301272,0}, {3,0}}},
196{{{0,1}, {0,3}, {3,2}, {5,2}}},
197
198{{{3.4386673,2.66977954}, {4.06668949,2.17046738}, {4.78887367,1.59629118}, {6,2}}},
199{{{1.71985495,3.49467373}, {2.11620402,2.7201426}, {2.91897964,1.15138781}, {6,3}}},
200
201{{{0,1}, {0.392703831,1.78540766}, {0.219947904,2.05676103}, {0.218561709,2.05630541}}},
202{{{0.218561709,2.05630541}, {0.216418028,2.05560064}, {0.624105453,1.40486407}, {4.16666651,1.00000012}}},
203
204{{{0, 1}, {3, 5}, {2, 1}, {3, 1}}},
205{{{1.01366711f, 2.21379328f}, {1.09074128f, 2.23241305f}, {1.60246587f, 0.451849401f}, {5, 3}}},
206
207{{{0, 1}, {0.541499972f, 3.16599989f}, {1.08299994f, 2.69299984f}, {2.10083938f, 1.80391729f}}},
208{{{0.806384504f, 2.85426903f}, {1.52740121f, 1.99355423f}, {2.81689167f, 0.454222918f}, {5, 1}}},
209
210{{{0, 1}, {1.90192389f, 2.90192389f}, {2.59807634f, 2.79422879f}, {3.1076951f, 2.71539044f}}},
211{{{2, 3}, {2.36602545f, 3.36602545f}, {2.330127f, 3.06217766f}, {2.28460979f, 2.67691422f}}},
212
213{{{0, 1}, {1.90192389f, 2.90192389f}, {2.59807634f, 2.79422879f}, {3.1076951f, 2.71539044f}}},
214{{{2.28460979f, 2.67691422f}, {2.20577145f, 2.00961876f}, {2.09807634f, 1.09807622f}, {4, 3}}},
215
216{{{0, 1}, {0.8211091160774231, 2.0948121547698975}, {0.91805583238601685, 2.515404224395752}, {0.91621249914169312, 2.5146586894989014}}},
217{{{0.91621249914169312, 2.5146586894989014}, {0.91132104396820068, 2.5126807689666748}, {0.21079301834106445, -0.45617169141769409}, {10.5, -1.6666665077209473}}},
218
219{{{42.6237564,68.9841232}, {32.449646,81.963089}, {14.7713947,103.565269}, {12.6310005,105.247002}}},
220{{{37.2640038,95.3540039}, {37.2640038,95.3540039}, {11.3710003,83.7339935}, {-25.0779991,124.912003}}},
221
222{{{0,1}, {4,5}, {6,0}, {1,0}}},
223{{{0,6}, {0,1}, {1,0}, {5,4}}},
224
225{{{0,1}, {4,6}, {5,1}, {6,2}}},
226{{{1,5}, {2,6}, {1,0}, {6,4}}},
227
228{{{322, 896.04803466796875}, {314.09201049804687, 833.4376220703125}, {260.24713134765625, 785}, {195, 785}}},
229{{{195, 785}, {265.14016723632812, 785}, {322, 842.30755615234375}, {322, 913}}},
230
231{{{1, 4}, {4, 5}, {3, 2}, {6, 3}}},
232{{{2, 3}, {3, 6}, {4, 1}, {5, 4}}},
233
234{{{67, 913}, {67, 917.388916015625}, {67.224380493164063, 921.72576904296875}, {67.662384033203125, 926}}},
235{{{194, 1041}, {123.85984039306641, 1041}, {67, 983.69244384765625}, {67, 913}}},
236
237{{{1,4}, {1,5}, {6,0}, {5,1}}},
238{{{0,6}, {1,5}, {4,1}, {5,1}}},
239
240{{{0,1}, {4,5}, {6,0}, {1,0}}},
241{{{0,6}, {0,1}, {1,0}, {5,4}}},
242
243{{{0,1}, {4,6}, {2,0}, {2,0}}},
244{{{0,2}, {0,2}, {1,0}, {6,4}}},
245
caryclarkdac1d172014-06-17 05:15:38 -0700246{{{980.9000244140625, 1474.3280029296875}, {980.9000244140625, 1474.3280029296875}, {978.89300537109375, 1471.95703125}, {981.791015625, 1469.487060546875}}},
247{{{981.791015625, 1469.487060546875}, {981.791015625, 1469.4859619140625}, {983.3580322265625, 1472.72900390625}, {980.9000244140625, 1474.3280029296875}}},
248
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000249{{{275,532}, {277.209137,532}, {279,530.209106}, {279,528}}},
250{{{278,529}, {278,530.65686}, {276.65686,532}, {275,532}}},
251
skia.committer@gmail.comb0a05892013-10-03 07:01:37 +0000252#if 0 // FIXME: asserts coincidence, not working yet
253{{{195, 785}, {124.30755615234375, 785}, {67, 841.85986328125}, {67, 912}}},
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000254{{{67, 913}, {67, 842.30755615234375}, {123.85984039306641, 785}, {194, 785}}},
255#endif
256
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000257{{{149,710.001465}, {149.000809,712.209961}, {150.791367,714}, {153,714}}},
258{{{154,715}, {151.238571,715}, {149,712.761414}, {149,710}}},
259
260{{{1,2}, {1,2}, {2,0}, {6,0}}},
261{{{0,2}, {0,6}, {2,1}, {2,1}}},
262
263{{{0,1}, {2,3}, {5,1}, {4,3}}},
264{{{1,5}, {3,4}, {1,0}, {3,2}}},
265
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000266{{{399,657}, {399,661.970581}, {403.029449,666}, {408,666}}},
267{{{406,666}, {402.686279,666}, {400,663.313721}, {400,660}}},
268
269{{{0,5}, {3,5}, {3,0}, {3,2}}},
270{{{0,3}, {2,3}, {5,0}, {5,3}}},
271
caryclark@google.com570863f2013-09-16 15:55:01 +0000272{{{132, 11419}, {130.89543151855469, 11419}, {130, 11418.1044921875}, {130, 11417}}},
273
skia.committer@gmail.com7f1af502013-07-24 07:01:12 +0000274{{{3, 4}, {1, 5}, {4, 3}, {6, 4}}},
275{{{3, 4}, {4, 6}, {4, 3}, {5, 1}}},
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000276
skia.committer@gmail.com7f1af502013-07-24 07:01:12 +0000277{{{130.04275512695312, 11417.413085937500 },
278 {130.23312377929687, 11418.319335937500 },
279 {131.03707885742187, 11419.000000000000 },
280 {132.00000000000000, 11419.000000000000 }}},
281
282{{{132.00000000000000, 11419.000000000000 },
283 {130.89543151855469, 11419.000000000000 },
284 {130.00000000000000, 11418.104492187500 },
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000285 {130.00000000000000, 11417.000000000000 }}},
286
robertphillips@google.com8dcea7d2013-07-15 15:38:55 +0000287{{{1.0516976506771041, 2.9684399028541346 },
288 {1.0604363140895228, 2.9633503074444141 },
289 {1.0692548215065762, 2.9580354426587459 },
290 {1.0781560339512140, 2.9525043684031349 }}},
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000291
robertphillips@google.com8dcea7d2013-07-15 15:38:55 +0000292{{{1.0523038101345104, 2.9523755204833737 },
293 {1.0607035288264237, 2.9580853881628375 },
294 {1.0690530472271964, 2.9633896794787749 },
295 {1.0773566568712512, 2.9682969775000219 }}},
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000296
robertphillips@google.com8dcea7d2013-07-15 15:38:55 +0000297{{{1.0386522625066592, 2.9759024812329078 },
298 {1.0559713690392631, 2.9661782500838885 },
299 {1.0736041309019990, 2.9555348259177858 },
300 {1.0915734362784633, 2.9440446879826569 }}},
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000301
robertphillips@google.com8dcea7d2013-07-15 15:38:55 +0000302{{{1.0396670794879301, 2.9435062123457261 },
303 {1.0565690546812769, 2.9557413250983462 },
304 {1.0732616463413533, 2.9663369676594282 },
305 {1.0897791867435489, 2.9753618045797472 }}},
306
307{{{0.8685656183311091, 3.0409266475785208 },
308 {0.99189542936395292, 3.0212163698184424 },
309 {1.1302108367493320, 2.9265646471747306 },
310 {1.2952305904872474, 2.7940808546473788 }}},
311
312{{{0.85437872843682727, 2.7536036928549055 },
313 {1.0045584590592620, 2.9493041024831705 },
314 {1.1336998329885613, 3.0248027987251747 },
315 {1.2593809752247314, 3.0152560315809107 }}},
316
317{{{0, 1}, {1, 6}, {1, 0}, {6, 2}}},
318{{{0, 1}, {2, 6}, {1, 0}, {6, 1}}},
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000319
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000320{{{134,11414}, {131.990234375,11414}, {130.32666015625,11415.482421875}, {130.04275512695312,11417.4130859375}}},
321{{{132,11419}, {130.89543151855469,11419}, {130,11418.1044921875}, {130,11417}}},
322
323{{{132,11419}, {130.89543151855469,11419}, {130,11418.1044921875}, {130,11417}}},
324{{{130.04275512695312,11417.4130859375}, {130.23312377929687,11418.3193359375}, {131.03707885742187,11419}, {132,11419}}},
325
caryclark@google.coma5e55922013-05-07 18:51:31 +0000326{{{0, 1}, {2, 3}, {5, 1}, {4, 3}}},
327{{{1, 5}, {3, 4}, {1, 0}, {3, 2}}},
328
caryclark@google.comb3f09212013-04-17 15:49:16 +0000329{{{3, 5}, {1, 6}, {5, 0}, {3, 1}}},
330{{{0, 5}, {1, 3}, {5, 3}, {6, 1}}},
331
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000332{{{0, 1}, {1, 5}, {1, 0}, {1, 0}}},
333{{{0, 1}, {0, 1}, {1, 0}, {5, 1}}},
334
335{{{1, 3}, {5, 6}, {5, 3}, {5, 4}}},
336{{{3, 5}, {4, 5}, {3, 1}, {6, 5}}},
337
338{{{0, 5}, {0, 5}, {5, 4}, {6, 4}}},
339{{{4, 5}, {4, 6}, {5, 0}, {5, 0}}},
340
341{{{0, 4}, {1, 3}, {5, 4}, {4, 2}}},
342{{{4, 5}, {2, 4}, {4, 0}, {3, 1}}},
343
344{{{0, 2}, {1, 5}, {3, 2}, {4, 1}}},
345{{{2, 3}, {1, 4}, {2, 0}, {5, 1}}},
346
347{{{0, 2}, {2, 3}, {5, 1}, {3, 2}}},
348{{{1, 5}, {2, 3}, {2, 0}, {3, 2}}},
349
350{{{2, 6}, {4, 5}, {1, 0}, {6, 1}}},
351{{{0, 1}, {1, 6}, {6, 2}, {5, 4}}},
352
353{{{0, 1}, {1, 2}, {6, 5}, {5, 4}}},
354{{{5, 6}, {4, 5}, {1, 0}, {2, 1}}},
355
356{{{2.5119999999999996, 1.5710000000000002}, {2.6399999999999983, 1.6599999999999997},
357 {2.8000000000000007, 1.8000000000000003}, {3, 2}}},
358{{{2.4181876227114887, 1.9849772580462195}, {2.8269904869227211, 2.009330650246834},
359 {3.2004679292461624, 1.9942047174679169}, {3.4986199496818058, 2.0035994597094731}}},
360
361{{{2, 3}, {1, 4}, {1, 0}, {6, 0}}},
362{{{0, 1}, {0, 6}, {3, 2}, {4, 1}}},
363
364{{{0, 2}, {1, 5}, {1, 0}, {6, 1}}},
365{{{0, 1}, {1, 6}, {2, 0}, {5, 1}}},
366
367{{{0, 1}, {1, 5}, {2, 1}, {4, 0}}},
368{{{1, 2}, {0, 4}, {1, 0}, {5, 1}}},
369
370{{{0, 1}, {3, 5}, {2, 1}, {3, 1}}},
371{{{1, 2}, {1, 3}, {1, 0}, {5, 3}}},
372
373{{{0, 1}, {2, 5}, {6, 0}, {5, 3}}},
374{{{0, 6}, {3, 5}, {1, 0}, {5, 2}}},
375
376{{{0, 1}, {3, 6}, {1, 0}, {5, 2}}},
377{{{0, 1}, {2, 5}, {1, 0}, {6, 3}}},
378
379{{{1, 2}, {5, 6}, {1, 0}, {1, 0}}},
380{{{0, 1}, {0, 1}, {2, 1}, {6, 5}}},
381
382{{{0, 6}, {1, 2}, {1, 0}, {1, 0}}},
383{{{0, 1}, {0, 1}, {6, 0}, {2, 1}}},
384
385{{{0, 2}, {0, 1}, {3, 0}, {1, 0}}},
386{{{0, 3}, {0, 1}, {2, 0}, {1, 0}}},
387};
388
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000389const int newTestSetCount = (int) SK_ARRAY_COUNT(newTestSet);
caryclarka35ab3e2016-10-20 08:32:18 -0700390static void oneOff(skiatest::Reporter* reporter, const CubicPts& cubic1, const CubicPts& cubic2,
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000391 bool coin) {
caryclarka35ab3e2016-10-20 08:32:18 -0700392 SkDCubic c1, c2;
393 c1.debugSet(cubic1.fPts);
394 c2.debugSet(cubic2.fPts);
395 SkASSERT(ValidCubic(c1));
396 SkASSERT(ValidCubic(c2));
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000397#if ONE_OFF_DEBUG
398 SkDebugf("computed quadratics given\n");
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000399 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000400 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY,
401 cubic1[2].fX, cubic1[2].fY, cubic1[3].fX, cubic1[3].fY);
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000402 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000403 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY,
404 cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY);
405#endif
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000406 SkIntersections intersections;
caryclarka35ab3e2016-10-20 08:32:18 -0700407 intersections.intersect(c1, c2);
caryclark54359292015-03-26 07:52:43 -0700408#if DEBUG_T_SECT_DUMP == 3
409 SkDebugf("</div>\n\n");
410 SkDebugf("<script type=\"text/javascript\">\n\n");
411 SkDebugf("var testDivs = [\n");
412 for (int index = 1; index <= gDumpTSectNum; ++index) {
413 SkDebugf("sect%d,\n", index);
414 }
415#endif
caryclark6c3b9cd2016-09-26 05:36:58 -0700416 REPORTER_ASSERT(reporter, !coin || intersections.used() >= 2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000417 double tt1, tt2;
418 SkDPoint xy1, xy2;
419 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) {
420 tt1 = intersections[0][pt3];
caryclarka35ab3e2016-10-20 08:32:18 -0700421 xy1 = c1.ptAtT(tt1);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000422 tt2 = intersections[1][pt3];
caryclarka35ab3e2016-10-20 08:32:18 -0700423 xy2 = c2.ptAtT(tt2);
caryclark@google.com5ec2b1e2013-07-15 20:50:24 +0000424 const SkDPoint& iPt = intersections.pt(pt3);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000425#if ONE_OFF_DEBUG
426 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1.9g\n",
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000427 __FUNCTION__, tt1, xy1.fX, xy1.fY, iPt.fX,
428 iPt.fY, xy2.fX, xy2.fY, tt2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000429#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000430 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(iPt));
431 REPORTER_ASSERT(reporter, xy2.approximatelyEqual(iPt));
432 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000433 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000434 reporter->bumpTestCount();
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000435}
436
437static void oneOff(skiatest::Reporter* reporter, int outer, int inner) {
caryclarka35ab3e2016-10-20 08:32:18 -0700438 const CubicPts& cubic1 = testSet[outer];
439 const CubicPts& cubic2 = testSet[inner];
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000440 oneOff(reporter, cubic1, cubic2, false);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000441}
442
443static void newOneOff(skiatest::Reporter* reporter, int outer, int inner) {
caryclarka35ab3e2016-10-20 08:32:18 -0700444 const CubicPts& cubic1 = newTestSet[outer];
445 const CubicPts& cubic2 = newTestSet[inner];
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000446 oneOff(reporter, cubic1, cubic2, false);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000447}
448
caryclark26ad22a2015-10-16 09:03:38 -0700449static void testsOneOff(skiatest::Reporter* reporter, int index) {
caryclarka35ab3e2016-10-20 08:32:18 -0700450 const CubicPts& cubic1 = tests[index][0];
451 const CubicPts& cubic2 = tests[index][1];
caryclark26ad22a2015-10-16 09:03:38 -0700452 oneOff(reporter, cubic1, cubic2, false);
453}
454
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000455static void oneOffTests(skiatest::Reporter* reporter) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000456 for (int outer = 0; outer < testSetCount - 1; ++outer) {
457 for (int inner = outer + 1; inner < testSetCount; ++inner) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000458 oneOff(reporter, outer, inner);
459 }
460 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000461 for (int outer = 0; outer < newTestSetCount - 1; ++outer) {
462 for (int inner = outer + 1; inner < newTestSetCount; ++inner) {
caryclark@google.com5ec2b1e2013-07-15 20:50:24 +0000463 newOneOff(reporter, outer, inner);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000464 }
465 }
466}
467
468#define DEBUG_CRASH 0
469
470static void CubicIntersection_RandTest(skiatest::Reporter* reporter) {
471 srand(0);
John Stiles97659732021-08-12 10:48:09 -0400472 const int kNumTests = 10000000;
caryclark@google.comdb60de72013-04-11 12:33:23 +0000473#if !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_ANDROID)
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000474 unsigned seed = 0;
475#endif
John Stiles97659732021-08-12 10:48:09 -0400476 for (int test = 0; test < kNumTests; ++test) {
caryclarka35ab3e2016-10-20 08:32:18 -0700477 CubicPts cubic1, cubic2;
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000478 for (int i = 0; i < 4; ++i) {
caryclarka35ab3e2016-10-20 08:32:18 -0700479 cubic1.fPts[i].fX = static_cast<double>(SK_RAND(seed)) / RAND_MAX * 100;
480 cubic1.fPts[i].fY = static_cast<double>(SK_RAND(seed)) / RAND_MAX * 100;
481 cubic2.fPts[i].fX = static_cast<double>(SK_RAND(seed)) / RAND_MAX * 100;
482 cubic2.fPts[i].fY = static_cast<double>(SK_RAND(seed)) / RAND_MAX * 100;
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000483 }
484 #if DEBUG_CRASH
485 char str[1024];
486 snprintf(str, sizeof(str),
487 "{{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}}},\n"
488 "{{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}}},\n",
489 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY, cubic1[2].fX, cubic1[2].fY,
490 cubic1[3].fX, cubic1[3].fY,
491 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY, cubic2[2].fX, cubic2[2].fY,
492 cubic2[3].fX, cubic2[3].fY);
493 #endif
494 SkDRect rect1, rect2;
caryclarka35ab3e2016-10-20 08:32:18 -0700495 SkDCubic c1, c2;
496 c1.debugSet(cubic1.fPts);
497 c2.debugSet(cubic2.fPts);
498 rect1.setBounds(c1);
499 rect2.setBounds(c2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000500 bool boundsIntersect = rect1.fLeft <= rect2.fRight && rect2.fLeft <= rect2.fRight
501 && rect1.fTop <= rect2.fBottom && rect2.fTop <= rect1.fBottom;
502 if (test == -1) {
503 SkDebugf("ready...\n");
504 }
505 SkIntersections intersections2;
caryclarka35ab3e2016-10-20 08:32:18 -0700506 int newIntersects = intersections2.intersect(c1, c2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000507 if (!boundsIntersect && newIntersects) {
508 #if DEBUG_CRASH
509 SkDebugf("%s %d unexpected intersection boundsIntersect=%d "
510 " newIntersects=%d\n%s %s\n", __FUNCTION__, test, boundsIntersect,
511 newIntersects, __FUNCTION__, str);
512 #endif
513 REPORTER_ASSERT(reporter, 0);
514 }
515 for (int pt = 0; pt < intersections2.used(); ++pt) {
516 double tt1 = intersections2[0][pt];
caryclarka35ab3e2016-10-20 08:32:18 -0700517 SkDPoint xy1 = c1.ptAtT(tt1);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000518 double tt2 = intersections2[1][pt];
caryclarka35ab3e2016-10-20 08:32:18 -0700519 SkDPoint xy2 = c2.ptAtT(tt2);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000520 REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2));
521 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000522 reporter->bumpTestCount();
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000523 }
524}
525
526static void intersectionFinder(int index0, int index1, double t1Seed, double t2Seed,
527 double t1Step, double t2Step) {
caryclarka35ab3e2016-10-20 08:32:18 -0700528 const CubicPts& cubic1 = newTestSet[index0];
529 const CubicPts& cubic2 = newTestSet[index1];
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000530 SkDPoint t1[3], t2[3];
531 bool toggle = true;
caryclarka35ab3e2016-10-20 08:32:18 -0700532 SkDCubic c1, c2;
533 c1.debugSet(cubic1.fPts);
534 c2.debugSet(cubic2.fPts);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000535 do {
caryclarka35ab3e2016-10-20 08:32:18 -0700536 t1[0] = c1.ptAtT(t1Seed - t1Step);
537 t1[1] = c1.ptAtT(t1Seed);
538 t1[2] = c1.ptAtT(t1Seed + t1Step);
539 t2[0] = c2.ptAtT(t2Seed - t2Step);
540 t2[1] = c2.ptAtT(t2Seed);
541 t2[2] = c2.ptAtT(t2Seed + t2Step);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000542 double dist[3][3];
543 dist[1][1] = t1[1].distance(t2[1]);
544 int best_i = 1, best_j = 1;
545 for (int i = 0; i < 3; ++i) {
546 for (int j = 0; j < 3; ++j) {
547 if (i == 1 && j == 1) {
548 continue;
549 }
550 dist[i][j] = t1[i].distance(t2[j]);
551 if (dist[best_i][best_j] > dist[i][j]) {
552 best_i = i;
553 best_j = j;
554 }
555 }
556 }
557 if (best_i == 0) {
558 t1Seed -= t1Step;
559 } else if (best_i == 2) {
560 t1Seed += t1Step;
561 }
562 if (best_j == 0) {
563 t2Seed -= t2Step;
564 } else if (best_j == 2) {
565 t2Seed += t2Step;
566 }
567 if (best_i == 1 && best_j == 1) {
568 if ((toggle ^= true)) {
569 t1Step /= 2;
570 } else {
571 t2Step /= 2;
572 }
573 }
574 } while (!t1[1].approximatelyEqual(t2[1]));
575 t1Step = t2Step = 0.1;
576 double t10 = t1Seed - t1Step * 2;
577 double t12 = t1Seed + t1Step * 2;
578 double t20 = t2Seed - t2Step * 2;
579 double t22 = t2Seed + t2Step * 2;
580 SkDPoint test;
581 while (!approximately_zero(t1Step)) {
caryclarka35ab3e2016-10-20 08:32:18 -0700582 test = c1.ptAtT(t10);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000583 t10 += t1[1].approximatelyEqual(test) ? -t1Step : t1Step;
584 t1Step /= 2;
585 }
586 t1Step = 0.1;
587 while (!approximately_zero(t1Step)) {
caryclarka35ab3e2016-10-20 08:32:18 -0700588 test = c1.ptAtT(t12);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000589 t12 -= t1[1].approximatelyEqual(test) ? -t1Step : t1Step;
590 t1Step /= 2;
591 }
592 while (!approximately_zero(t2Step)) {
caryclarka35ab3e2016-10-20 08:32:18 -0700593 test = c2.ptAtT(t20);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000594 t20 += t2[1].approximatelyEqual(test) ? -t2Step : t2Step;
595 t2Step /= 2;
596 }
597 t2Step = 0.1;
598 while (!approximately_zero(t2Step)) {
caryclarka35ab3e2016-10-20 08:32:18 -0700599 test = c2.ptAtT(t22);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000600 t22 -= t2[1].approximatelyEqual(test) ? -t2Step : t2Step;
601 t2Step /= 2;
602 }
603#if ONE_OFF_DEBUG
604 SkDebugf("%s t1=(%1.9g<%1.9g<%1.9g) t2=(%1.9g<%1.9g<%1.9g)\n", __FUNCTION__,
605 t10, t1Seed, t12, t20, t2Seed, t22);
caryclarka35ab3e2016-10-20 08:32:18 -0700606 SkDPoint p10 = c1.ptAtT(t10);
607 SkDPoint p1Seed = c1.ptAtT(t1Seed);
608 SkDPoint p12 = c1.ptAtT(t12);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000609 SkDebugf("%s p1=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__,
610 p10.fX, p10.fY, p1Seed.fX, p1Seed.fY, p12.fX, p12.fY);
caryclarka35ab3e2016-10-20 08:32:18 -0700611 SkDPoint p20 = c2.ptAtT(t20);
612 SkDPoint p2Seed = c2.ptAtT(t2Seed);
613 SkDPoint p22 = c2.ptAtT(t22);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000614 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__,
615 p20.fX, p20.fY, p2Seed.fX, p2Seed.fY, p22.fX, p22.fY);
616#endif
617}
618
619static void CubicIntersection_IntersectionFinder() {
620// double t1Seed = 0.87;
621// double t2Seed = 0.87;
622 double t1Step = 0.000001;
623 double t2Step = 0.000001;
624 intersectionFinder(0, 1, 0.855895664, 0.864850875, t1Step, t2Step);
625 intersectionFinder(0, 1, 0.865207906, 0.865207887, t1Step, t2Step);
626 intersectionFinder(0, 1, 0.865213351, 0.865208087, t1Step, t2Step);
627}
628
caryclarka35ab3e2016-10-20 08:32:18 -0700629static const CubicPts selfSet[] = {
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000630 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}},
631 {{{3, 6}, {2, 3}, {4, 0}, {3, 2}}},
632 {{{0, 2}, {2, 3}, {5, 1}, {3, 2}}},
633 {{{0, 2}, {3, 5}, {5, 0}, {4, 2}}},
634 {{{3.34, 8.98}, {1.95, 10.27}, {3.76, 7.65}, {4.96, 10.64}}},
635 {{{3.13, 2.74}, {1.08, 4.62}, {3.71, 0.94}, {2.01, 3.81}}},
636 {{{6.71, 3.14}, {7.99, 2.75}, {8.27, 1.96}, {6.35, 3.57}}},
637 {{{12.81, 7.27}, {7.22, 6.98}, {12.49, 8.97}, {11.42, 6.18}}},
638};
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000639
640int selfSetCount = (int) SK_ARRAY_COUNT(selfSet);
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000641
John Stiles97659732021-08-12 10:48:09 -0400642static void selfOneOff(skiatest::Reporter* reporter, int setIdx) {
643 const CubicPts& cubic = selfSet[setIdx];
caryclark54359292015-03-26 07:52:43 -0700644 SkPoint c[4];
645 for (int i = 0; i < 4; ++i) {
caryclarka35ab3e2016-10-20 08:32:18 -0700646 c[i] = cubic.fPts[i].asSkPoint();
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000647 }
Cary Clark7eb01e02016-12-08 14:36:32 -0500648 SkScalar loopT[3];
Chris Daltonfebbffa2017-06-08 13:12:02 -0600649 SkCubicType cubicType = SkClassifyCubic(c);
Cary Clark7eb01e02016-12-08 14:36:32 -0500650 int breaks = SkDCubic::ComplexBreak(c, loopT);
651 SkASSERT(breaks < 2);
Chris Dalton43436542017-04-13 14:26:00 -0600652 if (breaks && cubicType == SkCubicType::kLoop) {
caryclark54359292015-03-26 07:52:43 -0700653 SkIntersections i;
654 SkPoint twoCubics[7];
Cary Clark7eb01e02016-12-08 14:36:32 -0500655 SkChopCubicAt(c, twoCubics, loopT[0]);
caryclark54359292015-03-26 07:52:43 -0700656 SkDCubic chopped[2];
657 chopped[0].set(&twoCubics[0]);
658 chopped[1].set(&twoCubics[3]);
659 int result = i.intersect(chopped[0], chopped[1]);
660 REPORTER_ASSERT(reporter, result == 2);
661 REPORTER_ASSERT(reporter, i.used() == 2);
662 for (int index = 0; index < result; ++index) {
663 SkDPoint pt1 = chopped[0].ptAtT(i[0][index]);
664 SkDPoint pt2 = chopped[1].ptAtT(i[1][index]);
665 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2));
666 reporter->bumpTestCount();
667 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000668 }
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000669}
670
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000671static void cubicIntersectionSelfTest(skiatest::Reporter* reporter) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000672 int firstFail = 0;
673 for (int index = firstFail; index < selfSetCount; ++index) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000674 selfOneOff(reporter, index);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000675 }
676}
677
caryclarka35ab3e2016-10-20 08:32:18 -0700678static const CubicPts coinSet[] = {
caryclark26ad22a2015-10-16 09:03:38 -0700679 {{{72.350448608398438, 27.966041564941406}, {72.58441162109375, 27.861515045166016},
680 {72.818222045898437, 27.756658554077148}, {73.394996643066406, 27.49799919128418}}},
681 {{{73.394996643066406, 27.49799919128418}, {72.818222045898437, 27.756658554077148},
682 {72.58441162109375, 27.861515045166016}, {72.350448608398438, 27.966041564941406}}},
683
caryclark94c902e2015-08-18 07:12:43 -0700684 {{{297.04998779296875, 43.928997039794922}, {297.04998779296875, 43.928997039794922},
685 {300.69699096679688, 45.391998291015625}, {306.92498779296875, 43.08599853515625}}},
686 {{{297.04998779296875, 43.928997039794922}, {297.04998779296875, 43.928997039794922},
687 {300.69699096679688, 45.391998291015625}, {306.92498779296875, 43.08599853515625}}},
688
caryclark54359292015-03-26 07:52:43 -0700689 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}},
690 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}},
691
skia.committer@gmail.comb0a05892013-10-03 07:01:37 +0000692 {{{317, 711}, {322.52285766601562, 711}, {327, 715.4771728515625}, {327, 721}}},
693 {{{324.07107543945312, 713.928955078125}, {324.4051513671875, 714.26300048828125},
694 {324.71566772460937, 714.62060546875}, {325, 714.9990234375}}},
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000695};
696
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000697static int coinSetCount = (int) SK_ARRAY_COUNT(coinSet);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000698
699static void coinOneOff(skiatest::Reporter* reporter, int index) {
caryclarka35ab3e2016-10-20 08:32:18 -0700700 const CubicPts& cubic1 = coinSet[index];
701 const CubicPts& cubic2 = coinSet[index + 1];
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000702 oneOff(reporter, cubic1, cubic2, true);
703}
704
705static void cubicIntersectionCoinTest(skiatest::Reporter* reporter) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000706 int firstFail = 0;
707 for (int index = firstFail; index < coinSetCount; index += 2) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000708 coinOneOff(reporter, index);
709 }
710}
711
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000712DEF_TEST(PathOpsCubicCoinOneOff, reporter) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000713 coinOneOff(reporter, 0);
714}
715
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000716DEF_TEST(PathOpsCubicIntersectionOneOff, reporter) {
caryclark27c015d2016-09-23 05:47:20 -0700717 newOneOff(reporter, 0, 1);
caryclark26ad22a2015-10-16 09:03:38 -0700718}
719
720DEF_TEST(PathOpsCubicIntersectionTestsOneOff, reporter) {
721 testsOneOff(reporter, 10);
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000722}
723
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000724DEF_TEST(PathOpsCubicSelfOneOff, reporter) {
caryclark@google.com4fdbb222013-07-23 15:27:41 +0000725 selfOneOff(reporter, 0);
caryclark@google.comfa2aeee2013-07-15 13:29:13 +0000726}
727
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000728DEF_TEST(PathOpsCubicIntersection, reporter) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000729 oneOffTests(reporter);
730 cubicIntersectionSelfTest(reporter);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000731 cubicIntersectionCoinTest(reporter);
caryclark@google.com9166dcb2013-04-08 11:50:00 +0000732 standardTestCases(reporter);
733 if (false) CubicIntersection_IntersectionFinder();
734 if (false) CubicIntersection_RandTest(reporter);
735}