Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: src/pathops/SkDCubicIntersection.cpp

Issue 23542056: path ops work in progress (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: verbose + mutex around file number access Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkAddIntersections.cpp ('k') | src/pathops/SkDCubicLineIntersection.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkIntersections.h" 8 #include "SkIntersections.h"
9 #include "SkPathOpsCubic.h" 9 #include "SkPathOpsCubic.h"
10 #include "SkPathOpsLine.h" 10 #include "SkPathOpsLine.h"
11 #include "SkPathOpsPoint.h" 11 #include "SkPathOpsPoint.h"
12 #include "SkPathOpsQuad.h" 12 #include "SkPathOpsQuad.h"
13 #include "SkPathOpsRect.h" 13 #include "SkPathOpsRect.h"
14 #include "SkReduceOrder.h" 14 #include "SkReduceOrder.h"
15 #include "SkTSort.h" 15 #include "SkTSort.h"
16 16
17 #if ONE_OFF_DEBUG 17 #if ONE_OFF_DEBUG
18 static const double tLimits1[2][2] = {{0.388600450, 0.388600452}, {0.245852802, 0.245852804}}; 18 static const double tLimits1[2][2] = {{0.3, 0.4}, {0.8, 0.9}};
19 static const double tLimits2[2][2] = {{-0.865211397, -0.865215212}, {-0.86520769 6, -0.865208078}}; 19 static const double tLimits2[2][2] = {{-0.8, -0.9}, {-0.8, -0.9}};
20 #endif 20 #endif
21 21
22 #define DEBUG_QUAD_PART ONE_OFF_DEBUG && 1 22 #define DEBUG_QUAD_PART ONE_OFF_DEBUG && 1
23 #define DEBUG_QUAD_PART_SHOW_SIMPLE DEBUG_QUAD_PART && 0 23 #define DEBUG_QUAD_PART_SHOW_SIMPLE DEBUG_QUAD_PART && 0
24 #define SWAP_TOP_DEBUG 0 24 #define SWAP_TOP_DEBUG 0
25 25
26 static const int kCubicToQuadSubdivisionDepth = 8; // slots reserved for cubic t o quads subdivision 26 static const int kCubicToQuadSubdivisionDepth = 8; // slots reserved for cubic t o quads subdivision
27 27
28 static int quadPart(const SkDCubic& cubic, double tStart, double tEnd, SkReduceO rder* reducer) { 28 static int quadPart(const SkDCubic& cubic, double tStart, double tEnd, SkReduceO rder* reducer) {
29 SkDCubic part = cubic.subDivide(tStart, tEnd); 29 SkDCubic part = cubic.subDivide(tStart, tEnd);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 locals.allowNear(false); 117 locals.allowNear(false);
118 intersectWithOrder(s1.fQuad, o1, s2.fQuad, o2, locals); 118 intersectWithOrder(s1.fQuad, o1, s2.fQuad, o2, locals);
119 int tCount = locals.used(); 119 int tCount = locals.used();
120 for (int tIdx = 0; tIdx < tCount; ++tIdx) { 120 for (int tIdx = 0; tIdx < tCount; ++tIdx) {
121 double to1 = t1Start + (t1 - t1Start) * locals[0][tIdx]; 121 double to1 = t1Start + (t1 - t1Start) * locals[0][tIdx];
122 double to2 = t2Start + (t2 - t2Start) * locals[1][tIdx]; 122 double to2 = t2Start + (t2 - t2Start) * locals[1][tIdx];
123 // if the computed t is not sufficiently precise, iterate 123 // if the computed t is not sufficiently precise, iterate
124 SkDPoint p1 = cubic1.ptAtT(to1); 124 SkDPoint p1 = cubic1.ptAtT(to1);
125 SkDPoint p2 = cubic2.ptAtT(to2); 125 SkDPoint p2 = cubic2.ptAtT(to2);
126 if (p1.approximatelyEqual(p2)) { 126 if (p1.approximatelyEqual(p2)) {
127 SkASSERT(!locals.isCoincident(tIdx)); 127 // FIXME: local edge may be coincident -- experiment with not propagating co incidence to caller
128 // SkASSERT(!locals.isCoincident(tIdx));
128 if (&cubic1 != &cubic2 || !approximately_equal(to1, to2)) { 129 if (&cubic1 != &cubic2 || !approximately_equal(to1, to2)) {
129 if (i.swapped()) { // FIXME: insert should respect swa p 130 if (i.swapped()) { // FIXME: insert should respect swa p
130 i.insert(to2, to1, p1); 131 i.insert(to2, to1, p1);
131 } else { 132 } else {
132 i.insert(to1, to2, p1); 133 i.insert(to1, to2, p1);
133 } 134 }
134 } 135 }
135 } else { 136 } else {
136 double offset = precisionScale / 16; // FIME: const is arbi trary: test, refine 137 double offset = precisionScale / 16; // FIME: const is arbi trary: test, refine
137 double c1Bottom = tIdx == 0 ? 0 : 138 double c1Bottom = tIdx == 0 ? 0 :
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // for that. 243 // for that.
243 } 244 }
244 } 245 }
245 t2Start = t2; 246 t2Start = t2;
246 } 247 }
247 t1Start = t1; 248 t1Start = t1;
248 } 249 }
249 i.downDepth(); 250 i.downDepth();
250 } 251 }
251 252
253 // if two ends intersect, check middle for coincidence
254 bool SkIntersections::cubicCheckCoincidence(const SkDCubic& c1, const SkDCubic& c2) {
255 if (fUsed < 2) {
256 return false;
257 }
258 int last = fUsed - 1;
259 double tRange1 = fT[0][last] - fT[0][0];
260 double tRange2 = fT[1][last] - fT[1][0];
261 for (int index = 1; index < 5; ++index) {
262 double testT1 = fT[0][0] + tRange1 * index / 5;
263 double testT2 = fT[1][0] + tRange2 * index / 5;
264 SkDPoint testPt1 = c1.ptAtT(testT1);
265 SkDPoint testPt2 = c2.ptAtT(testT2);
266 if (!testPt1.approximatelyEqual(testPt2)) {
267 return false;
268 }
269 }
270 if (fUsed > 2) {
271 fPt[1] = fPt[last];
272 fT[0][1] = fT[0][last];
273 fT[1][1] = fT[1][last];
274 fUsed = 2;
275 }
276 fIsCoincident[0] = fIsCoincident[1] = 0x03;
277 return true;
278 }
279
252 #define LINE_FRACTION 0.1 280 #define LINE_FRACTION 0.1
253 281
254 // intersect the end of the cubic with the other. Try lines from the end to cont rol and opposite 282 // intersect the end of the cubic with the other. Try lines from the end to cont rol and opposite
255 // end to determine range of t on opposite cubic. 283 // end to determine range of t on opposite cubic.
256 static void intersectEnd(const SkDCubic& cubic1, bool start, const SkDCubic& cub ic2, 284 bool SkIntersections::cubicExactEnd(const SkDCubic& cubic1, bool start, const Sk DCubic& cubic2) {
257 const SkDRect& bounds2, bool selfIntersect, SkIntersect ions& i) { 285 int t1Index = start ? 0 : 3;
286 double testT = (double) !start;
287 bool swap = swapped();
288 // quad/quad at this point checks to see if exact matches have already been found
289 // cubic/cubic can't reject so easily since cubics can intersect same point more than once
290 SkDLine tmpLine;
291 tmpLine[0] = tmpLine[1] = cubic2[t1Index];
292 tmpLine[1].fX += cubic2[2 - start].fY - cubic2[t1Index].fY;
293 tmpLine[1].fY -= cubic2[2 - start].fX - cubic2[t1Index].fX;
294 SkIntersections impTs;
295 impTs.intersectRay(cubic1, tmpLine);
296 for (int index = 0; index < impTs.used(); ++index) {
297 SkDPoint realPt = impTs.pt(index);
298 if (!tmpLine[0].approximatelyEqual(realPt)) {
299 continue;
300 }
301 if (swap) {
302 insert(testT, impTs[0][index], tmpLine[0]);
303 } else {
304 insert(impTs[0][index], testT, tmpLine[0]);
305 }
306 return true;
307 }
308 return false;
309 }
310
311 void SkIntersections::cubicNearEnd(const SkDCubic& cubic1, bool start, const SkD Cubic& cubic2,
312 const SkDRect& bounds2) {
258 SkDLine line; 313 SkDLine line;
259 int t1Index = start ? 0 : 3; 314 int t1Index = start ? 0 : 3;
260 bool swap = i.swapped();
261 double testT = (double) !start; 315 double testT = (double) !start;
262 // quad/quad at this point checks to see if exact matches have already been found 316 // don't bother if the two cubics are connnected
263 // cubic/cubic can't reject so easily since cubics can intersect same point more than once
264 if (!selfIntersect) {
265 SkDLine tmpLine;
266 tmpLine[0] = tmpLine[1] = cubic2[t1Index];
267 tmpLine[1].fX += cubic2[2 - start].fY - cubic2[t1Index].fY;
268 tmpLine[1].fY -= cubic2[2 - start].fX - cubic2[t1Index].fX;
269 SkIntersections impTs;
270 impTs.intersectRay(cubic1, tmpLine);
271 for (int index = 0; index < impTs.used(); ++index) {
272 SkDPoint realPt = impTs.pt(index);
273 if (!tmpLine[0].approximatelyEqualHalf(realPt)) {
274 continue;
275 }
276 if (swap) {
277 i.insert(testT, impTs[0][index], tmpLine[0]);
278 } else {
279 i.insert(impTs[0][index], testT, tmpLine[0]);
280 }
281 return;
282 }
283 }
284 // don't bother if the two cubics are connnected
285 static const int kPointsInCubic = 4; // FIXME: move to DCubic, replace '4' w ith this 317 static const int kPointsInCubic = 4; // FIXME: move to DCubic, replace '4' w ith this
286 static const int kMaxLineCubicIntersections = 3; 318 static const int kMaxLineCubicIntersections = 3;
287 SkSTArray<(kMaxLineCubicIntersections - 1) * kMaxLineCubicIntersections, dou ble, true> tVals; 319 SkSTArray<(kMaxLineCubicIntersections - 1) * kMaxLineCubicIntersections, dou ble, true> tVals;
288 line[0] = cubic1[t1Index]; 320 line[0] = cubic1[t1Index];
289 // this variant looks for intersections with the end point and lines paralle l to other points 321 // this variant looks for intersections with the end point and lines paralle l to other points
290 for (int index = 0; index < kPointsInCubic; ++index) { 322 for (int index = 0; index < kPointsInCubic; ++index) {
291 if (index == t1Index) { 323 if (index == t1Index) {
292 continue; 324 continue;
293 } 325 }
294 SkDVector dxy1 = cubic1[index] - line[0]; 326 SkDVector dxy1 = cubic1[index] - line[0];
295 dxy1 /= SkDCubic::gPrecisionUnit; 327 dxy1 /= SkDCubic::gPrecisionUnit;
296 line[1] = line[0] + dxy1; 328 line[1] = line[0] + dxy1;
297 SkDRect lineBounds; 329 SkDRect lineBounds;
298 lineBounds.setBounds(line); 330 lineBounds.setBounds(line);
299 if (!bounds2.intersects(&lineBounds)) { 331 if (!bounds2.intersects(&lineBounds)) {
300 continue; 332 continue;
301 } 333 }
302 SkIntersections local; 334 SkIntersections local;
303 if (!local.intersect(cubic2, line)) { 335 if (!local.intersect(cubic2, line)) {
304 continue; 336 continue;
305 } 337 }
306 for (int idx2 = 0; idx2 < local.used(); ++idx2) { 338 for (int idx2 = 0; idx2 < local.used(); ++idx2) {
307 double foundT = local[0][idx2]; 339 double foundT = local[0][idx2];
308 if (approximately_less_than_zero(foundT) 340 if (approximately_less_than_zero(foundT)
309 || approximately_greater_than_one(foundT)) { 341 || approximately_greater_than_one(foundT)) {
310 continue; 342 continue;
311 } 343 }
312 if (local.pt(idx2).approximatelyEqual(line[0])) { 344 if (local.pt(idx2).approximatelyEqual(line[0])) {
313 if (i.swapped()) { // FIXME: insert should respect swap 345 if (swapped()) { // FIXME: insert should respect swap
314 i.insert(foundT, testT, line[0]); 346 insert(foundT, testT, line[0]);
315 } else { 347 } else {
316 i.insert(testT, foundT, line[0]); 348 insert(testT, foundT, line[0]);
317 } 349 }
318 } else { 350 } else {
319 tVals.push_back(foundT); 351 tVals.push_back(foundT);
320 } 352 }
321 } 353 }
322 } 354 }
323 if (tVals.count() == 0) { 355 if (tVals.count() == 0) {
324 return; 356 return;
325 } 357 }
326 SkTQSort<double>(tVals.begin(), tVals.end() - 1); 358 SkTQSort<double>(tVals.begin(), tVals.end() - 1);
327 double tMin1 = start ? 0 : 1 - LINE_FRACTION; 359 double tMin1 = start ? 0 : 1 - LINE_FRACTION;
328 double tMax1 = start ? LINE_FRACTION : 1; 360 double tMax1 = start ? LINE_FRACTION : 1;
329 int tIdx = 0; 361 int tIdx = 0;
330 do { 362 do {
331 int tLast = tIdx; 363 int tLast = tIdx;
332 while (tLast + 1 < tVals.count() && roughly_equal(tVals[tLast + 1], tVal s[tIdx])) { 364 while (tLast + 1 < tVals.count() && roughly_equal(tVals[tLast + 1], tVal s[tIdx])) {
333 ++tLast; 365 ++tLast;
334 } 366 }
335 double tMin2 = SkTMax(tVals[tIdx] - LINE_FRACTION, 0.0); 367 double tMin2 = SkTMax(tVals[tIdx] - LINE_FRACTION, 0.0);
336 double tMax2 = SkTMin(tVals[tLast] + LINE_FRACTION, 1.0); 368 double tMax2 = SkTMin(tVals[tLast] + LINE_FRACTION, 1.0);
337 int lastUsed = i.used(); 369 int lastUsed = used();
338 intersect(cubic1, tMin1, tMax1, cubic2, tMin2, tMax2, 1, i); 370 ::intersect(cubic1, tMin1, tMax1, cubic2, tMin2, tMax2, 1, *this);
339 if (lastUsed == i.used()) { 371 if (lastUsed == used()) {
340 tMin2 = SkTMax(tVals[tIdx] - (1.0 / SkDCubic::gPrecisionUnit), 0.0); 372 tMin2 = SkTMax(tVals[tIdx] - (1.0 / SkDCubic::gPrecisionUnit), 0.0);
341 tMax2 = SkTMin(tVals[tLast] + (1.0 / SkDCubic::gPrecisionUnit), 1.0) ; 373 tMax2 = SkTMin(tVals[tLast] + (1.0 / SkDCubic::gPrecisionUnit), 1.0) ;
342 intersect(cubic1, tMin1, tMax1, cubic2, tMin2, tMax2, 1, i); 374 ::intersect(cubic1, tMin1, tMax1, cubic2, tMin2, tMax2, 1, *this);
343 } 375 }
344 tIdx = tLast + 1; 376 tIdx = tLast + 1;
345 } while (tIdx < tVals.count()); 377 } while (tIdx < tVals.count());
346 return; 378 return;
347 } 379 }
348 380
349 const double CLOSE_ENOUGH = 0.001; 381 const double CLOSE_ENOUGH = 0.001;
350 382
351 static bool closeStart(const SkDCubic& cubic, int cubicIndex, SkIntersections& i , SkDPoint& pt) { 383 static bool closeStart(const SkDCubic& cubic, int cubicIndex, SkIntersections& i , SkDPoint& pt) {
352 if (i[cubicIndex][0] != 0 || i[cubicIndex][1] > CLOSE_ENOUGH) { 384 if (i[cubicIndex][0] != 0 || i[cubicIndex][1] > CLOSE_ENOUGH) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 429 }
398 } 430 }
399 return true; 431 return true;
400 tryNextHalfPlane: 432 tryNextHalfPlane:
401 ; 433 ;
402 } 434 }
403 return false; 435 return false;
404 } 436 }
405 437
406 int SkIntersections::intersect(const SkDCubic& c1, const SkDCubic& c2) { 438 int SkIntersections::intersect(const SkDCubic& c1, const SkDCubic& c2) {
439 if (fMax == 0) {
440 fMax = 9;
441 }
407 bool selfIntersect = &c1 == &c2; 442 bool selfIntersect = &c1 == &c2;
408 if (selfIntersect) { 443 if (selfIntersect) {
409 if (c1[0].approximatelyEqualHalf(c1[3])) { 444 if (c1[0].approximatelyEqual(c1[3])) {
410 insert(0, 1, c1[0]); 445 insert(0, 1, c1[0]);
446 return fUsed;
411 } 447 }
412 } else { 448 } else {
413 for (int i1 = 0; i1 < 4; i1 += 3) { 449 for (int i1 = 0; i1 < 4; i1 += 3) {
414 for (int i2 = 0; i2 < 4; i2 += 3) { 450 for (int i2 = 0; i2 < 4; i2 += 3) {
415 if (c1[i1].approximatelyEqualHalf(c2[i2])) { 451 if (c1[i1].approximatelyEqual(c2[i2])) {
416 insert(i1 >> 1, i2 >> 1, c1[i1]); 452 insert(i1 >> 1, i2 >> 1, c1[i1]);
417 } 453 }
418 } 454 }
419 } 455 }
420 } 456 }
421 SkASSERT(fUsed < 4); 457 SkASSERT(fUsed < 4);
422 if (!selfIntersect) { 458 if (!selfIntersect) {
423 if (only_end_pts_in_common(c1, c2)) { 459 if (only_end_pts_in_common(c1, c2)) {
424 return fUsed; 460 return fUsed;
425 } 461 }
426 if (only_end_pts_in_common(c2, c1)) { 462 if (only_end_pts_in_common(c2, c1)) {
427 return fUsed; 463 return fUsed;
428 } 464 }
429 } 465 }
430 // quad/quad does linear test here -- cubic does not 466 // quad/quad does linear test here -- cubic does not
431 // cubics which are really lines should have been detected in reduce step ea rlier 467 // cubics which are really lines should have been detected in reduce step ea rlier
432 SkDRect c1Bounds, c2Bounds; 468 int exactEndBits = 0;
433 // FIXME: pass in cached bounds from caller
434 c1Bounds.setBounds(c1); // OPTIMIZE use setRawBounds ?
435 c2Bounds.setBounds(c2);
436 intersectEnd(c1, false, c2, c2Bounds, selfIntersect, *this);
437 intersectEnd(c1, true, c2, c2Bounds, selfIntersect, *this);
438 if (selfIntersect) { 469 if (selfIntersect) {
439 if (fUsed) { 470 if (fUsed) {
440 return fUsed; 471 return fUsed;
441 } 472 }
442 } else { 473 } else {
474 exactEndBits |= cubicExactEnd(c1, false, c2) << 0;
475 exactEndBits |= cubicExactEnd(c1, true, c2) << 1;
443 swap(); 476 swap();
444 intersectEnd(c2, false, c1, c1Bounds, false, *this); 477 exactEndBits |= cubicExactEnd(c2, false, c1) << 2;
445 intersectEnd(c2, true, c1, c1Bounds, false, *this); 478 exactEndBits |= cubicExactEnd(c2, true, c1) << 3;
446 swap(); 479 swap();
447 } 480 }
448 // if two ends intersect, check middle for coincidence 481 if (cubicCheckCoincidence(c1, c2)) {
449 if (fUsed >= 2) {
450 SkASSERT(!selfIntersect); 482 SkASSERT(!selfIntersect);
451 int last = fUsed - 1;
452 double tRange1 = fT[0][last] - fT[0][0];
453 double tRange2 = fT[1][last] - fT[1][0];
454 for (int index = 1; index < 5; ++index) {
455 double testT1 = fT[0][0] + tRange1 * index / 5;
456 double testT2 = fT[1][0] + tRange2 * index / 5;
457 SkDPoint testPt1 = c1.ptAtT(testT1);
458 SkDPoint testPt2 = c2.ptAtT(testT2);
459 if (!testPt1.approximatelyEqual(testPt2)) {
460 goto skipCoincidence;
461 }
462 }
463 if (fUsed > 2) {
464 fPt[1] = fPt[last];
465 fT[0][1] = fT[0][last];
466 fT[1][1] = fT[1][last];
467 fUsed = 2;
468 }
469 fIsCoincident[0] = fIsCoincident[1] = 0x03;
470 return fUsed; 483 return fUsed;
471 } 484 }
472 skipCoincidence: 485 // FIXME: pass in cached bounds from caller
486 SkDRect c1Bounds, c2Bounds;
487 c1Bounds.setBounds(c1); // OPTIMIZE use setRawBounds ?
488 c2Bounds.setBounds(c2);
489 if (!(exactEndBits & 1)) {
490 cubicNearEnd(c1, false, c2, c2Bounds);
491 }
492 if (!(exactEndBits & 2)) {
493 cubicNearEnd(c1, true, c2, c2Bounds);
494 }
495 if (!selfIntersect) {
496 swap();
497 if (!(exactEndBits & 4)) {
498 cubicNearEnd(c2, false, c1, c1Bounds);
499 }
500 if (!(exactEndBits & 8)) {
501 cubicNearEnd(c2, true, c1, c1Bounds);
502 }
503 swap();
504 }
505 if (cubicCheckCoincidence(c1, c2)) {
506 SkASSERT(!selfIntersect);
507 return fUsed;
508 }
473 ::intersect(c1, 0, 1, c2, 0, 1, 1, *this); 509 ::intersect(c1, 0, 1, c2, 0, 1, 1, *this);
474 // If an end point and a second point very close to the end is returned, the second 510 // If an end point and a second point very close to the end is returned, the second
475 // point may have been detected because the approximate quads 511 // point may have been detected because the approximate quads
476 // intersected at the end and close to it. Verify that the second point is v alid. 512 // intersected at the end and close to it. Verify that the second point is v alid.
477 if (fUsed <= 1) { 513 if (fUsed <= 1) {
478 return fUsed; 514 return fUsed;
479 } 515 }
480 SkDPoint pt[2]; 516 SkDPoint pt[2];
481 if (closeStart(c1, 0, *this, pt[0]) && closeStart(c2, 1, *this, pt[1]) 517 if (closeStart(c1, 0, *this, pt[0]) && closeStart(c2, 1, *this, pt[1])
482 && pt[0].approximatelyEqual(pt[1])) { 518 && pt[0].approximatelyEqual(pt[1])) {
(...skipping 11 matching lines...) Expand all
494 for (int index = 0; index < last; ++index) { 530 for (int index = 0; index < last; ++index) {
495 double mid1 = (fT[0][index] + fT[0][index + 1]) / 2; 531 double mid1 = (fT[0][index] + fT[0][index + 1]) / 2;
496 double mid2 = (fT[1][index] + fT[1][index + 1]) / 2; 532 double mid2 = (fT[1][index] + fT[1][index + 1]) / 2;
497 pt[0] = c1.ptAtT(mid1); 533 pt[0] = c1.ptAtT(mid1);
498 pt[1] = c2.ptAtT(mid2); 534 pt[1] = c2.ptAtT(mid2);
499 if (pt[0].approximatelyEqual(pt[1])) { 535 if (pt[0].approximatelyEqual(pt[1])) {
500 match |= 1 << index; 536 match |= 1 << index;
501 } 537 }
502 } 538 }
503 if (match) { 539 if (match) {
540 #if DEBUG_CONCIDENT
504 if (((match + 1) & match) != 0) { 541 if (((match + 1) & match) != 0) {
505 SkDebugf("%s coincident hole\n", __FUNCTION__); 542 SkDebugf("%s coincident hole\n", __FUNCTION__);
506 } 543 }
544 #endif
507 // for now, assume that everything from start to finish is coinciden t 545 // for now, assume that everything from start to finish is coinciden t
508 if (fUsed > 2) { 546 if (fUsed > 2) {
509 fPt[1] = fPt[last]; 547 fPt[1] = fPt[last];
510 fT[0][1] = fT[0][last]; 548 fT[0][1] = fT[0][last];
511 fT[1][1] = fT[1][last]; 549 fT[1][1] = fT[1][last];
512 fIsCoincident[0] = 0x03; 550 fIsCoincident[0] = 0x03;
513 fIsCoincident[1] = 0x03; 551 fIsCoincident[1] = 0x03;
514 fUsed = 2; 552 fUsed = 2;
515 } 553 }
516 } 554 }
517 } 555 }
518 return fUsed; 556 return fUsed;
519 } 557 }
520 558
521 // Up promote the quad to a cubic. 559 // Up promote the quad to a cubic.
522 // OPTIMIZATION If this is a common use case, optimize by duplicating 560 // OPTIMIZATION If this is a common use case, optimize by duplicating
523 // the intersect 3 loop to avoid the promotion / demotion code 561 // the intersect 3 loop to avoid the promotion / demotion code
524 int SkIntersections::intersect(const SkDCubic& cubic, const SkDQuad& quad) { 562 int SkIntersections::intersect(const SkDCubic& cubic, const SkDQuad& quad) {
563 fMax = 6;
525 SkDCubic up = quad.toCubic(); 564 SkDCubic up = quad.toCubic();
526 (void) intersect(cubic, up); 565 (void) intersect(cubic, up);
527 return used(); 566 return used();
528 } 567 }
529 568
530 /* http://www.ag.jku.at/compass/compasssample.pdf 569 /* http://www.ag.jku.at/compass/compasssample.pdf
531 ( Self-Intersection Problems and Approximate Implicitization by Jan B. Thomassen 570 ( Self-Intersection Problems and Approximate Implicitization by Jan B. Thomassen
532 Centre of Mathematics for Applications, University of Oslo http://www.cma.uio.no janbth@math.uio.no 571 Centre of Mathematics for Applications, University of Oslo http://www.cma.uio.no janbth@math.uio.no
533 SINTEF Applied Mathematics http://www.sintef.no ) 572 SINTEF Applied Mathematics http://www.sintef.no )
534 describes a method to find the self intersection of a cubic by taking the gradie nt of the implicit 573 describes a method to find the self intersection of a cubic by taking the gradie nt of the implicit
535 form dotted with the normal, and solving for the roots. My math foo is too poor to implement this.*/ 574 form dotted with the normal, and solving for the roots. My math foo is too poor to implement this.*/
536 575
537 int SkIntersections::intersect(const SkDCubic& c) { 576 int SkIntersections::intersect(const SkDCubic& c) {
577 fMax = 1;
538 // check to see if x or y end points are the extrema. Are other quick reject s possible? 578 // check to see if x or y end points are the extrema. Are other quick reject s possible?
539 if (c.endsAreExtremaInXOrY()) { 579 if (c.endsAreExtremaInXOrY()) {
540 return false; 580 return false;
541 } 581 }
542 (void) intersect(c, c); 582 (void) intersect(c, c);
543 if (used() > 0) { 583 if (used() > 0) {
544 SkASSERT(used() == 1); 584 SkASSERT(used() == 1);
545 if (fT[0][0] > fT[1][0]) { 585 if (fT[0][0] > fT[1][0]) {
546 swapPts(); 586 swapPts();
547 } 587 }
548 } 588 }
549 return used(); 589 return used();
550 } 590 }
OLDNEW
« no previous file with comments | « src/pathops/SkAddIntersections.cpp ('k') | src/pathops/SkDCubicLineIntersection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698