blob: 9662eb8379746d3d8dc2c575f17b26584f71b8db [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +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 */
caryclark@google.comc6825902012-02-03 22:07:47 +00007#include "CurveIntersection.h"
caryclark@google.com8dcf1142012-07-02 20:27:02 +00008#include "CurveUtilities.h"
caryclark@google.com639df892012-01-10 21:46:10 +00009#include "CubicIntersection_TestData.h"
caryclark@google.com27accef2012-01-25 18:57:23 +000010#include "Intersection_Tests.h"
caryclark@google.com639df892012-01-10 21:46:10 +000011#include "Intersections.h"
12#include "TestUtilities.h"
13
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +000014#define SHOW_ORIGINAL 1
15
caryclark@google.com639df892012-01-10 21:46:10 +000016const int firstCubicIntersectionTest = 9;
17
caryclark@google.com45a8fc62013-02-14 15:29:11 +000018static void standardTestCases() {
caryclark@google.com639df892012-01-10 21:46:10 +000019 for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) {
20 const Cubic& cubic1 = tests[index][0];
21 const Cubic& cubic2 = tests[index][1];
22 Cubic reduce1, reduce2;
caryclark@google.com47d73da2013-02-17 01:41:25 +000023 int order1 = reduceOrder(cubic1, reduce1, kReduceOrder_NoQuadraticsAllowed,
24 kReduceOrder_TreatAsFill);
25 int order2 = reduceOrder(cubic2, reduce2, kReduceOrder_NoQuadraticsAllowed,
26 kReduceOrder_TreatAsFill);
caryclark@google.com639df892012-01-10 21:46:10 +000027 if (order1 < 4) {
caryclark@google.com27accef2012-01-25 18:57:23 +000028 printf("%s [%d] cubic1 order=%d\n", __FUNCTION__, (int) index, order1);
29 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000030 }
31 if (order2 < 4) {
caryclark@google.com27accef2012-01-25 18:57:23 +000032 printf("%s [%d] cubic2 order=%d\n", __FUNCTION__, (int) index, order2);
33 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000034 }
caryclark@google.com27accef2012-01-25 18:57:23 +000035 if (implicit_matches(reduce1, reduce2)) {
36 printf("%s [%d] coincident\n", __FUNCTION__, (int) index);
37 continue;
38 }
39 Intersections tIntersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000040 intersect(reduce1, reduce2, tIntersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000041 if (!tIntersections.intersected()) {
42 printf("%s [%d] no intersection\n", __FUNCTION__, (int) index);
43 continue;
44 }
45 for (int pt = 0; pt < tIntersections.used(); ++pt) {
46 double tt1 = tIntersections.fT[0][pt];
47 double tx1, ty1;
48 xy_at_t(cubic1, tt1, tx1, ty1);
49 double tt2 = tIntersections.fT[1][pt];
50 double tx2, ty2;
51 xy_at_t(cubic2, tt2, tx2, ty2);
caryclark@google.com6d0032a2013-01-04 19:41:13 +000052 if (!AlmostEqualUlps(tx1, tx2)) {
caryclark@google.com27accef2012-01-25 18:57:23 +000053 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
54 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
55 }
caryclark@google.com6d0032a2013-01-04 19:41:13 +000056 if (!AlmostEqualUlps(ty1, ty2)) {
caryclark@google.com27accef2012-01-25 18:57:23 +000057 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
58 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
caryclark@google.com639df892012-01-10 21:46:10 +000059 }
60 }
61 }
62}
caryclark@google.com73ca6242013-01-17 21:02:47 +000063
caryclark@google.com73ca6242013-01-17 21:02:47 +000064static const Cubic testSet[] = {
caryclark@google.com45a8fc62013-02-14 15:29:11 +000065{{0,1}, {4,5}, {1,0}, {5,3}},
66{{0,1}, {3,5}, {1,0}, {5,4}},
67
68{{0, 1}, {1, 6}, {1, 0}, {1, 0}},
69{{0, 1}, {0, 1}, {1, 0}, {6, 1}},
70
71{{0,1}, {3,4}, {1,0}, {5,1}},
72{{0,1}, {1,5}, {1,0}, {4,3}},
73
74{{0,1}, {1,2}, {1,0}, {6,1}},
75{{0,1}, {1,6}, {1,0}, {2,1}},
76
skia.committer@gmail.com044679e2013-02-15 07:16:57 +000077{{0,1}, {0,5}, {1,0}, {4,0}},
caryclark@google.com45a8fc62013-02-14 15:29:11 +000078{{0,1}, {0,4}, {1,0}, {5,0}},
79
caryclark@google.combeda3892013-02-07 13:13:41 +000080{{0,1}, {3,4}, {1,0}, {3,0}},
81{{0,1}, {0,3}, {1,0}, {4,3}},
82
83{{0, 0}, {1, 2}, {3, 4}, {4, 4}},
84{{0, 0}, {1, 2}, {3, 4}, {4, 4}},
85{{4, 4}, {3, 4}, {1, 2}, {0, 0}},
86
87{{0,1}, {2,3}, {1,0}, {1,0}},
88{{0,1}, {0,1}, {1,0}, {3,2}},
89
90{{0,2}, {0,1}, {1,0}, {1,0}},
91{{0,1}, {0,1}, {2,0}, {1,0}},
92
caryclark@google.comf9502d72013-02-04 14:06:49 +000093{{0, 0}, {0, 1}, {1, 1}, {1, 0}},
94{{1, 0}, {0, 0}, {0, 1}, {1, 1}},
95
caryclark@google.comaa358312013-01-29 20:28:49 +000096{{0, 1}, {0, 2}, {1, 0}, {1, 0}},
97{{0, 1}, {0, 1}, {1, 0}, {2, 0}},
98
caryclark@google.comf9502d72013-02-04 14:06:49 +000099{{0, 1}, {1, 6}, {1, 0}, {2, 0}},
100{{0, 1}, {0, 2}, {1, 0}, {6, 1}},
101
102{{0, 1}, {5, 6}, {1, 0}, {1, 0}},
103{{0, 1}, {0, 1}, {1, 0}, {6, 5}},
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000104
105{{95.837747722788592, 45.025976907939643}, {16.564570095652982, 0.72959763963222402}, {63.209855865319199, 68.047528419665767}, {57.640240647662544, 59.524565264361243}},
106{{51.593891741518817, 38.53849970667553}, {62.34752929878772, 74.924924725166022}, {74.810149322641152, 34.17966562983564}, {29.368398119401373, 94.66719277886078}},
107
108{{39.765160968417838, 33.060396198677083}, {5.1922921581157908, 66.854301452103215}, {31.619281802149157, 25.269248720849514}, {81.541621071073038, 70.025341524754353}},
109{{46.078911165743556, 48.259962651999651}, {20.24450549867214, 49.403916182650214}, {0.26325131778756683, 24.46489805563581}, {15.915006546264051, 83.515023059917155}},
110
caryclark@google.com9f602912013-01-24 21:47:16 +0000111{{65.454505973241524, 93.881892270353575}, {45.867360264932437, 92.723972719499827}, {2.1464054482739447, 74.636369140183717}, {33.774068594804994, 40.770872887582925}},
112{{72.963387832494163, 95.659300729473728}, {11.809496633619768, 82.209921247423594}, {13.456139067865974, 57.329313623406605}, {36.060621606214262, 70.867335643091849}},
113
114{{32.484981432782945, 75.082940782924624}, {42.467313093350882, 48.131159948246157}, {3.5963115764764657, 43.208665839959245}, {79.442476890721579, 89.709102357602262}},
115{{18.98573861410177, 93.308887208490106}, {40.405250173250792, 91.039661826118675}, {8.0467721950480584, 42.100282172719147}, {40.883324221187891, 26.030185504830527}},
116
117{{7.5374809128872498, 82.441702896003477}, {22.444346930107265, 22.138854312775123}, {66.76091829629658, 50.753805856571446}, {78.193478508942519, 97.7932997968948}},
118{{97.700573130371311, 53.53260215070685}, {87.72443481149358, 84.575876772671876}, {19.215031396232092, 47.032676472809484}, {11.989686410869325, 10.659507480757082}},
119
120{{26.192053931854691, 9.8504326817814416}, {10.174241480498686, 98.476562741434464}, {21.177712558385782, 33.814968789841501}, {75.329030899018534, 55.02231980442177}},
121{{56.222082700683771, 24.54395039218662}, {95.589995289030483, 81.050822735322086}, {28.180450866082897, 28.837706255185282}, {60.128952916771617, 87.311672180570511}},
122
123{{42.449716172390481, 52.379709366885805}, {27.896043159019225, 48.797373636065686}, {92.770268299044233, 89.899302036454571}, {12.102066544863426, 99.43241951960718}},
124{{45.77532924980639, 45.958701495993274}, {37.458701356062065, 68.393691335056758}, {37.569326692060258, 27.673713456687381}, {60.674866037757539, 62.47349659096146}},
125
caryclark@google.com73ca6242013-01-17 21:02:47 +0000126{{67.426548091427676, 37.993772624988935}, {23.483695892376684, 90.476863174921306}, {35.597065061143162, 79.872482633158796}, {75.38634169631932, 18.244890038969412}},
127{{61.336508189019057, 82.693132843213675}, {44.639380902349664, 54.074825790745592}, {16.815615499771951, 20.049704667203923}, {41.866884958868326, 56.735503699973002}},
128
129{{67.4265481, 37.9937726}, {23.4836959, 90.4768632}, {35.5970651, 79.8724826}, {75.3863417, 18.24489}},
130{{61.3365082, 82.6931328}, {44.6393809, 54.0748258}, {16.8156155, 20.0497047}, {41.866885, 56.7355037}},
131
132{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945}, {18.5656052, 32.1268808}},
133{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981}, {56.4860195, 60.529264}},
134};
135
136const size_t testSetCount = sizeof(testSet) / sizeof(testSet[0]);
137
caryclark@google.com47d73da2013-02-17 01:41:25 +0000138static const Cubic newTestSet[] = {
caryclark@google.com996d78b2013-03-14 16:24:30 +0000139{{1,3}, {5,6}, {5,3}, {5,4}},
140{{3,5}, {4,5}, {3,1}, {6,5}},
141
caryclark@google.com1304bb22013-03-13 20:29:41 +0000142{{0,5}, {0,5}, {5,4}, {6,4}},
143{{4,5}, {4,6}, {5,0}, {5,0}},
144
145{{0,4}, {1,3}, {5,4}, {4,2}},
146{{4,5}, {2,4}, {4,0}, {3,1}},
147
148{{0,2}, {1,5}, {3,2}, {4,1}},
149{{2,3}, {1,4}, {2,0}, {5,1}},
150
151{{0,2}, {2,3}, {5,1}, {3,2}},
152{{1,5}, {2,3}, {2,0}, {3,2}},
153
154{{2,6}, {4,5}, {1,0}, {6,1}},
155{{0,1}, {1,6}, {6,2}, {5,4}},
156
157{{0,1}, {1,2}, {6,5}, {5,4}},
158{{5,6}, {4,5}, {1,0}, {2,1}},
159
160{{2.5119999999999996, 1.5710000000000002}, {2.6399999999999983, 1.6599999999999997}, {2.8000000000000007, 1.8000000000000003}, {3, 2}},
161{{2.4181876227114887, 1.9849772580462195}, {2.8269904869227211, 2.009330650246834}, {3.2004679292461624, 1.9942047174679169}, {3.4986199496818058, 2.0035994597094731}},
162
163{{2,3}, {1,4}, {1,0}, {6,0}},
164{{0,1}, {0,6}, {3,2}, {4,1}},
165
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +0000166{{0,2}, {1,5}, {1,0}, {6,1}},
167{{0,1}, {1,6}, {2,0}, {5,1}},
168
169{{0,1}, {1,5}, {2,1}, {4,0}},
170{{1,2}, {0,4}, {1,0}, {5,1}},
171
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000172{{0,1}, {3,5}, {2,1}, {3,1}},
173{{1,2}, {1,3}, {1,0}, {5,3}},
174
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +0000175{{0,1}, {2,5}, {6,0}, {5,3}},
caryclark@google.com7ff5c842013-02-26 15:56:05 +0000176{{0,6}, {3,5}, {1,0}, {5,2}},
177
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000178{{0,1}, {3,6}, {1,0}, {5,2}},
179{{0,1}, {2,5}, {1,0}, {6,3}},
180
caryclark@google.com5e0500f2013-02-20 12:51:37 +0000181{{1,2},{5,6},{1,0},{1,0}},
182{{0,1},{0,1},{2,1},{6,5}},
183
skia.committer@gmail.comd454ec12013-02-21 07:15:03 +0000184{{0,6},{1,2},{1,0},{1,0}},
caryclark@google.com5e0500f2013-02-20 12:51:37 +0000185{{0,1},{0,1},{6,0},{2,1}},
186
caryclark@google.com47d73da2013-02-17 01:41:25 +0000187{{0,2},{0,1},{3,0},{1,0}},
188{{0,3},{0,1},{2,0},{1,0}},
189};
190
191const size_t newTestSetCount = sizeof(newTestSet) / sizeof(newTestSet[0]);
192
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000193#if 0
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000194static void oneOff(const Cubic& cubic1, const Cubic& cubic2) {
195 SkTDArray<Quadratic> quads1;
196 cubic_to_quadratics(cubic1, calcPrecision(cubic1), quads1);
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +0000197#if SHOW_ORIGINAL
198 SkDebugf("computed quadratics given\n");
199 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}, {%1.9g,%1.9g}},\n",
200 cubic1[0].x, cubic1[0].y, cubic1[1].x, cubic1[1].y,
201 cubic1[2].x, cubic1[2].y, cubic1[3].x, cubic1[3].y));
202 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}, {%1.9g,%1.9g}},\n",
203 cubic2[0].x, cubic2[0].y, cubic2[1].x, cubic2[1].y,
204 cubic2[2].x, cubic2[2].y, cubic2[3].x, cubic2[3].y));
205#endif
caryclark@google.com9f602912013-01-24 21:47:16 +0000206#if ONE_OFF_DEBUG
caryclark@google.com1304bb22013-03-13 20:29:41 +0000207 SkDebugf("computed quadratics set 1\n");
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000208 for (int index = 0; index < quads1.count(); ++index) {
209 const Quadratic& q = quads1[index];
210 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].x, q[0].y,
211 q[1].x, q[1].y, q[2].x, q[2].y);
212 }
caryclark@google.com9f602912013-01-24 21:47:16 +0000213#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000214 SkTDArray<Quadratic> quads2;
215 cubic_to_quadratics(cubic2, calcPrecision(cubic2), quads2);
caryclark@google.com9f602912013-01-24 21:47:16 +0000216#if ONE_OFF_DEBUG
caryclark@google.com1304bb22013-03-13 20:29:41 +0000217 SkDebugf("computed quadratics set 2\n");
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000218 for (int index = 0; index < quads2.count(); ++index) {
219 const Quadratic& q = quads2[index];
220 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].x, q[0].y,
221 q[1].x, q[1].y, q[2].x, q[2].y);
222 }
caryclark@google.com9f602912013-01-24 21:47:16 +0000223#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000224 Intersections intersections2, intersections3;
225 intersect2(cubic1, cubic2, intersections2);
226 intersect3(cubic1, cubic2, intersections3);
227 int pt1, pt2, pt3;
228 bool found;
229 double tt1, tt2, last = -1;
230 _Point xy1, xy2;
231 for (pt1 = 0; pt1 < intersections2.used(); ++pt1) {
232 tt1 = intersections2.fT[0][pt1];
233 SkASSERT(!approximately_equal(last, tt1));
234 last = tt1;
235 xy_at_t(cubic1, tt1, xy1.x, xy1.y);
236 pt2 = intersections2.fFlip ? intersections2.used() - pt1 - 1 : pt1;
237 tt2 = intersections2.fT[1][pt2];
238 xy_at_t(cubic2, tt2, xy2.x, xy2.y);
239#if ONE_OFF_DEBUG
240 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1.9g\n",
241 __FUNCTION__, tt1, xy1.x, xy1.y, intersections2.fPt[pt1].x,
242 intersections2.fPt[pt1].y, xy2.x, xy2.y, tt2);
243#endif
244 SkASSERT(xy1.approximatelyEqual(xy2));
245#if SK_DEBUG
246 found = false;
247 for (pt3 = 0; pt3 < intersections3.used(); ++pt3) {
248 if (roughly_equal(tt1, intersections3.fT[0][pt3])) {
249 found = true;
250 break;
251 }
252 }
253 SkASSERT(found);
254#endif
255 }
256 last = -1;
257 for (pt3 = 0; pt3 < intersections3.used(); ++pt3) {
258 found = false;
259 double tt3 = intersections3.fT[0][pt3];
260 SkASSERT(!approximately_equal(last, tt3));
261 last = tt3;
262 for (pt1 = 0; pt1 < intersections2.used(); ++pt1) {
263 if (approximately_equal(tt3, intersections2.fT[0][pt1])) {
264 found = true;
265 break;
266 }
267 }
268 if (!found) {
269 tt1 = intersections3.fT[0][pt3];
270 xy_at_t(cubic1, tt1, xy1.x, xy1.y);
271 pt2 = intersections3.fFlip ? intersections3.used() - pt3 - 1 : pt3;
272 tt2 = intersections3.fT[1][pt2];
273 xy_at_t(cubic2, tt2, xy2.x, xy2.y);
274 #if ONE_OFF_DEBUG
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000275 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1.9g\n",
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000276 __FUNCTION__, tt1, xy1.x, xy1.y, intersections3.fPt[pt1].x,
277 intersections3.fPt[pt1].y, xy2.x, xy2.y, tt2);
278 #endif
279 SkASSERT(xy1.approximatelyEqual(xy2));
280 SkDebugf("%s missing in intersect2\n", __FUNCTION__);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000281 }
282 }
283}
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000284#endif
caryclark@google.com73ca6242013-01-17 21:02:47 +0000285
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000286static void oneOff3(const Cubic& cubic1, const Cubic& cubic2) {
caryclark@google.com1304bb22013-03-13 20:29:41 +0000287#if ONE_OFF_DEBUG
288 SkDebugf("computed quadratics given\n");
289 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
290 cubic1[0].x, cubic1[0].y, cubic1[1].x, cubic1[1].y,
291 cubic1[2].x, cubic1[2].y, cubic1[3].x, cubic1[3].y);
292 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
293 cubic2[0].x, cubic2[0].y, cubic2[1].x, cubic2[1].y,
294 cubic2[2].x, cubic2[2].y, cubic2[3].x, cubic2[3].y);
295#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000296 SkTDArray<Quadratic> quads1;
297 cubic_to_quadratics(cubic1, calcPrecision(cubic1), quads1);
298#if ONE_OFF_DEBUG
caryclark@google.com1304bb22013-03-13 20:29:41 +0000299 SkDebugf("computed quadratics set 1\n");
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000300 for (int index = 0; index < quads1.count(); ++index) {
301 const Quadratic& q = quads1[index];
302 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].x, q[0].y,
303 q[1].x, q[1].y, q[2].x, q[2].y);
304 }
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000305#endif
306 SkTDArray<Quadratic> quads2;
307 cubic_to_quadratics(cubic2, calcPrecision(cubic2), quads2);
308#if ONE_OFF_DEBUG
caryclark@google.com1304bb22013-03-13 20:29:41 +0000309 SkDebugf("computed quadratics set 2\n");
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000310 for (int index = 0; index < quads2.count(); ++index) {
311 const Quadratic& q = quads2[index];
312 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].x, q[0].y,
313 q[1].x, q[1].y, q[2].x, q[2].y);
314 }
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000315#endif
316 Intersections intersections3;
317 intersect3(cubic1, cubic2, intersections3);
318 int pt2, pt3;
319 double tt1, tt2, last = -1;
320 _Point xy1, xy2;
321 for (pt3 = 0; pt3 < intersections3.used(); ++pt3) {
322 double tt3 = intersections3.fT[0][pt3];
caryclark@google.com1304bb22013-03-13 20:29:41 +0000323 // SkASSERT(!approximately_equal(last, tt3));
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000324 last = tt3;
325 tt1 = intersections3.fT[0][pt3];
326 xy_at_t(cubic1, tt1, xy1.x, xy1.y);
327 pt2 = intersections3.fFlip ? intersections3.used() - pt3 - 1 : pt3;
328 tt2 = intersections3.fT[1][pt2];
329 xy_at_t(cubic2, tt2, xy2.x, xy2.y);
330#if ONE_OFF_DEBUG
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000331 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1.9g\n",
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000332 __FUNCTION__, tt1, xy1.x, xy1.y, intersections3.fPt[pt3].x,
333 intersections3.fPt[pt3].y, xy2.x, xy2.y, tt2);
334#endif
335 SkASSERT(xy1.approximatelyEqual(xy2));
336 }
337}
338
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000339#if 0
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000340static int fails[][2] = { {0, 23}, // fails in intersect2 recursing
341 {2, 7}, // answers differ, but neither is correct ('3' is closer)
342 {3, 26}, // fails in intersect2 recursing
343 {4, 9}, // fails in intersect2 recursing
344 {4, 10}, // fails in intersect2 recursing
345 {10, 17}, // fails in intersect2 recursing
346 {12, 14}, // loops indefinitely
347 {12, 21}, // fails in intersect2 recursing
348 {13, 21}, // fails in intersect2 recursing
349 {14, 21}, // fails in intersect2 recursing
350 {17, 25}, // fails in intersect2 recursing
351 {23, 25}, // fails in intersect2 recursing
352};
353
354static int failCount = sizeof(fails) / sizeof(fails[0]);
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000355#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000356
357static void oneOff(int outer, int inner) {
358 const Cubic& cubic1 = testSet[outer];
359 const Cubic& cubic2 = testSet[inner];
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000360#if 0
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000361 bool failing = false;
362 for (int i = 0; i < failCount; ++i) {
363 if ((fails[i][0] == outer && fails[i][1] == inner)
364 || (fails[i][1] == outer && fails[i][0] == inner)) {
365 failing = true;
366 break;
367 }
368 }
369 if (!failing) {
370 oneOff(cubic1, cubic2);
371 } else {
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000372#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000373 oneOff3(cubic1, cubic2);
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000374// }
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000375}
376
377void CubicIntersection_OneOffTest() {
378 oneOff(12, 14);
379}
380
caryclark@google.com47d73da2013-02-17 01:41:25 +0000381static void newOneOff(int outer, int inner) {
382 const Cubic& cubic1 = newTestSet[outer];
383 const Cubic& cubic2 = newTestSet[inner];
384 oneOff3(cubic1, cubic2);
385}
386
387void CubicIntersection_NewOneOffTest() {
388 newOneOff(0, 1);
389}
390
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000391static void oneOffTests() {
392 for (size_t outer = 0; outer < testSetCount - 1; ++outer) {
393 for (size_t inner = outer + 1; inner < testSetCount; ++inner) {
394 oneOff(outer, inner);
395 }
396 }
397}
398
399void CubicIntersection_OneOffTests() {
400 oneOffTests();
401}
402
caryclark@google.comf9502d72013-02-04 14:06:49 +0000403#define DEBUG_CRASH 0
caryclark@google.com73ca6242013-01-17 21:02:47 +0000404
405class CubicChopper {
406public:
407
408// only finds one intersection
409CubicChopper(const Cubic& c1, const Cubic& c2)
410 : cubic1(c1)
411 , cubic2(c2)
412 , depth(0) {
413}
414
415bool intersect(double minT1, double maxT1, double minT2, double maxT2) {
416 Cubic sub1, sub2;
417 // FIXME: carry last subdivide and reduceOrder result with cubic
418 sub_divide(cubic1, minT1, maxT1, sub1);
419 sub_divide(cubic2, minT2, maxT2, sub2);
420 Intersections i;
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000421 intersect3(sub1, sub2, i);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000422 if (i.used() == 0) {
423 return false;
424 }
425 double x1, y1, x2, y2;
426 t1 = minT1 + i.fT[0][0] * (maxT1 - minT1);
427 t2 = minT2 + i.fT[1][0] * (maxT2 - minT2);
428 xy_at_t(cubic1, t1, x1, y1);
429 xy_at_t(cubic2, t2, x2, y2);
430 if (AlmostEqualUlps(x1, x2) && AlmostEqualUlps(y1, y2)) {
431 return true;
432 }
433 double half1 = (minT1 + maxT1) / 2;
434 double half2 = (minT2 + maxT2) / 2;
435 ++depth;
436 bool result;
437 if (depth & 1) {
438 result = intersect(minT1, half1, minT2, maxT2) || intersect(half1, maxT1, minT2, maxT2)
439 || intersect(minT1, maxT1, minT2, half2) || intersect(minT1, maxT1, half2, maxT2);
440 } else {
441 result = intersect(minT1, maxT1, minT2, half2) || intersect(minT1, maxT1, half2, maxT2)
442 || intersect(minT1, half1, minT2, maxT2) || intersect(half1, maxT1, minT2, maxT2);
443 }
444 --depth;
445 return result;
446}
447
448const Cubic& cubic1;
449const Cubic& cubic2;
450double t1;
451double t2;
452int depth;
453};
454
455#define TRY_OLD 0 // old way fails on test == 1
456
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000457void CubicIntersection_RandTestOld() {
caryclark@google.com73ca6242013-01-17 21:02:47 +0000458 srand(0);
459 const int tests = 1000000; // 10000000;
460 double largestFactor = DBL_MAX;
461 for (int test = 0; test < tests; ++test) {
462 Cubic cubic1, cubic2;
463 for (int i = 0; i < 4; ++i) {
464 cubic1[i].x = (double) rand() / RAND_MAX * 100;
465 cubic1[i].y = (double) rand() / RAND_MAX * 100;
466 cubic2[i].x = (double) rand() / RAND_MAX * 100;
467 cubic2[i].y = (double) rand() / RAND_MAX * 100;
468 }
469 if (test == 2513) { // the pair crosses three times, but the quadratic approximation
470 continue; // only sees one -- should be OK to ignore the other two?
471 }
472 if (test == 12932) { // this exposes a weakness when one cubic touches the other but
473 continue; // does not touch the quad approximation. Captured in qc.htm as cubic15
474 }
475 #if DEBUG_CRASH
476 char str[1024];
477 sprintf(str, "{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}},\n"
478 "{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}},\n",
479 cubic1[0].x, cubic1[0].y, cubic1[1].x, cubic1[1].y, cubic1[2].x, cubic1[2].y,
480 cubic1[3].x, cubic1[3].y,
481 cubic2[0].x, cubic2[0].y, cubic2[1].x, cubic2[1].y, cubic2[2].x, cubic2[2].y,
482 cubic2[3].x, cubic2[3].y);
483 #endif
484 _Rect rect1, rect2;
485 rect1.setBounds(cubic1);
486 rect2.setBounds(cubic2);
487 bool boundsIntersect = rect1.left <= rect2.right && rect2.left <= rect2.right
488 && rect1.top <= rect2.bottom && rect2.top <= rect1.bottom;
489 Intersections i1, i2;
490 #if TRY_OLD
491 bool oldIntersects = intersect(cubic1, cubic2, i1);
492 #else
493 bool oldIntersects = false;
494 #endif
495 if (test == -1) {
496 SkDebugf("ready...\n");
497 }
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000498 bool newIntersects = intersect3(cubic1, cubic2, i2);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000499 if (!boundsIntersect && (oldIntersects || newIntersects)) {
caryclark@google.comf9502d72013-02-04 14:06:49 +0000500 #if DEBUG_CRASH
caryclark@google.com73ca6242013-01-17 21:02:47 +0000501 SkDebugf("%s %d unexpected intersection boundsIntersect=%d oldIntersects=%d"
502 " newIntersects=%d\n%s %s\n", __FUNCTION__, test, boundsIntersect,
503 oldIntersects, newIntersects, __FUNCTION__, str);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000504 #endif
caryclark@google.comaa358312013-01-29 20:28:49 +0000505 SkASSERT(0);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000506 }
507 if (oldIntersects && !newIntersects) {
caryclark@google.comf9502d72013-02-04 14:06:49 +0000508 #if DEBUG_CRASH
caryclark@google.com73ca6242013-01-17 21:02:47 +0000509 SkDebugf("%s %d missing intersection oldIntersects=%d newIntersects=%d\n%s %s\n",
510 __FUNCTION__, test, oldIntersects, newIntersects, __FUNCTION__, str);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000511 #endif
caryclark@google.comaa358312013-01-29 20:28:49 +0000512 SkASSERT(0);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000513 }
514 if (!oldIntersects && !newIntersects) {
515 continue;
516 }
517 if (i2.used() > 1) {
518 continue;
519 // just look at single intercepts for simplicity
520 }
521 Intersections self1, self2; // self-intersect checks
522 if (intersect(cubic1, self1)) {
523 continue;
524 }
525 if (intersect(cubic2, self2)) {
526 continue;
527 }
528 // binary search for range necessary to enclose real intersection
529 CubicChopper c(cubic1, cubic2);
530 bool result = c.intersect(0, 1, 0, 1);
531 if (!result) {
532 // FIXME: a failure here probably means that a core routine used by CubicChopper is failing
533 continue;
534 }
535 double delta1 = fabs(c.t1 - i2.fT[0][0]);
536 double delta2 = fabs(c.t2 - i2.fT[1][0]);
537 double calc1 = calcPrecision(cubic1);
538 double calc2 = calcPrecision(cubic2);
539 double factor1 = calc1 / delta1;
540 double factor2 = calc2 / delta2;
541 SkDebugf("%s %d calc1=%1.9g delta1=%1.9g factor1=%1.9g calc2=%1.9g delta2=%1.9g"
542 " factor2=%1.9g\n", __FUNCTION__, test,
543 calc1, delta1, factor1, calc2, delta2, factor2);
544 if (factor1 < largestFactor) {
545 SkDebugf("WE HAVE A WINNER! %1.9g\n", factor1);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000546 #if DEBUG_CRASH
caryclark@google.com73ca6242013-01-17 21:02:47 +0000547 SkDebugf("%s\n", str);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000548 #endif
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000549 oneOff3(cubic1, cubic2);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000550 largestFactor = factor1;
551 }
552 if (factor2 < largestFactor) {
553 SkDebugf("WE HAVE A WINNER! %1.9g\n", factor2);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000554 #if DEBUG_CRASH
caryclark@google.com73ca6242013-01-17 21:02:47 +0000555 SkDebugf("%s\n", str);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000556 #endif
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000557 oneOff3(cubic1, cubic2);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000558 largestFactor = factor2;
559 }
560 }
561}
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000562
563void CubicIntersection_RandTest() {
564 srand(0);
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000565 const int tests = 10000000;
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000566 for (int test = 0; test < tests; ++test) {
567 Cubic cubic1, cubic2;
568 for (int i = 0; i < 4; ++i) {
569 cubic1[i].x = (double) rand() / RAND_MAX * 100;
570 cubic1[i].y = (double) rand() / RAND_MAX * 100;
571 cubic2[i].x = (double) rand() / RAND_MAX * 100;
572 cubic2[i].y = (double) rand() / RAND_MAX * 100;
573 }
574 #if DEBUG_CRASH
575 char str[1024];
576 sprintf(str, "{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}},\n"
577 "{{%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}, {%1.9g, %1.9g}},\n",
578 cubic1[0].x, cubic1[0].y, cubic1[1].x, cubic1[1].y, cubic1[2].x, cubic1[2].y,
579 cubic1[3].x, cubic1[3].y,
580 cubic2[0].x, cubic2[0].y, cubic2[1].x, cubic2[1].y, cubic2[2].x, cubic2[2].y,
581 cubic2[3].x, cubic2[3].y);
582 #endif
583 _Rect rect1, rect2;
584 rect1.setBounds(cubic1);
585 rect2.setBounds(cubic2);
586 bool boundsIntersect = rect1.left <= rect2.right && rect2.left <= rect2.right
587 && rect1.top <= rect2.bottom && rect2.top <= rect1.bottom;
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000588 if (test == -1) {
589 SkDebugf("ready...\n");
590 }
591 Intersections intersections2;
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000592 bool newIntersects = intersect3(cubic1, cubic2, intersections2);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000593 if (!boundsIntersect && newIntersects) {
caryclark@google.comf9502d72013-02-04 14:06:49 +0000594 #if DEBUG_CRASH
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000595 SkDebugf("%s %d unexpected intersection boundsIntersect=%d "
596 " newIntersects=%d\n%s %s\n", __FUNCTION__, test, boundsIntersect,
597 newIntersects, __FUNCTION__, str);
caryclark@google.comf9502d72013-02-04 14:06:49 +0000598 #endif
caryclark@google.comaa358312013-01-29 20:28:49 +0000599 SkASSERT(0);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000600 }
601 for (int pt = 0; pt < intersections2.used(); ++pt) {
602 double tt1 = intersections2.fT[0][pt];
603 _Point xy1, xy2;
604 xy_at_t(cubic1, tt1, xy1.x, xy1.y);
605 int pt2 = intersections2.fFlip ? intersections2.used() - pt - 1 : pt;
606 double tt2 = intersections2.fT[1][pt2];
607 xy_at_t(cubic2, tt2, xy2.x, xy2.y);
caryclark@google.com9f602912013-01-24 21:47:16 +0000608 #if 0
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000609 SkDebugf("%s t1=%1.9g (%1.9g, %1.9g) (%1.9g, %1.9g) t2=%1.9g\n", __FUNCTION__,
610 tt1, xy1.x, xy1.y, xy2.x, xy2.y, tt2);
caryclark@google.com9f602912013-01-24 21:47:16 +0000611 #endif
caryclark@google.comaa358312013-01-29 20:28:49 +0000612 SkASSERT(xy1.approximatelyEqual(xy2));
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000613 }
614 }
615}
caryclark@google.com9f602912013-01-24 21:47:16 +0000616
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +0000617static void intersectionFinder(int index0, int index1, double t1Seed, double t2Seed,
618 double t1Step, double t2Step) {
619 const Cubic& cubic1 = newTestSet[index0];
620 const Cubic& cubic2 = newTestSet[index1];
caryclark@google.comf9502d72013-02-04 14:06:49 +0000621 _Point t1[3], t2[3];
622 bool toggle = true;
623 do {
624 xy_at_t(cubic1, t1Seed - t1Step, t1[0].x, t1[0].y);
625 xy_at_t(cubic1, t1Seed, t1[1].x, t1[1].y);
626 xy_at_t(cubic1, t1Seed + t1Step, t1[2].x, t1[2].y);
627 xy_at_t(cubic2, t2Seed - t2Step, t2[0].x, t2[0].y);
628 xy_at_t(cubic2, t2Seed, t2[1].x, t2[1].y);
629 xy_at_t(cubic2, t2Seed + t2Step, t2[2].x, t2[2].y);
630 double dist[3][3];
631 dist[1][1] = t1[1].distance(t2[1]);
632 int best_i = 1, best_j = 1;
633 for (int i = 0; i < 3; ++i) {
634 for (int j = 0; j < 3; ++j) {
635 if (i == 1 && j == 1) {
636 continue;
637 }
638 dist[i][j] = t1[i].distance(t2[j]);
639 if (dist[best_i][best_j] > dist[i][j]) {
640 best_i = i;
641 best_j = j;
642 }
643 }
644 }
645 if (best_i == 0) {
646 t1Seed -= t1Step;
647 } else if (best_i == 2) {
648 t1Seed += t1Step;
649 }
650 if (best_j == 0) {
651 t2Seed -= t2Step;
652 } else if (best_j == 2) {
653 t2Seed += t2Step;
654 }
655 if (best_i == 1 && best_j == 1) {
656 if ((toggle ^= true)) {
657 t1Step /= 2;
658 } else {
659 t2Step /= 2;
660 }
661 }
662 } while (!t1[1].approximatelyEqual(t2[1]));
663 t1Step = t2Step = 0.1;
664 double t10 = t1Seed - t1Step * 2;
665 double t12 = t1Seed + t1Step * 2;
666 double t20 = t2Seed - t2Step * 2;
667 double t22 = t2Seed + t2Step * 2;
668 _Point test;
669 while (!approximately_zero(t1Step)) {
670 xy_at_t(cubic1, t10, test.x, test.y);
671 t10 += t1[1].approximatelyEqual(test) ? -t1Step : t1Step;
672 t1Step /= 2;
caryclark@google.com9f602912013-01-24 21:47:16 +0000673 }
caryclark@google.comf9502d72013-02-04 14:06:49 +0000674 t1Step = 0.1;
675 while (!approximately_zero(t1Step)) {
676 xy_at_t(cubic1, t12, test.x, test.y);
677 t12 -= t1[1].approximatelyEqual(test) ? -t1Step : t1Step;
678 t1Step /= 2;
679 }
680 while (!approximately_zero(t2Step)) {
681 xy_at_t(cubic2, t20, test.x, test.y);
682 t20 += t2[1].approximatelyEqual(test) ? -t2Step : t2Step;
683 t2Step /= 2;
684 }
685 t2Step = 0.1;
686 while (!approximately_zero(t2Step)) {
687 xy_at_t(cubic2, t22, test.x, test.y);
688 t22 -= t2[1].approximatelyEqual(test) ? -t2Step : t2Step;
689 t2Step /= 2;
690 }
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000691#if ONE_OFF_DEBUG
caryclark@google.comf9502d72013-02-04 14:06:49 +0000692 SkDebugf("%s t1=(%1.9g<%1.9g<%1.9g) t2=(%1.9g<%1.9g<%1.9g)\n", __FUNCTION__,
693 t10, t1Seed, t12, t20, t2Seed, t22);
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000694 _Point p10 = xy_at_t(cubic1, t10);
695 _Point p1Seed = xy_at_t(cubic1, t1Seed);
696 _Point p12 = xy_at_t(cubic1, t12);
697 SkDebugf("%s p1=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__,
698 p10.x, p10.y, p1Seed.x, p1Seed.y, p12.x, p12.y);
699 _Point p20 = xy_at_t(cubic2, t20);
700 _Point p2Seed = xy_at_t(cubic2, t2Seed);
701 _Point p22 = xy_at_t(cubic2, t22);
702 SkDebugf("%s p2=(%1.9g,%1.9g)<(%1.9g,%1.9g)<(%1.9g,%1.9g)\n", __FUNCTION__,
703 p20.x, p20.y, p2Seed.x, p2Seed.y, p22.x, p22.y);
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000704#endif
caryclark@google.com9f602912013-01-24 21:47:16 +0000705}
caryclark@google.comf9502d72013-02-04 14:06:49 +0000706
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +0000707void CubicIntersection_IntersectionFinder() {
708
caryclark@google.com996d78b2013-03-14 16:24:30 +0000709 // double t1Seed = 0.87;
710 // double t2Seed = 0.87;
711 double t1Step = 0.000001;
712 double t2Step = 0.000001;
713 intersectionFinder(0, 1, 0.855895664, 0.864850875, t1Step, t2Step);
714 intersectionFinder(0, 1, 0.865207906, 0.865207887, t1Step, t2Step);
715 intersectionFinder(0, 1, 0.865213351, 0.865208087, t1Step, t2Step);
caryclark@google.comd4c8e1e2013-03-05 14:13:13 +0000716}
717
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000718static void coincidentTest() {
caryclark@google.comf9502d72013-02-04 14:06:49 +0000719#if 0
caryclark@google.comf9502d72013-02-04 14:06:49 +0000720 Cubic cubic1 = {{0, 1}, {0, 2}, {1, 0}, {1, 0}};
721 Cubic cubic2 = {{0, 1}, {0, 2}, {1, 0}, {6, 1}};
caryclark@google.comf9502d72013-02-04 14:06:49 +0000722#endif
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000723}
724
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000725void CubicIntersection_SelfTest() {
726 const Cubic selfSet[] = {
caryclark@google.com1304bb22013-03-13 20:29:41 +0000727 {{0,2}, {2,3}, {5,1}, {3,2}},
728 {{0,2}, {3,5}, {5,0}, {4,2}},
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000729 {{3.34,8.98}, {1.95,10.27}, {3.76,7.65}, {4.96,10.64}},
730 {{3.13,2.74}, {1.08,4.62}, {3.71,0.94}, {2.01,3.81}},
skia.committer@gmail.com58433de2013-02-23 07:02:45 +0000731 {{6.71,3.14}, {7.99,2.75}, {8.27,1.96}, {6.35,3.57}},
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000732 {{12.81,7.27}, {7.22,6.98}, {12.49,8.97}, {11.42,6.18}},
733 };
734 size_t selfSetCount = sizeof(selfSet) / sizeof(selfSet[0]);
735 for (size_t index = 0; index < selfSetCount; ++index) {
736 const Cubic& cubic = selfSet[index];
737 #if ONE_OFF_DEBUG
caryclark@google.com1304bb22013-03-13 20:29:41 +0000738 int idx2;
739 double max[3];
740 int ts = find_cubic_max_curvature(cubic, max);
741 for (idx2 = 0; idx2 < ts; ++idx2) {
742 SkDebugf("%s max[%d]=%1.9g (%1.9g, %1.9g)\n", __FUNCTION__, idx2,
743 max[idx2], xy_at_t(cubic, max[idx2]).x, xy_at_t(cubic, max[idx2]).y);
744 }
745 SkTDArray<double> ts1;
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000746 SkTDArray<Quadratic> quads1;
caryclark@google.com1304bb22013-03-13 20:29:41 +0000747 cubic_to_quadratics(cubic, calcPrecision(cubic), ts1);
748 for (idx2 = 0; idx2 < ts1.count(); ++idx2) {
749 SkDebugf("%s t[%d]=%1.9g\n", __FUNCTION__, idx2, ts1[idx2]);
750 }
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000751 cubic_to_quadratics(cubic, calcPrecision(cubic), quads1);
caryclark@google.com1304bb22013-03-13 20:29:41 +0000752 for (idx2 = 0; idx2 < quads1.count(); ++idx2) {
753 const Quadratic& q = quads1[idx2];
skia.committer@gmail.com03682be2013-03-14 07:02:51 +0000754 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n",
caryclark@google.com1304bb22013-03-13 20:29:41 +0000755 q[0].x, q[0].y, q[1].x, q[1].y, q[2].x, q[2].y);
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000756 }
757 SkDebugf("\n");
758 #endif
759 Intersections i;
caryclark@google.com1304bb22013-03-13 20:29:41 +0000760 SkDEBUGCODE(int result = ) intersect(cubic, i);
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000761 SkASSERT(result == 1);
762 SkASSERT(i.used() == 1);
763 SkASSERT(!approximately_equal(i.fT[0][0], i.fT[1][0]));
764 _Point pt1 = xy_at_t(cubic, i.fT[0][0]);
765 _Point pt2 = xy_at_t(cubic, i.fT[1][0]);
766 SkASSERT(pt1.approximatelyEqual(pt2));
767 }
768}
769
caryclark@google.com45a8fc62013-02-14 15:29:11 +0000770void CubicIntersection_Test() {
771 oneOffTests();
772 coincidentTest();
773 standardTestCases();
774}