blob: 9316f342a4845c437cbee1adff66e0c4a6a2f763 [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.com9d5f99b2013-01-22 12:55:54 +00007
8#include "CubicUtilities.h"
caryclark@google.comc6825902012-02-03 22:07:47 +00009#include "CurveIntersection.h"
caryclark@google.com639df892012-01-10 21:46:10 +000010#include "Intersections.h"
caryclark@google.comc6825902012-02-03 22:07:47 +000011#include "IntersectionUtilities.h"
caryclark@google.com639df892012-01-10 21:46:10 +000012#include "LineIntersection.h"
caryclark@google.com9f602912013-01-24 21:47:16 +000013#include "LineUtilities.h"
caryclark@google.com639df892012-01-10 21:46:10 +000014
caryclark@google.com0d3d09e2012-12-10 14:50:04 +000015static const double tClipLimit = 0.8; // http://cagd.cs.byu.edu/~tom/papers/bezclip.pdf see Multiple intersections
16
caryclark@google.comc6825902012-02-03 22:07:47 +000017class CubicIntersections : public Intersections {
18public:
19
rmistry@google.comd6176b02012-08-23 18:14:13 +000020CubicIntersections(const Cubic& c1, const Cubic& c2, Intersections& i)
caryclark@google.comc6825902012-02-03 22:07:47 +000021 : cubic1(c1)
22 , cubic2(c2)
23 , intersections(i)
rmistry@google.comd6176b02012-08-23 18:14:13 +000024 , depth(0)
caryclark@google.comc6825902012-02-03 22:07:47 +000025 , splits(0) {
caryclark@google.com639df892012-01-10 21:46:10 +000026}
27
caryclark@google.comc6825902012-02-03 22:07:47 +000028bool intersect() {
caryclark@google.com639df892012-01-10 21:46:10 +000029 double minT1, minT2, maxT1, maxT2;
30 if (!bezier_clip(cubic2, cubic1, minT1, maxT1)) {
31 return false;
32 }
33 if (!bezier_clip(cubic1, cubic2, minT2, maxT2)) {
34 return false;
35 }
caryclark@google.comc6825902012-02-03 22:07:47 +000036 int split;
caryclark@google.com639df892012-01-10 21:46:10 +000037 if (maxT1 - minT1 < maxT2 - minT2) {
38 intersections.swap();
caryclark@google.comc6825902012-02-03 22:07:47 +000039 minT2 = 0;
40 maxT2 = 1;
41 split = maxT1 - minT1 > tClipLimit;
42 } else {
43 minT1 = 0;
44 maxT1 = 1;
45 split = (maxT2 - minT2 > tClipLimit) << 1;
46 }
47 return chop(minT1, maxT1, minT2, maxT2, split);
caryclark@google.com639df892012-01-10 21:46:10 +000048}
caryclark@google.comc6825902012-02-03 22:07:47 +000049
50protected:
rmistry@google.comd6176b02012-08-23 18:14:13 +000051
caryclark@google.comc6825902012-02-03 22:07:47 +000052bool intersect(double minT1, double maxT1, double minT2, double maxT2) {
53 Cubic smaller, larger;
rmistry@google.comd6176b02012-08-23 18:14:13 +000054 // FIXME: carry last subdivide and reduceOrder result with cubic
caryclark@google.comc6825902012-02-03 22:07:47 +000055 sub_divide(cubic1, minT1, maxT1, intersections.swapped() ? larger : smaller);
56 sub_divide(cubic2, minT2, maxT2, intersections.swapped() ? smaller : larger);
57 Cubic smallResult;
58 if (reduceOrder(smaller, smallResult,
59 kReduceOrder_NoQuadraticsAllowed) <= 2) {
60 Cubic largeResult;
61 if (reduceOrder(larger, largeResult,
62 kReduceOrder_NoQuadraticsAllowed) <= 2) {
63 const _Line& smallLine = (const _Line&) smallResult;
64 const _Line& largeLine = (const _Line&) largeResult;
65 double smallT[2];
66 double largeT[2];
67 // FIXME: this doesn't detect or deal with coincident lines
68 if (!::intersect(smallLine, largeLine, smallT, largeT)) {
69 return false;
70 }
71 if (intersections.swapped()) {
rmistry@google.comd6176b02012-08-23 18:14:13 +000072 smallT[0] = interp(minT2, maxT2, smallT[0]);
73 largeT[0] = interp(minT1, maxT1, largeT[0]);
caryclark@google.comc6825902012-02-03 22:07:47 +000074 } else {
rmistry@google.comd6176b02012-08-23 18:14:13 +000075 smallT[0] = interp(minT1, maxT1, smallT[0]);
76 largeT[0] = interp(minT2, maxT2, largeT[0]);
caryclark@google.comc6825902012-02-03 22:07:47 +000077 }
78 intersections.add(smallT[0], largeT[0]);
79 return true;
80 }
81 }
82 double minT, maxT;
83 if (!bezier_clip(smaller, larger, minT, maxT)) {
84 if (minT == maxT) {
85 if (intersections.swapped()) {
86 minT1 = (minT1 + maxT1) / 2;
87 minT2 = interp(minT2, maxT2, minT);
88 } else {
89 minT1 = interp(minT1, maxT1, minT);
90 minT2 = (minT2 + maxT2) / 2;
91 }
92 intersections.add(minT1, minT2);
93 return true;
94 }
95 return false;
96 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000097
caryclark@google.comc6825902012-02-03 22:07:47 +000098 int split;
99 if (intersections.swapped()) {
100 double newMinT1 = interp(minT1, maxT1, minT);
101 double newMaxT1 = interp(minT1, maxT1, maxT);
102 split = (newMaxT1 - newMinT1 > (maxT1 - minT1) * tClipLimit) << 1;
103#define VERBOSE 0
104#if VERBOSE
105 printf("%s d=%d s=%d new1=(%g,%g) old1=(%g,%g) split=%d\n",
106 __FUNCTION__, depth, splits, newMinT1, newMaxT1, minT1, maxT1,
107 split);
108#endif
109 minT1 = newMinT1;
110 maxT1 = newMaxT1;
111 } else {
112 double newMinT2 = interp(minT2, maxT2, minT);
113 double newMaxT2 = interp(minT2, maxT2, maxT);
114 split = newMaxT2 - newMinT2 > (maxT2 - minT2) * tClipLimit;
115#if VERBOSE
116 printf("%s d=%d s=%d new2=(%g,%g) old2=(%g,%g) split=%d\n",
117 __FUNCTION__, depth, splits, newMinT2, newMaxT2, minT2, maxT2,
118 split);
119#endif
120 minT2 = newMinT2;
121 maxT2 = newMaxT2;
122 }
123 return chop(minT1, maxT1, minT2, maxT2, split);
124}
125
126bool chop(double minT1, double maxT1, double minT2, double maxT2, int split) {
127 ++depth;
128 intersections.swap();
129 if (split) {
130 ++splits;
131 if (split & 2) {
132 double middle1 = (maxT1 + minT1) / 2;
133 intersect(minT1, middle1, minT2, maxT2);
134 intersect(middle1, maxT1, minT2, maxT2);
135 } else {
136 double middle2 = (maxT2 + minT2) / 2;
137 intersect(minT1, maxT1, minT2, middle2);
138 intersect(minT1, maxT1, middle2, maxT2);
139 }
140 --splits;
141 intersections.swap();
142 --depth;
143 return intersections.intersected();
144 }
145 bool result = intersect(minT1, maxT1, minT2, maxT2);
146 intersections.swap();
147 --depth;
148 return result;
149}
150
151private:
152
caryclark@google.comc6825902012-02-03 22:07:47 +0000153const Cubic& cubic1;
154const Cubic& cubic2;
155Intersections& intersections;
156int depth;
157int splits;
158};
159
160bool intersect(const Cubic& c1, const Cubic& c2, Intersections& i) {
161 CubicIntersections c(c1, c2, i);
162 return c.intersect();
163}
164
caryclark@google.com73ca6242013-01-17 21:02:47 +0000165#include "CubicUtilities.h"
166
caryclark@google.com9f602912013-01-24 21:47:16 +0000167static void cubicTangent(const Cubic& cubic, double t, _Line& tangent, _Point& pt, _Point& dxy) {
168 xy_at_t(cubic, t, tangent[0].x, tangent[0].y);
169 pt = tangent[1] = tangent[0];
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000170 dxdy_at_t(cubic, t, dxy);
caryclark@google.com9f602912013-01-24 21:47:16 +0000171 tangent[0] -= dxy;
172 tangent[1] += dxy;
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000173}
174
caryclark@google.com9f602912013-01-24 21:47:16 +0000175static double cubicDelta(const _Point& dxy, _Line& tangent, double scale) {
176 double tangentLen = dxy.length();
177 tangent[0] -= tangent[1];
178 double intersectLen = tangent[0].length();
179 double result = intersectLen / tangentLen + scale;
180 return result;
181}
182
183// FIXME: after testing, make this static
184void computeDelta(const Cubic& c1, double t1, double scale1, const Cubic& c2, double t2,
185 double scale2, double& delta1, double& delta2) {
186 _Line tangent1, tangent2, line1, line2;
187 _Point dxy1, dxy2;
188 cubicTangent(c1, t1, line1, tangent1[0], dxy1);
189 cubicTangent(c2, t2, line2, tangent2[0], dxy2);
190 double range1[2], range2[2];
191 int found = intersect(line1, line2, range1, range2);
192 if (found == 0) {
193 range1[0] = 0.5;
194 } else {
195 SkASSERT(found == 1);
196 }
197 xy_at_t(line1, range1[0], tangent1[1].x, tangent1[1].y);
198#if SK_DEBUG
199 if (found == 1) {
200 xy_at_t(line2, range2[0], tangent2[1].x, tangent2[1].y);
201 SkASSERT(tangent2[1].approximatelyEqual(tangent1[1]));
202 }
203#endif
204 tangent2[1] = tangent1[1];
205 delta1 = cubicDelta(dxy1, tangent1, scale1 / precisionUnit);
206 delta2 = cubicDelta(dxy2, tangent2, scale2 / precisionUnit);
207}
208
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000209#if SK_DEBUG
caryclark@google.com9f602912013-01-24 21:47:16 +0000210int debugDepth;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000211#endif
212
caryclark@google.com73ca6242013-01-17 21:02:47 +0000213// this flavor approximates the cubics with quads to find the intersecting ts
214// OPTIMIZE: if this strategy proves successful, the quad approximations, or the ts used
215// to create the approximations, could be stored in the cubic segment
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000216// FIXME: this strategy needs to intersect the convex hull on either end with the opposite to
217// account for inset quadratics that cause the endpoint intersection to avoid detection
218// the segments can be very short -- the length of the maximum quadratic error (precision)
219// FIXME: this needs to recurse on itself, taking a range of T values and computing the new
220// t range ala is linear inner. The range can be figured by taking the dx/dy and determining
221// the fraction that matches the precision. That fraction is the change in t for the smaller cubic.
222static bool intersect2(const Cubic& cubic1, double t1s, double t1e, const Cubic& cubic2,
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000223 double t2s, double t2e, double precisionScale, Intersections& i) {
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000224 Cubic c1, c2;
225 sub_divide(cubic1, t1s, t1e, c1);
226 sub_divide(cubic2, t2s, t2e, c2);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000227 SkTDArray<double> ts1;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000228 cubic_to_quadratics(c1, calcPrecision(c1) * precisionScale, ts1);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000229 SkTDArray<double> ts2;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000230 cubic_to_quadratics(c2, calcPrecision(c2) * precisionScale, ts2);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000231 double t1Start = t1s;
caryclark@google.com73ca6242013-01-17 21:02:47 +0000232 int ts1Count = ts1.count();
233 for (int i1 = 0; i1 <= ts1Count; ++i1) {
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000234 const double tEnd1 = i1 < ts1Count ? ts1[i1] : 1;
235 const double t1 = t1s + (t1e - t1s) * tEnd1;
caryclark@google.com73ca6242013-01-17 21:02:47 +0000236 Cubic part1;
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000237 sub_divide(cubic1, t1Start, t1, part1);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000238 Quadratic q1;
239 demote_cubic_to_quad(part1, q1);
240 // start here;
241 // should reduceOrder be looser in this use case if quartic is going to blow up on an
242 // extremely shallow quadratic?
caryclark@google.com73ca6242013-01-17 21:02:47 +0000243 Quadratic s1;
244 int o1 = reduceOrder(q1, s1);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000245 double t2Start = t2s;
caryclark@google.com73ca6242013-01-17 21:02:47 +0000246 int ts2Count = ts2.count();
247 for (int i2 = 0; i2 <= ts2Count; ++i2) {
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000248 const double tEnd2 = i2 < ts2Count ? ts2[i2] : 1;
249 const double t2 = t2s + (t2e - t2s) * tEnd2;
caryclark@google.com73ca6242013-01-17 21:02:47 +0000250 Cubic part2;
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000251 sub_divide(cubic2, t2Start, t2, part2);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000252 Quadratic q2;
253 demote_cubic_to_quad(part2, q2);
254 Quadratic s2;
255 double o2 = reduceOrder(q2, s2);
256 Intersections locals;
257 if (o1 == 3 && o2 == 3) {
258 intersect2(q1, q2, locals);
259 } else if (o1 <= 2 && o2 <= 2) {
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000260 locals.fUsed = intersect((const _Line&) s1, (const _Line&) s2, locals.fT[0],
261 locals.fT[1]);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000262 } else if (o1 == 3 && o2 <= 2) {
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000263 intersect(q1, (const _Line&) s2, locals);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000264 } else {
265 SkASSERT(o1 <= 2 && o2 == 3);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000266 intersect(q2, (const _Line&) s1, locals);
267 for (int s = 0; s < locals.fUsed; ++s) {
268 SkTSwap(locals.fT[0][s], locals.fT[1][s]);
caryclark@google.com73ca6242013-01-17 21:02:47 +0000269 }
270 }
271 for (int tIdx = 0; tIdx < locals.used(); ++tIdx) {
272 double to1 = t1Start + (t1 - t1Start) * locals.fT[0][tIdx];
273 double to2 = t2Start + (t2 - t2Start) * locals.fT[1][tIdx];
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000274 // if the computed t is not sufficiently precise, iterate
275 _Point p1, p2;
276 xy_at_t(cubic1, to1, p1.x, p1.y);
277 xy_at_t(cubic2, to2, p2.x, p2.y);
278 if (p1.approximatelyEqual(p2)) {
279 i.insert(i.swapped() ? to2 : to1, i.swapped() ? to1 : to2);
280 } else {
caryclark@google.com9f602912013-01-24 21:47:16 +0000281 double dt1, dt2;
282 computeDelta(cubic1, to1, (t1e - t1s), cubic2, to2, (t2e - t2s), dt1, dt2);
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000283 double scale = precisionScale;
284 if (dt1 > 0.125 || dt2 > 0.125) {
285 scale /= 2;
286 SkDebugf("%s scale=%1.9g\n", __FUNCTION__, scale);
287 }
288#if SK_DEBUG
caryclark@google.com9f602912013-01-24 21:47:16 +0000289 ++debugDepth;
290 assert(debugDepth < 10);
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000291#endif
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000292 i.swap();
caryclark@google.com9f602912013-01-24 21:47:16 +0000293 intersect2(cubic2, SkTMax(to2 - dt2, 0.), SkTMin(to2 + dt2, 1.),
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000294 cubic1, SkTMax(to1 - dt1, 0.), SkTMin(to1 + dt1, 1.), scale, i);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000295 i.swap();
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000296#if SK_DEBUG
caryclark@google.com9f602912013-01-24 21:47:16 +0000297 --debugDepth;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000298#endif
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000299 }
caryclark@google.com73ca6242013-01-17 21:02:47 +0000300 }
301 t2Start = t2;
302 }
303 t1Start = t1;
304 }
305 return i.intersected();
306}
307
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000308static bool intersectEnd(const Cubic& cubic1, bool start, const Cubic& cubic2, const _Rect& bounds2,
309 Intersections& i) {
310 _Line line1;
311 line1[0] = line1[1] = cubic1[start ? 0 : 3];
312 _Point dxy1 = line1[0] - cubic1[start ? 1 : 2];
313 dxy1 /= precisionUnit;
314 line1[1] += dxy1;
315 _Rect line1Bounds;
316 line1Bounds.setBounds(line1);
317 if (!bounds2.intersects(line1Bounds)) {
318 return false;
319 }
320 _Line line2;
321 line2[0] = line2[1] = line1[0];
322 _Point dxy2 = line2[0] - cubic1[start ? 3 : 0];
323 dxy2 /= precisionUnit;
324 line2[1] += dxy2;
325#if 0 // this is so close to the first bounds test it isn't worth the short circuit test
326 _Rect line2Bounds;
327 line2Bounds.setBounds(line2);
328 if (!bounds2.intersects(line2Bounds)) {
329 return false;
330 }
331#endif
332 Intersections local1;
333 if (!intersect(cubic2, line1, local1)) {
334 return false;
335 }
336 Intersections local2;
337 if (!intersect(cubic2, line2, local2)) {
338 return false;
339 }
340 double tMin, tMax;
341 tMin = tMax = local1.fT[0][0];
342 for (int index = 1; index < local1.fUsed; ++index) {
343 tMin = std::min(tMin, local1.fT[0][index]);
344 tMax = std::max(tMax, local1.fT[0][index]);
345 }
346 for (int index = 1; index < local2.fUsed; ++index) {
347 tMin = std::min(tMin, local2.fT[0][index]);
348 tMax = std::max(tMax, local2.fT[0][index]);
349 }
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000350#if SK_DEBUG
caryclark@google.com9f602912013-01-24 21:47:16 +0000351 debugDepth = 0;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000352#endif
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000353 return intersect2(cubic1, start ? 0 : 1, start ? 1.0 / precisionUnit : 1 - 1.0 / precisionUnit,
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000354 cubic2, tMin, tMax, 1, i);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000355}
356
357// FIXME: add intersection of convex null on cubics' ends with the opposite cubic. The hull line
358// segments can be constructed to be only as long as the calculated precision suggests. If the hull
359// line segments intersect the cubic, then use the intersections to construct a subdivision for
360// quadratic curve fitting.
361bool intersect2(const Cubic& c1, const Cubic& c2, Intersections& i) {
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000362#if SK_DEBUG
caryclark@google.com9f602912013-01-24 21:47:16 +0000363 debugDepth = 0;
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000364#endif
365 bool result = intersect2(c1, 0, 1, c2, 0, 1, 1, i);
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000366 // FIXME: pass in cached bounds from caller
367 _Rect c1Bounds, c2Bounds;
368 c1Bounds.setBounds(c1); // OPTIMIZE use setRawBounds ?
369 c2Bounds.setBounds(c2);
370 result |= intersectEnd(c1, false, c2, c2Bounds, i);
371 result |= intersectEnd(c1, true, c2, c2Bounds, i);
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000372 i.swap();
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000373 result |= intersectEnd(c2, false, c1, c1Bounds, i);
374 result |= intersectEnd(c2, true, c1, c1Bounds, i);
caryclark@google.com85ec74c2013-01-28 19:25:51 +0000375 i.swap();
caryclark@google.com05c4bad2013-01-19 13:22:39 +0000376 return result;
377}
378
caryclark@google.com73ca6242013-01-17 21:02:47 +0000379int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& i) {
380 SkTDArray<double> ts;
381 double precision = calcPrecision(cubic);
382 cubic_to_quadratics(cubic, precision, ts);
383 double tStart = 0;
384 Cubic part;
385 int tsCount = ts.count();
386 for (int idx = 0; idx <= tsCount; ++idx) {
387 double t = idx < tsCount ? ts[idx] : 1;
388 Quadratic q1;
389 sub_divide(cubic, tStart, t, part);
390 demote_cubic_to_quad(part, q1);
391 Intersections locals;
392 intersect2(q1, quad, locals);
393 for (int tIdx = 0; tIdx < locals.used(); ++tIdx) {
394 double globalT = tStart + (t - tStart) * locals.fT[0][tIdx];
395 i.insertOne(globalT, 0);
396 globalT = locals.fT[1][tIdx];
397 i.insertOne(globalT, 1);
398 }
399 tStart = t;
400 }
401 return i.used();
402}
403
404bool intersect(const Cubic& cubic, Intersections& i) {
405 SkTDArray<double> ts;
406 double precision = calcPrecision(cubic);
407 cubic_to_quadratics(cubic, precision, ts);
408 int tsCount = ts.count();
409 if (tsCount == 1) {
410 return false;
411 }
412 double t1Start = 0;
413 Cubic part;
414 for (int idx = 0; idx < tsCount; ++idx) {
415 double t1 = ts[idx];
416 Quadratic q1;
417 sub_divide(cubic, t1Start, t1, part);
418 demote_cubic_to_quad(part, q1);
419 double t2Start = t1;
420 for (int i2 = idx + 1; i2 <= tsCount; ++i2) {
421 const double t2 = i2 < tsCount ? ts[i2] : 1;
422 Quadratic q2;
423 sub_divide(cubic, t2Start, t2, part);
424 demote_cubic_to_quad(part, q2);
425 Intersections locals;
426 intersect2(q1, q2, locals);
427 for (int tIdx = 0; tIdx < locals.used(); ++tIdx) {
428 // discard intersections at cusp? (maximum curvature)
429 double t1sect = locals.fT[0][tIdx];
430 double t2sect = locals.fT[1][tIdx];
431 if (idx + 1 == i2 && t1sect == 1 && t2sect == 0) {
432 continue;
433 }
434 double to1 = t1Start + (t1 - t1Start) * t1sect;
435 double to2 = t2Start + (t2 - t2Start) * t2sect;
436 i.insert(to1, to2);
437 }
438 t2Start = t2;
439 }
440 t1Start = t1;
441 }
442 return i.intersected();
443}