| OLD | NEW |
| 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 #include "SkIntersections.h" | 7 #include "SkIntersections.h" |
| 8 #include "SkPathOpsCubic.h" | 8 #include "SkPathOpsCubic.h" |
| 9 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
| 10 | 10 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 bool pinTs(double* cubicT, double* lineT, SkDPoint* pt, PinTPoint ptSet) { | 296 bool pinTs(double* cubicT, double* lineT, SkDPoint* pt, PinTPoint ptSet) { |
| 297 if (!approximately_one_or_less(*lineT)) { | 297 if (!approximately_one_or_less(*lineT)) { |
| 298 return false; | 298 return false; |
| 299 } | 299 } |
| 300 if (!approximately_zero_or_more(*lineT)) { | 300 if (!approximately_zero_or_more(*lineT)) { |
| 301 return false; | 301 return false; |
| 302 } | 302 } |
| 303 double cT = *cubicT = SkPinT(*cubicT); | 303 double cT = *cubicT = SkPinT(*cubicT); |
| 304 double lT = *lineT = SkPinT(*lineT); | 304 double lT = *lineT = SkPinT(*lineT); |
| 305 SkDPoint lPt = fLine.ptAtT(lT); |
| 306 SkDPoint cPt = fCubic.ptAtT(cT); |
| 307 if (!lPt.moreRoughlyEqual(cPt)) { |
| 308 return false; |
| 309 } |
| 310 // FIXME: if points are roughly equal but not approximately equal, need
to do |
| 311 // a binary search like quad/quad intersection to find more precise t va
lues |
| 305 if (lT == 0 || lT == 1 || (ptSet == kPointUninitialized && cT != 0 && cT
!= 1)) { | 312 if (lT == 0 || lT == 1 || (ptSet == kPointUninitialized && cT != 0 && cT
!= 1)) { |
| 306 *pt = fLine.ptAtT(lT); | 313 *pt = lPt; |
| 307 } else if (ptSet == kPointUninitialized) { | 314 } else if (ptSet == kPointUninitialized) { |
| 308 *pt = fCubic.ptAtT(cT); | 315 *pt = cPt; |
| 309 } | 316 } |
| 310 SkPoint gridPt = pt->asSkPoint(); | 317 SkPoint gridPt = pt->asSkPoint(); |
| 311 if (gridPt == fLine[0].asSkPoint()) { | 318 if (gridPt == fLine[0].asSkPoint()) { |
| 312 *lineT = 0; | 319 *lineT = 0; |
| 313 } else if (gridPt == fLine[1].asSkPoint()) { | 320 } else if (gridPt == fLine[1].asSkPoint()) { |
| 314 *lineT = 1; | 321 *lineT = 1; |
| 315 } | 322 } |
| 316 if (gridPt == fCubic[0].asSkPoint() && approximately_equal(*cubicT, 0))
{ | 323 if (gridPt == fCubic[0].asSkPoint() && approximately_equal(*cubicT, 0))
{ |
| 317 *cubicT = 0; | 324 *cubicT = 0; |
| 318 } else if (gridPt == fCubic[3].asSkPoint() && approximately_equal(*cubic
T, 1)) { | 325 } else if (gridPt == fCubic[3].asSkPoint() && approximately_equal(*cubic
T, 1)) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 349 } | 356 } |
| 350 | 357 |
| 351 int SkIntersections::intersectRay(const SkDCubic& cubic, const SkDLine& line) { | 358 int SkIntersections::intersectRay(const SkDCubic& cubic, const SkDLine& line) { |
| 352 LineCubicIntersections c(cubic, line, this); | 359 LineCubicIntersections c(cubic, line, this); |
| 353 fUsed = c.intersectRay(fT[0]); | 360 fUsed = c.intersectRay(fT[0]); |
| 354 for (int index = 0; index < fUsed; ++index) { | 361 for (int index = 0; index < fUsed; ++index) { |
| 355 fPt[index] = cubic.ptAtT(fT[0][index]); | 362 fPt[index] = cubic.ptAtT(fT[0][index]); |
| 356 } | 363 } |
| 357 return fUsed; | 364 return fUsed; |
| 358 } | 365 } |
| OLD | NEW |