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 // may have this below somewhere else already: | |
10 // copying here because I thought it was clever | |
11 | |
12 // Copyright 2001, softSurfer (www.softsurfer.com) | |
13 // This code may be freely used and modified for any purpose | |
14 // providing that this copyright notice is included with it. | |
15 // SoftSurfer makes no warranty for this code, and cannot be held | |
16 // liable for any real or imagined damage resulting from its use. | |
17 // Users of this code must verify correctness for their application. | |
18 | |
19 // Assume that a class is already given for the object: | |
20 // Point with coordinates {float x, y;} | |
21 //=================================================================== | |
22 | |
23 // (only used by testing) | |
24 // isLeft(): tests if a point is Left|On|Right of an infinite line. | |
25 // Input: three points P0, P1, and P2 | |
26 // Return: >0 for P2 left of the line through P0 and P1 | |
27 // =0 for P2 on the line | |
28 // <0 for P2 right of the line | |
29 // See: the January 2001 Algorithm on Area of Triangles | |
30 // return (float) ((P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y))
; | |
31 double SkDLine::isLeft(const SkDPoint& pt) const { | |
32 SkDVector p0 = fPts[1] - fPts[0]; | |
33 SkDVector p2 = pt - fPts[0]; | |
34 return p0.cross(p2); | |
35 } | |
36 | |
37 SkDPoint SkDLine::ptAtT(double t) const { | 9 SkDPoint SkDLine::ptAtT(double t) const { |
38 if (0 == t) { | 10 if (0 == t) { |
39 return fPts[0]; | 11 return fPts[0]; |
40 } | 12 } |
41 if (1 == t) { | 13 if (1 == t) { |
42 return fPts[1]; | 14 return fPts[1]; |
43 } | 15 } |
44 double one_t = 1 - t; | 16 double one_t = 1 - t; |
45 SkDPoint result = { one_t * fPts[0].fX + t * fPts[1].fX, one_t * fPts[0].fY
+ t * fPts[1].fY }; | 17 SkDPoint result = { one_t * fPts[0].fX + t * fPts[1].fX, one_t * fPts[0].fY
+ t * fPts[1].fY }; |
46 return result; | 18 return result; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; | 137 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; |
166 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? | 138 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? |
167 double tiniest = SkTMin(SkTMin(x, top), bottom); | 139 double tiniest = SkTMin(SkTMin(x, top), bottom); |
168 double largest = SkTMax(SkTMax(x, top), bottom); | 140 double largest = SkTMax(SkTMax(x, top), bottom); |
169 largest = SkTMax(largest, -tiniest); | 141 largest = SkTMax(largest, -tiniest); |
170 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? | 142 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? |
171 return -1; | 143 return -1; |
172 } | 144 } |
173 return t; | 145 return t; |
174 } | 146 } |
OLD | NEW |