| OLD | NEW |
| 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 SkDPoint SkDLine::ptAtT(double t) const { | 9 SkDPoint SkDLine::ptAtT(double t) const { |
| 10 if (0 == t) { | 10 if (0 == t) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 return -1; | 34 return -1; |
| 35 } | 35 } |
| 36 // project a perpendicular ray from the point to the line; find the T on the
line | 36 // project a perpendicular ray from the point to the line; find the T on the
line |
| 37 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line | 37 SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line |
| 38 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay | 38 double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay |
| 39 SkDVector ab0 = xy - fPts[0]; | 39 SkDVector ab0 = xy - fPts[0]; |
| 40 double numer = len.fX * ab0.fX + ab0.fY * len.fY; | 40 double numer = len.fX * ab0.fX + ab0.fY * len.fY; |
| 41 if (!between(0, numer, denom)) { | 41 if (!between(0, numer, denom)) { |
| 42 return -1; | 42 return -1; |
| 43 } | 43 } |
| 44 if (!denom) { |
| 45 return 0; |
| 46 } |
| 44 double t = numer / denom; | 47 double t = numer / denom; |
| 45 SkDPoint realPt = ptAtT(t); | 48 SkDPoint realPt = ptAtT(t); |
| 46 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against
distSq instead ? | 49 double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against
distSq instead ? |
| 47 // find the ordinal in the original line with the largest unsigned exponent | 50 // find the ordinal in the original line with the largest unsigned exponent |
| 48 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX),
fPts[1].fY); | 51 double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX),
fPts[1].fY); |
| 49 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX),
fPts[1].fY); | 52 double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX),
fPts[1].fY); |
| 50 largest = SkTMax(largest, -tiniest); | 53 largest = SkTMax(largest, -tiniest); |
| 51 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? | 54 if (!AlmostEqualUlps_Pin(largest, largest + dist)) { // is the dist within U
LPS tolerance? |
| 52 return -1; | 55 return -1; |
| 53 } | 56 } |
| 54 if (unequal) { | 57 if (unequal) { |
| 55 *unequal = (float) largest != (float) (largest + dist); | 58 *unequal = (float) largest != (float) (largest + dist); |
| 56 } | 59 } |
| 57 t = SkPinT(t); // a looser pin breaks skpwww_lptemp_com_3 | 60 t = SkPinT(t); // a looser pin breaks skpwww_lptemp_com_3 |
| 58 SkASSERT(between(0, t, 1)); | 61 SkASSERT(between(0, t, 1)); |
| 59 return t; | 62 return t; |
| 60 } | 63 } |
| 61 | 64 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; | 140 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; |
| 138 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? | 141 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? |
| 139 double tiniest = SkTMin(SkTMin(x, top), bottom); | 142 double tiniest = SkTMin(SkTMin(x, top), bottom); |
| 140 double largest = SkTMax(SkTMax(x, top), bottom); | 143 double largest = SkTMax(SkTMax(x, top), bottom); |
| 141 largest = SkTMax(largest, -tiniest); | 144 largest = SkTMax(largest, -tiniest); |
| 142 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? | 145 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? |
| 143 return -1; | 146 return -1; |
| 144 } | 147 } |
| 145 return t; | 148 return t; |
| 146 } | 149 } |
| OLD | NEW |