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

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

Issue 2128633003: pathops coincidence and security rewrite (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: require resulting t to be between 0 and 1 Created 4 years, 5 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
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 "SkPathOpsCurve.h"
9 #include "SkPathOpsLine.h" 10 #include "SkPathOpsLine.h"
10 11
11 /* 12 /*
12 Find the interection of a line and cubic by solving for valid t values. 13 Find the interection of a line and cubic by solving for valid t values.
13 14
14 Analogous to line-quadratic intersection, solve line-cubic intersection by 15 Analogous to line-quadratic intersection, solve line-cubic intersection by
15 representing the cubic as: 16 representing the cubic as:
16 x = a(1-t)^3 + 2b(1-t)^2t + c(1-t)t^2 + dt^3 17 x = a(1-t)^3 + 2b(1-t)^2t + c(1-t)t^2 + dt^3
17 y = e(1-t)^3 + 2f(1-t)^2t + g(1-t)t^2 + ht^3 18 y = e(1-t)^3 + 2f(1-t)^2t + g(1-t)t^2 + ht^3
18 and the line as: 19 and the line as:
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 double cubicT = (double) (cIndex >> 1); 285 double cubicT = (double) (cIndex >> 1);
285 if (fIntersections->hasT(cubicT)) { 286 if (fIntersections->hasT(cubicT)) {
286 continue; 287 continue;
287 } 288 }
288 double lineT = fLine.nearPoint(fCubic[cIndex], nullptr); 289 double lineT = fLine.nearPoint(fCubic[cIndex], nullptr);
289 if (lineT < 0) { 290 if (lineT < 0) {
290 continue; 291 continue;
291 } 292 }
292 fIntersections->insert(cubicT, lineT, fCubic[cIndex]); 293 fIntersections->insert(cubicT, lineT, fCubic[cIndex]);
293 } 294 }
295 addLineNearEndPoints();
296 }
297
298 void addLineNearEndPoints() {
299 for (int lIndex = 0; lIndex < 2; ++lIndex) {
300 double lineT = (double) lIndex;
301 if (fIntersections->hasOppT(lineT)) {
302 continue;
303 }
304 double cubicT = ((SkDCurve*) &fCubic)->nearPoint(SkPath::kCubic_Verb ,
305 fLine[lIndex], fLine[!lIndex]);
306 if (cubicT < 0) {
307 continue;
308 }
309 fIntersections->insert(cubicT, lineT, fLine[lIndex]);
310 }
294 } 311 }
295 312
296 void addExactHorizontalEndPoints(double left, double right, double y) { 313 void addExactHorizontalEndPoints(double left, double right, double y) {
297 for (int cIndex = 0; cIndex < 4; cIndex += 3) { 314 for (int cIndex = 0; cIndex < 4; cIndex += 3) {
298 double lineT = SkDLine::ExactPointH(fCubic[cIndex], left, right, y); 315 double lineT = SkDLine::ExactPointH(fCubic[cIndex], left, right, y);
299 if (lineT < 0) { 316 if (lineT < 0) {
300 continue; 317 continue;
301 } 318 }
302 double cubicT = (double) (cIndex >> 1); 319 double cubicT = (double) (cIndex >> 1);
303 fIntersections->insert(cubicT, lineT, fCubic[cIndex]); 320 fIntersections->insert(cubicT, lineT, fCubic[cIndex]);
304 } 321 }
305 } 322 }
306 323
307 void addNearHorizontalEndPoints(double left, double right, double y) { 324 void addNearHorizontalEndPoints(double left, double right, double y) {
308 for (int cIndex = 0; cIndex < 4; cIndex += 3) { 325 for (int cIndex = 0; cIndex < 4; cIndex += 3) {
309 double cubicT = (double) (cIndex >> 1); 326 double cubicT = (double) (cIndex >> 1);
310 if (fIntersections->hasT(cubicT)) { 327 if (fIntersections->hasT(cubicT)) {
311 continue; 328 continue;
312 } 329 }
313 double lineT = SkDLine::NearPointH(fCubic[cIndex], left, right, y); 330 double lineT = SkDLine::NearPointH(fCubic[cIndex], left, right, y);
314 if (lineT < 0) { 331 if (lineT < 0) {
315 continue; 332 continue;
316 } 333 }
317 fIntersections->insert(cubicT, lineT, fCubic[cIndex]); 334 fIntersections->insert(cubicT, lineT, fCubic[cIndex]);
318 } 335 }
319 // FIXME: see if line end is nearly on cubic 336 addLineNearEndPoints();
herb_g 2016/07/18 15:13:39 this->
caryclark 2016/07/18 15:55:49 Done.
320 } 337 }
321 338
322 void addExactVerticalEndPoints(double top, double bottom, double x) { 339 void addExactVerticalEndPoints(double top, double bottom, double x) {
323 for (int cIndex = 0; cIndex < 4; cIndex += 3) { 340 for (int cIndex = 0; cIndex < 4; cIndex += 3) {
324 double lineT = SkDLine::ExactPointV(fCubic[cIndex], top, bottom, x); 341 double lineT = SkDLine::ExactPointV(fCubic[cIndex], top, bottom, x);
325 if (lineT < 0) { 342 if (lineT < 0) {
326 continue; 343 continue;
327 } 344 }
328 double cubicT = (double) (cIndex >> 1); 345 double cubicT = (double) (cIndex >> 1);
329 fIntersections->insert(cubicT, lineT, fCubic[cIndex]); 346 fIntersections->insert(cubicT, lineT, fCubic[cIndex]);
330 } 347 }
331 } 348 }
332 349
333 void addNearVerticalEndPoints(double top, double bottom, double x) { 350 void addNearVerticalEndPoints(double top, double bottom, double x) {
334 for (int cIndex = 0; cIndex < 4; cIndex += 3) { 351 for (int cIndex = 0; cIndex < 4; cIndex += 3) {
335 double cubicT = (double) (cIndex >> 1); 352 double cubicT = (double) (cIndex >> 1);
336 if (fIntersections->hasT(cubicT)) { 353 if (fIntersections->hasT(cubicT)) {
337 continue; 354 continue;
338 } 355 }
339 double lineT = SkDLine::NearPointV(fCubic[cIndex], top, bottom, x); 356 double lineT = SkDLine::NearPointV(fCubic[cIndex], top, bottom, x);
340 if (lineT < 0) { 357 if (lineT < 0) {
341 continue; 358 continue;
342 } 359 }
343 fIntersections->insert(cubicT, lineT, fCubic[cIndex]); 360 fIntersections->insert(cubicT, lineT, fCubic[cIndex]);
344 } 361 }
345 // FIXME: see if line end is nearly on cubic 362 addLineNearEndPoints();
346 } 363 }
347 364
348 double findLineT(double t) { 365 double findLineT(double t) {
349 SkDPoint xy = fCubic.ptAtT(t); 366 SkDPoint xy = fCubic.ptAtT(t);
350 double dx = fLine[1].fX - fLine[0].fX; 367 double dx = fLine[1].fX - fLine[0].fX;
351 double dy = fLine[1].fY - fLine[0].fY; 368 double dy = fLine[1].fY - fLine[0].fY;
352 if (fabs(dx) > fabs(dy)) { 369 if (fabs(dx) > fabs(dy)) {
353 return (xy.fX - fLine[0].fX) / dx; 370 return (xy.fX - fLine[0].fX) / dx;
354 } 371 }
355 return (xy.fY - fLine[0].fY) / dy; 372 return (xy.fY - fLine[0].fY) / dy;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 445
429 // SkDCubic accessors to Intersection utilities 446 // SkDCubic accessors to Intersection utilities
430 447
431 int SkDCubic::horizontalIntersect(double yIntercept, double roots[3]) const { 448 int SkDCubic::horizontalIntersect(double yIntercept, double roots[3]) const {
432 return LineCubicIntersections::HorizontalIntersect(*this, yIntercept, roots) ; 449 return LineCubicIntersections::HorizontalIntersect(*this, yIntercept, roots) ;
433 } 450 }
434 451
435 int SkDCubic::verticalIntersect(double xIntercept, double roots[3]) const { 452 int SkDCubic::verticalIntersect(double xIntercept, double roots[3]) const {
436 return LineCubicIntersections::VerticalIntersect(*this, xIntercept, roots); 453 return LineCubicIntersections::VerticalIntersect(*this, xIntercept, roots);
437 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698