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 #ifndef SkPathOpsPoint_DEFINED | 7 #ifndef SkPathOpsPoint_DEFINED |
8 #define SkPathOpsPoint_DEFINED | 8 #define SkPathOpsPoint_DEFINED |
9 | 9 |
10 #include "SkPathOpsTypes.h" | 10 #include "SkPathOpsTypes.h" |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 | 12 |
13 inline bool AlmostEqualUlps(const SkPoint& pt1, const SkPoint& pt2) { | 13 inline bool AlmostEqualUlps(const SkPoint& pt1, const SkPoint& pt2) { |
14 return AlmostEqualUlps(pt1.fX, pt2.fX) && AlmostEqualUlps(pt1.fY, pt2.fY); | 14 return AlmostEqualUlps(pt1.fX, pt2.fX) && AlmostEqualUlps(pt1.fY, pt2.fY); |
15 } | 15 } |
16 | 16 |
17 struct SkDVector { | 17 struct SkDVector { |
18 double fX; | 18 double fX; |
19 double fY; | 19 double fY; |
20 | 20 |
21 void set(const SkVector& pt) { | 21 void set(const SkVector& pt) { |
22 fX = pt.fX; | 22 fX = pt.fX; |
23 fY = pt.fY; | 23 fY = pt.fY; |
24 } | 24 } |
25 | 25 |
26 friend SkDPoint operator+(const SkDPoint& a, const SkDVector& b); | |
27 | |
28 // only used by testing | 26 // only used by testing |
29 void operator+=(const SkDVector& v) { | 27 void operator+=(const SkDVector& v) { |
30 fX += v.fX; | 28 fX += v.fX; |
31 fY += v.fY; | 29 fY += v.fY; |
32 } | 30 } |
33 | 31 |
34 // only called by nearestT, which is currently only used by testing | 32 // only called by nearestT, which is currently only used by testing |
35 void operator-=(const SkDVector& v) { | 33 void operator-=(const SkDVector& v) { |
36 fX -= v.fX; | 34 fX -= v.fX; |
37 fY -= v.fY; | 35 fY -= v.fY; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return true; | 199 return true; |
202 } | 200 } |
203 double dist = distance(a); // OPTIMIZATION: can we compare against dist
Sq instead ? | 201 double dist = distance(a); // OPTIMIZATION: can we compare against dist
Sq instead ? |
204 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); | 202 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
205 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); | 203 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
206 largest = SkTMax(largest, -tiniest); | 204 largest = SkTMax(largest, -tiniest); |
207 return RoughlyEqualUlps(largest, largest + dist); // is the dist within
ULPS tolerance? | 205 return RoughlyEqualUlps(largest, largest + dist); // is the dist within
ULPS tolerance? |
208 } | 206 } |
209 | 207 |
210 static bool RoughlyEqual(const SkPoint& a, const SkPoint& b) { | 208 static bool RoughlyEqual(const SkPoint& a, const SkPoint& b) { |
211 if (!RoughlyEqualUlps(a.fX, b.fX) || !RoughlyEqualUlps(a.fY, b.fY)) { | 209 if (!RoughlyEqualUlps(a.fX, b.fX) && !RoughlyEqualUlps(a.fY, b.fY)) { |
212 return false; | 210 return false; |
213 } | 211 } |
214 SkDPoint dA, dB; | 212 SkDPoint dA, dB; |
215 dA.set(a); | 213 dA.set(a); |
216 dB.set(b); | 214 dB.set(b); |
217 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? | 215 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? |
218 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); | 216 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); |
219 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); | 217 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); |
220 largest = SkTMax(largest, -tiniest); | 218 largest = SkTMax(largest, -tiniest); |
221 return RoughlyEqualUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? | 219 return RoughlyEqualUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? |
222 } | 220 } |
223 | 221 |
224 // utilities callable by the user from the debugger when the implementation
code is linked in | 222 // utilities callable by the user from the debugger when the implementation
code is linked in |
225 void dump() const; | 223 void dump() const; |
226 static void Dump(const SkPoint& pt); | 224 static void Dump(const SkPoint& pt); |
227 static void DumpHex(const SkPoint& pt); | 225 static void DumpHex(const SkPoint& pt); |
228 }; | 226 }; |
229 | 227 |
230 #endif | 228 #endif |
OLD | NEW |