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

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

Issue 272153002: fix bugs found by computing flat clips in 800K skps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix maybe-uninitialized error in unbuntu Created 6 years, 6 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 { 9 SkDLine SkDLine::subDivide(double t1, double t2) const {
10 SkDVector delta = tangent(); 10 SkDVector delta = tangent();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 double SkDLine::exactPoint(const SkDPoint& xy) const { 56 double SkDLine::exactPoint(const SkDPoint& xy) const {
57 if (xy == fPts[0]) { // do cheapest test first 57 if (xy == fPts[0]) { // do cheapest test first
58 return 0; 58 return 0;
59 } 59 }
60 if (xy == fPts[1]) { 60 if (xy == fPts[1]) {
61 return 1; 61 return 1;
62 } 62 }
63 return -1; 63 return -1;
64 } 64 }
65 65
66 double SkDLine::nearPoint(const SkDPoint& xy) const { 66 double SkDLine::nearPoint(const SkDPoint& xy, bool* unequal) const {
67 if (!AlmostBetweenUlps(fPts[0].fX, xy.fX, fPts[1].fX) 67 if (!AlmostBetweenUlps(fPts[0].fX, xy.fX, fPts[1].fX)
68 || !AlmostBetweenUlps(fPts[0].fY, xy.fY, fPts[1].fY)) { 68 || !AlmostBetweenUlps(fPts[0].fY, xy.fY, fPts[1].fY)) {
69 return -1; 69 return -1;
70 } 70 }
71 // project a perpendicular ray from the point to the line; find the T on the line 71 // project a perpendicular ray from the point to the line; find the T on the line
72 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line 72 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line
73 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay 73 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay
74 SkDVector ab0 = xy - fPts[0]; 74 SkDVector ab0 = xy - fPts[0];
75 double numer = len.fX * ab0.fX + ab0.fY * len.fY; 75 double numer = len.fX * ab0.fX + ab0.fY * len.fY;
76 if (!between(0, numer, denom)) { 76 if (!between(0, numer, denom)) {
77 return -1; 77 return -1;
78 } 78 }
79 double t = numer / denom; 79 double t = numer / denom;
80 SkDPoint realPt = ptAtT(t); 80 SkDPoint realPt = ptAtT(t);
81 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against distSq instead ? 81 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against distSq instead ?
82 // find the ordinal in the original line with the largest unsigned exponent 82 // find the ordinal in the original line with the largest unsigned exponent
83 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY); 83 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
84 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY); 84 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
85 largest = SkTMax(largest, -tiniest); 85 largest = SkTMax(largest, -tiniest);
86 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance? 86 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
87 return -1; 87 return -1;
88 } 88 }
89 if (unequal) {
90 *unequal = (float) largest != (float) (largest + dist);
91 }
89 t = SkPinT(t); 92 t = SkPinT(t);
90 SkASSERT(between(0, t, 1)); 93 SkASSERT(between(0, t, 1));
91 return t; 94 return t;
92 } 95 }
93 96
94 bool SkDLine::nearRay(const SkDPoint& xy) const { 97 bool SkDLine::nearRay(const SkDPoint& xy) const {
95 // project a perpendicular ray from the point to the line; find the T on the line 98 // project a perpendicular ray from the point to the line; find the T on the line
96 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line 99 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line
97 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay 100 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay
98 SkDVector ab0 = xy - fPts[0]; 101 SkDVector ab0 = xy - fPts[0];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; 185 double distSq = distU.fX * distU.fX + distU.fY * distU.fY;
183 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i nstead ? 186 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i nstead ?
184 double tiniest = SkTMin(SkTMin(x, top), bottom); 187 double tiniest = SkTMin(SkTMin(x, top), bottom);
185 double largest = SkTMax(SkTMax(x, top), bottom); 188 double largest = SkTMax(SkTMax(x, top), bottom);
186 largest = SkTMax(largest, -tiniest); 189 largest = SkTMax(largest, -tiniest);
187 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance? 190 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
188 return -1; 191 return -1;
189 } 192 }
190 return t; 193 return t;
191 } 194 }
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