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

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

Issue 252243003: fix cubic/line intersection; add skp tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bracket new test correctly Created 6 years, 7 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
« no previous file with comments | « no previous file | tests/PathOpsCubicLineIntersectionTest.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 #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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | tests/PathOpsCubicLineIntersectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698