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

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

Issue 13934009: path ops -- use standard max, min, double-is-nan (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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/SkPathOpsPoint.h ('k') | src/pathops/SkPathOpsTypes.h » ('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 "SkLineParameters.h" 7 #include "SkLineParameters.h"
8 #include "SkPathOpsCubic.h" 8 #include "SkPathOpsCubic.h"
9 #include "SkPathOpsQuad.h" 9 #include "SkPathOpsQuad.h"
10 #include "SkPathOpsTriangle.h" 10 #include "SkPathOpsTriangle.h"
11 11
12 // from http://blog.gludion.com/2009/08/distance-to-quadratic-bezier-curve.html 12 // from http://blog.gludion.com/2009/08/distance-to-quadratic-bezier-curve.html
13 // (currently only used by testing) 13 // (currently only used by testing)
14 double SkDQuad::nearestT(const SkDPoint& pt) const { 14 double SkDQuad::nearestT(const SkDPoint& pt) const {
15 SkDVector pos = fPts[0] - pt; 15 SkDVector pos = fPts[0] - pt;
16 // search points P of bezier curve with PM.(dP / dt) = 0 16 // search points P of bezier curve with PM.(dP / dt) = 0
17 // a calculus leads to a 3d degree equation : 17 // a calculus leads to a 3d degree equation :
18 SkDVector A = fPts[1] - fPts[0]; 18 SkDVector A = fPts[1] - fPts[0];
19 SkDVector B = fPts[2] - fPts[1]; 19 SkDVector B = fPts[2] - fPts[1];
20 B -= A; 20 B -= A;
21 double a = B.dot(B); 21 double a = B.dot(B);
22 double b = 3 * A.dot(B); 22 double b = 3 * A.dot(B);
23 double c = 2 * A.dot(A) + pos.dot(B); 23 double c = 2 * A.dot(A) + pos.dot(B);
24 double d = pos.dot(A); 24 double d = pos.dot(A);
25 double ts[3]; 25 double ts[3];
26 int roots = SkDCubic::RootsValidT(a, b, c, d, ts); 26 int roots = SkDCubic::RootsValidT(a, b, c, d, ts);
27 double d0 = pt.distanceSquared(fPts[0]); 27 double d0 = pt.distanceSquared(fPts[0]);
28 double d2 = pt.distanceSquared(fPts[2]); 28 double d2 = pt.distanceSquared(fPts[2]);
29 double distMin = SkTMin<double>(d0, d2); 29 double distMin = SkTMin(d0, d2);
30 int bestIndex = -1; 30 int bestIndex = -1;
31 for (int index = 0; index < roots; ++index) { 31 for (int index = 0; index < roots; ++index) {
32 SkDPoint onQuad = xyAtT(ts[index]); 32 SkDPoint onQuad = xyAtT(ts[index]);
33 double dist = pt.distanceSquared(onQuad); 33 double dist = pt.distanceSquared(onQuad);
34 if (distMin > dist) { 34 if (distMin > dist) {
35 distMin = dist; 35 distMin = dist;
36 bestIndex = index; 36 bestIndex = index;
37 } 37 }
38 } 38 }
39 if (bestIndex >= 0) { 39 if (bestIndex >= 0) {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 * c = C 284 * c = C
285 */ 285 */
286 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { 286 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) {
287 *a = quad[0]; // a = A 287 *a = quad[0]; // a = A
288 *b = 2 * quad[2]; // b = 2*B 288 *b = 2 * quad[2]; // b = 2*B
289 *c = quad[4]; // c = C 289 *c = quad[4]; // c = C
290 *b -= *c; // b = 2*B - C 290 *b -= *c; // b = 2*B - C
291 *a -= *b; // a = A - 2*B + C 291 *a -= *b; // a = A - 2*B + C
292 *b -= *c; // b = 2*B - 2*C 292 *b -= *c; // b = 2*B - 2*C
293 } 293 }
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsPoint.h ('k') | src/pathops/SkPathOpsTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698