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

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

Issue 1037573004: cumulative pathops patch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix pathopsinverse gm Created 5 years, 9 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 | « src/pathops/SkPathOpsLine.h ('k') | src/pathops/SkPathOpsOp.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 "SkPathOpsLine.h" 7 #include "SkPathOpsLine.h"
8 8
9 SkDLine SkDLine::subDivide(double t1, double t2) const {
10 SkDVector delta = tangent();
11 SkDLine dst = {{{
12 fPts[0].fX - t1 * delta.fX, fPts[0].fY - t1 * delta.fY}, {
13 fPts[0].fX - t2 * delta.fX, fPts[0].fY - t2 * delta.fY}}};
14 return dst;
15 }
16
17 // may have this below somewhere else already: 9 // may have this below somewhere else already:
18 // copying here because I thought it was clever 10 // copying here because I thought it was clever
19 11
20 // Copyright 2001, softSurfer (www.softsurfer.com) 12 // Copyright 2001, softSurfer (www.softsurfer.com)
21 // This code may be freely used and modified for any purpose 13 // This code may be freely used and modified for any purpose
22 // providing that this copyright notice is included with it. 14 // providing that this copyright notice is included with it.
23 // SoftSurfer makes no warranty for this code, and cannot be held 15 // SoftSurfer makes no warranty for this code, and cannot be held
24 // liable for any real or imagined damage resulting from its use. 16 // liable for any real or imagined damage resulting from its use.
25 // Users of this code must verify correctness for their application. 17 // Users of this code must verify correctness for their application.
26 18
27 // Assume that a class is already given for the object: 19 // Assume that a class is already given for the object:
28 // Point with coordinates {float x, y;} 20 // Point with coordinates {float x, y;}
29 //=================================================================== 21 //===================================================================
30 22
23 // (only used by testing)
31 // isLeft(): tests if a point is Left|On|Right of an infinite line. 24 // isLeft(): tests if a point is Left|On|Right of an infinite line.
32 // Input: three points P0, P1, and P2 25 // Input: three points P0, P1, and P2
33 // Return: >0 for P2 left of the line through P0 and P1 26 // Return: >0 for P2 left of the line through P0 and P1
34 // =0 for P2 on the line 27 // =0 for P2 on the line
35 // <0 for P2 right of the line 28 // <0 for P2 right of the line
36 // See: the January 2001 Algorithm on Area of Triangles 29 // See: the January 2001 Algorithm on Area of Triangles
37 // return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y)) ; 30 // return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y)) ;
38 double SkDLine::isLeft(const SkDPoint& pt) const { 31 double SkDLine::isLeft(const SkDPoint& pt) const {
39 SkDVector p0 = fPts[1] - fPts[0]; 32 SkDVector p0 = fPts[1] - fPts[0];
40 SkDVector p2 = pt - fPts[0]; 33 SkDVector p2 = pt - fPts[0];
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 double t = numer / denom; 96 double t = numer / denom;
104 SkDPoint realPt = ptAtT(t); 97 SkDPoint realPt = ptAtT(t);
105 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against distSq instead ? 98 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against distSq instead ?
106 // find the ordinal in the original line with the largest unsigned exponent 99 // find the ordinal in the original line with the largest unsigned exponent
107 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY); 100 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
108 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY); 101 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
109 largest = SkTMax(largest, -tiniest); 102 largest = SkTMax(largest, -tiniest);
110 return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance? 103 return RoughlyEqualUlps(largest, largest + dist); // is the dist within ULPS tolerance?
111 } 104 }
112 105
113 // Returns true if a ray from (0,0) to (x1,y1) is coincident with a ray (0,0) to (x2,y2)
114 // OPTIMIZE: a specialty routine could speed this up -- may not be called very o ften though
115 bool SkDLine::NearRay(double x1, double y1, double x2, double y2) {
116 double denom1 = x1 * x1 + y1 * y1;
117 double denom2 = x2 * x2 + y2 * y2;
118 SkDLine line = {{{0, 0}, {x1, y1}}};
119 SkDPoint pt = {x2, y2};
120 if (denom2 > denom1) {
121 SkTSwap(line[1], pt);
122 }
123 return line.nearRay(pt);
124 }
125
126 double SkDLine::ExactPointH(const SkDPoint& xy, double left, double right, doubl e y) { 106 double SkDLine::ExactPointH(const SkDPoint& xy, double left, double right, doubl e y) {
127 if (xy.fY == y) { 107 if (xy.fY == y) {
128 if (xy.fX == left) { 108 if (xy.fX == left) {
129 return 0; 109 return 0;
130 } 110 }
131 if (xy.fX == right) { 111 if (xy.fX == right) {
132 return 1; 112 return 1;
133 } 113 }
134 } 114 }
135 return -1; 115 return -1;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; 165 double distSq = distU.fX * distU.fX + distU.fY * distU.fY;
186 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i nstead ? 166 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i nstead ?
187 double tiniest = SkTMin(SkTMin(x, top), bottom); 167 double tiniest = SkTMin(SkTMin(x, top), bottom);
188 double largest = SkTMax(SkTMax(x, top), bottom); 168 double largest = SkTMax(SkTMax(x, top), bottom);
189 largest = SkTMax(largest, -tiniest); 169 largest = SkTMax(largest, -tiniest);
190 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance? 170 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
191 return -1; 171 return -1;
192 } 172 }
193 return t; 173 return t;
194 } 174 }
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsLine.h ('k') | src/pathops/SkPathOpsOp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698